PHPackages                             corex/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. [Framework](/categories/framework)
4. /
5. corex/container

ActiveLibrary[Framework](/categories/framework)

corex/container
===============

Simple Dependency Injection Container

2.4.0(3mo ago)097MITPHPPHP ^8.1CI failing

Since Jan 19Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/corex/container)[ Packagist](https://packagist.org/packages/corex/container)[ RSS](/packages/corex-container/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (3)Versions (12)Used By (0)

Simple Dependency Injection Container
=====================================

[](#simple-dependency-injection-container)

[![license](https://camo.githubusercontent.com/6380ca3fa1a6a382f846d80d6d38706969eb6483574524ada1a03e2540e29a21/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f636f7265782f636f6e7461696e65723f6c6162656c3d6c6963656e7365)](https://camo.githubusercontent.com/6380ca3fa1a6a382f846d80d6d38706969eb6483574524ada1a03e2540e29a21/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f636f7265782f636f6e7461696e65723f6c6162656c3d6c6963656e7365)[![build](https://github.com/corex/container/workflows/build/badge.svg?branch=master)](https://github.com/corex/container/workflows/build/badge.svg?branch=master)[![Code Coverage](https://camo.githubusercontent.com/9c3c21a8ebc678bd57c76fa180f7bfdd300b7435e29953a8c6594a789f1c6fcf/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f75726c3d68747470733a2f2f676973742e67697468756275736572636f6e74656e742e636f6d2f636f7265782f32613635623733646238363864336265343631646564653962316435636562612f7261772f746573742d636f7665726167655f5f6d61737465722e6a736f6e)](https://github.com/corex/container/actions)[![PHPStan Level](https://camo.githubusercontent.com/f6033af1a8903352c30248df33399db19768ae0dd1db33c091b5f2a9ceff530b/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f75726c3d68747470733a2f2f676973742e67697468756275736572636f6e74656e742e636f6d2f636f7265782f32613635623733646238363864336265343631646564653962316435636562612f7261772f7068707374616e2d6c6576656c5f5f6d61737465722e6a736f6e)](https://github.com/corex/container/actions)

> **Breaking changes** - this package has been rewritten from scratch to be more strict and simple to use.

- Support for PSR-11 Container Interface.
- Support for setting default parameters on definitions.

Examples
--------

[](#examples)

### Make a class without binding.

[](#make-a-class-without-binding)

```
$myClass = (new Container())->make(MyClass::class);
```

Type-hints will be resolved if they are bound in advance.

### Make a class with binding and parameters.

[](#make-a-class-with-binding-and-parameters)

```
$containerBuilder = new ContainerBuilder();

$containerBuilder->bind('myClass', MyClass::class)
    ->setArgument('firstname', 'Roger');

$container = new Container($containerBuilder);

$myClass = $container->make('myClass', [
    'lastname' => 'Moore'
]);
```

### Make a class binding by class.

[](#make-a-class-binding-by-class)

```
$containerBuilder = new ContainerBuilder();

$containerBuilder->bindClass(MyClass::class);

$container = new Container($containerBuilder);
$myClass = $container->get(MyClass::class);
```

### Make a class binding by implemented interface.

[](#make-a-class-binding-by-implemented-interface)

```
interface MyClassInterface
{
}

class MyClass implements MyClassInterface
{
}

$containerBuilder = new ContainerBuilder();

$containerBuilder->bindClassByInterface(MyClass::class);

$container = new Container($containerBuilder);
$myClass = $container->get(MyClassInterface::class);
```

### Factory - closure

[](#factory---closure)

```
interface MyClassInterface
{
}

class MyClass implements MyClassInterface
{
}

$containerBuilder = new ContainerBuilder();

$containerBuilder->bindClassByInterface(MyClass::class)
    ->setFactory(function (ContainerInterface $container) {
        return $container->make(MyClass::class);
    });

$container = new Container($containerBuilder);
$myClass = $container->get(MyClassInterface::class);
```

> Container will be parsed as first and only argument on Closure and can be used to instantiate and resolve dependencies.

### Factory - invokable

[](#factory---invokable)

```
interface MyClassInterface
{
}

class MyClass implements MyClassInterface
{
}

class MyFactory
{
    public function __invoke(ContainerInterface $container): MyClassInterface
    {
        return $container->make(MyClass::class);
    }
}

$containerBuilder = new ContainerBuilder();

$containerBuilder->bindClassByInterface(MyClass::class)
    ->setFactory(MyFactory::class);

$container = new Container($containerBuilder);
$myClass = $container->get(MyClassInterface::class);
```

> Container will be parsed as first and only argument on \_\_invoke() and can be used to instantiate and resolve dependencies.

### Factory - dynamic method

[](#factory---dynamic-method)

```
interface MyClassInterface
{
}

class MyClass implements MyClassInterface
{
}

class MyFactory
{
    public function createMyClass(ContainerInterface $container): MyClassInterface
    {
        return $container->make(MyClass::class);
    }
}

$containerBuilder = new ContainerBuilder();

$containerBuilder->bindClassByInterface(MyClass::class)
    ->setFactory(MyFactory::class, 'createMyClass');

$container = new Container($containerBuilder);
$myClass = $container->get(MyClassInterface::class);
```

> Container will be parsed as first and only argument on createMyClass() and can be used to instantiate and resolve dependencies.

### Factory - static method

[](#factory---static-method)

```
interface MyClassInterface
{
}

class MyClass implements MyClassInterface
{
}

class MyFactory
{
    public static function createMyClass(ContainerInterface $container): MyClassInterface
    {
        return $container->make(MyClass::class);
    }
}

$containerBuilder = new ContainerBuilder();

$containerBuilder->bindClassByInterface(MyClass::class)
    ->setFactory(MyFactory::class, '::createMyClass');

$container = new Container($containerBuilder);
$myClass = $container->get(MyClassInterface::class);
```

> Container will be parsed as first and only argument on createMyClass() and can be used to instantiate and resolve dependencies.
>
> Notice the "::" on `$factoryMethod` which indicate a static method.

Parameters
----------

[](#parameters)

Parameters will be resolved in following order:

1. Type-hint ContainerInterface will be resolved to instance of container.
2. Default parameters specified on definition.
3. Default parameters in constructor/method.
4. Specified parameters when calling make() and not already resolved.

###  Health Score

46

—

FairBetter than 93% of packages

Maintenance81

Actively maintained with recent releases

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity72

Established project with proven stability

 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

Every ~276 days

Recently: every ~197 days

Total

9

Last Release

99d ago

Major Versions

1.1.1 → 2.0.02022-12-29

PHP version history (2 changes)1.0.0PHP ^7.2

2.0.0PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/2168107cb28f49e937f963a925553ebac5923aa27cad2e1cf90ddbcabf663d6d?d=identicon)[corex](/maintainers/corex)

---

Top Contributors

[![corex](https://avatars.githubusercontent.com/u/21259173?v=4)](https://github.com/corex "corex (32 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[cakephp/cakephp

The CakePHP framework

8.8k18.5M1.6k](/packages/cakephp-cakephp)[silverstripe/framework

The SilverStripe framework

7213.5M2.5k](/packages/silverstripe-framework)[drupal/core-recommended

Locked core dependencies; require this project INSTEAD OF drupal/core.

6939.5M343](/packages/drupal-core-recommended)[cakephp/core

CakePHP Framework Core classes

6026.8M39](/packages/cakephp-core)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)[neos/flow

Flow Application Framework

862.0M451](/packages/neos-flow)

PHPackages © 2026

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