PHPackages                             aleris/container - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. aleris/container

ActivePackage[Utility &amp; Helpers](/categories/utility)

aleris/container
================

Light weight, straight forward DI container that simply works, and works well.

0.1(5y ago)09MITPHPPHP &gt;=8.0.0

Since Feb 15Pushed 5y ago1 watchersCompare

[ Source](https://github.com/alerisio/container)[ Packagist](https://packagist.org/packages/aleris/container)[ Docs](https://aleris.io)[ RSS](/packages/aleris-container/feed)WikiDiscussions master Synced 5d ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

Aleris Container
================

[](#aleris-container)

A lightweight, straight forward dependency injection container that simply works, and works well. Supports config file and all standard injection methods -- constructor, setter, annotation, plus also attributes. Also includes a `Di` wrapper class that allows container methods to be accessed statically for greater simplicity and efficiency.

Installation
------------

[](#installation)

Install via Composer with:

> `composer require aleris/container`

Basic Usage
-----------

[](#basic-usage)

Supports the standard container methods -- `has, get, set, make, call`,

```
use Aleris\Container\Container;

$cntr = new Container('/path/to/definitions.php');

// Set and get
$cntr->set('full_name', 'John Doe');
// Get service
$logger = $cntr->get(LoggerInterface::class);
$logger->info("Here I am");

// Make and set
$user = $cntr->makeset(User::class, ['id' => 311]);

// Call via method setter injection
$cntr->call([$user, 'updateStatus'], ['status' => 'inactive']);
```

Constructor
-----------

[](#constructor)

Constructor takes the following parameters, none of which are required.

ParameterTypeDescription`$config_file`stringLocation of the definitions file which defines starting items and services. Should be a PHP file that returns an associative array. Please see the [Definitions File](https://github.com/alerisio/container/blob/master/docs/definitions.md) page for details. If defind in the constructor, will be automatically loaded.`$use_autowiring`boolWhether or not to enable auto-wiring. If true, the `use` declarations of all files will be loaded, and checked for injection parameters. Defaults to true.`$use_attributes`boolIf true, will scan attributes in all files for injection properties. Please see the [Attributes Injection](https://github.com/alerisio/container/blob/master/docs/attributes.md) page for details. Defaults to false.`$use_annotations`boolIf true, will scan the properties and doc blocks of all files for injected properties. Please see the [Annotation Injection](https://github.com/alerisio/container/blob/master/docs/annotations.md) page for details. Defaults to false.Methods
-------

[](#methods)

The following base methods are supported, as per all containers.

MethodDescription`has(string $name):bool`Check whether or not item is available in container.`get(string $name):mixed`Gets an item from the container. If does not already exist, will try to make and set the item. Returns null on non-existent item.`set(string $name, mixed $item):void`Sets an item in the container.`make(string $name, array $params = []):mixed`Creates new instance of the class with provided parameters.`makeset(string $name, array $params = []):mixed`Creates new instance of the class with provided parameters, and also sets class name into container for future use.`call(callablearray $callable, array $params = \[\]):mixed``buildContainer(string $config_file):void`Build container with the specified definitions file. Useful if you didn't pass a definitions file to the constructor, or if you're using the `Di` class to access the container statically.Singleton Di Class
------------------

[](#singleton-di-class)

This package includes the `Di` class which acts as a singleton and allows container methods to be accessed statically, instead of passing the container object from class to class, method to method. This is done to provide efficiency and simplicity, and also assumes you're only managing one DI container per-request.

Modify the properties within the `/src/Di.php` file as they are used as the constructor parameters for the container. Example usage is below.

```
namespace myApp;

use Aleris\Container\Di;
use myApp\Users\User;

// Get logger
$logger = Di::get(LoggerInterface::Class);

// Make user object
Di::make(User::class, ['id' => 52]);

// Set and get variable
Di::set('full_name', 'John Doe');
$name = Di::get('full_name');   // John Doe
```

Follow Aleris
-------------

[](#follow-aleris)

Loads of good things coming in the near future including new quality open source packages, more advanced articles / tutorials that go over down to earth useful topics, et al. Stay informed by joining the [mailing list](https://apexpl.io/) on our web site, or follow along on Twitter at [@mdizak1](https://twitter.com/mdizak1).

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1916d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/88607fb28c4504c2cfa06acf68f46ca9a0bc1184942def316cf1ec6b6bc220a7?d=identicon)[aleris](/maintainers/aleris)

---

Top Contributors

[![mdizak](https://avatars.githubusercontent.com/u/59886259?v=4)](https://github.com/mdizak "mdizak (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/aleris-container/health.svg)

```
[![Health](https://phpackages.com/badges/aleris-container/health.svg)](https://phpackages.com/packages/aleris-container)
```

###  Alternatives

[symfony/dependency-injection

Allows you to standardize and centralize the way objects are constructed in your application

4.2k431.1M7.5k](/packages/symfony-dependency-injection)[illuminate/contracts

The Illuminate Contracts package.

704122.9M10.1k](/packages/illuminate-contracts)[illuminate/container

The Illuminate Container package.

31278.1M2.0k](/packages/illuminate-container)[ecotone/ecotone

Supporting you in building DDD, CQRS, Event Sourcing applications with ease.

558549.8k17](/packages/ecotone-ecotone)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

728272.9k20](/packages/civicrm-civicrm-core)[internal/dload

Downloads binaries.

98142.7k10](/packages/internal-dload)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
