PHPackages                             codeburner/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. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. codeburner/container

ActiveLibrary[PSR &amp; Standards](/categories/psr-standards)

codeburner/container
====================

The faster IoC Container ever seen.

v2.0.0(9y ago)4311MITPHPPHP &gt;=7.0.0

Since Feb 17Pushed 9y ago1 watchersCompare

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

READMEChangelog (2)Dependencies (2)Versions (4)Used By (0)

Codeburner Container
====================

[](#codeburner-container)

[![Software License](https://camo.githubusercontent.com/074b89bca64d3edc93a1db6c7e3b1636b874540ba91d66367c0e5e354c56d0ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](LICENSE)[![Build Status](https://camo.githubusercontent.com/9d21351ec029909f1746c6754191f0f032407554187af9ed3adf07a1cebe94da/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f636f64656275726e65726672616d65776f726b2f636f6e7461696e65722f6d61737465722e737667)](https://travis-ci.org/codeburnerframework/container)[![Code Coverage](https://camo.githubusercontent.com/11bdd05610fbefe9f2ca00cde694172fbd93bc8c7b9918b17cfe6192377fd3be/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f636f64656275726e65726672616d65776f726b2f636f6e7461696e65722f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/codeburnerframework/container/?branch=master)[![Quality Score](https://camo.githubusercontent.com/f978363a3bc91c4ed66687aed20d75a328afa2dcce95e8cf027c96f87f91a708/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f636f64656275726e65726672616d65776f726b2f636f6e7461696e65722e737667)](https://scrutinizer-ci.com/g/codeburnerframework/container)

[![SensioLabsInsight](https://camo.githubusercontent.com/e1f4d8259af544a0b68ea4d059b722dcc1a25b1340a6d3f15ea855b32239a0b1/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f39616632633432392d636337662d346337312d386561632d6533633364646434633164322f6269672e706e67)](https://insight.sensiolabs.com/projects/9af2c429-cc7f-4c71-8eac-e3c3ddd4c1d2)

The faster IoC container package for you build blazing fast applications for the web.

Thanks to [Tom Butler](https://r.je/dice.html) for motivate me with [this announce of dice](https://r.je/dice.html), a fast dependency injection container.

\##Instalation

Add `codeburner/container` to your `composer.json` file, and update or install composer dependencies.

```
{
    "require": {
        "codeburner/container": "^2.0"
    }
}
```

or via CLI:

```
$ composer require codeburner/container --save
```

\##Usage

- [Introduction](#introduction)
    - [Performance](#performance)
    - [Concepts](#concepts)
    - [Usage](#usage)
        - [Examples](#examples)
- [Bindings](#bindings)
    - [Binding Types](#binding-types)
        - [Resolvable Bindings](#resolvable-bindings)
        - [Resolved Bindings](#resolved-bindings)
    - [Binding Ways](#binding-ways)
        - [Strings](#strings)
        - [Closures](#closures)
        - [Instances](#instances)
    - [Resolving Bindings](#resolving-bindings)
        - [Setting Dependencies Manually](#setting-dependencies-manually)
    - [Extending Bindings](#extending-bindings)
- [Exceptions](#exceptions)
- [API](#api)

Introduction
------------

[](#introduction)

Welcome to the [Codeburner](http://github.com/codeburnerframework) blazing fast container docs! Before starting the usage is recommended understand the main goal and mission of all parts of this package.

### Performance

[](#performance)

[Codeburner](http://github.com/codeburnerframework) project create packages with performance in focus, and the benchmarks are comming!

### Concepts

[](#concepts)

The container is responsable to automatilly instantiate new objects, resolving all class dependencies and storing these objects over aliases. This enable a greater flexibility removing hard-coded class dependencies, and instead, making the dependencies be dinacally injected at run-time.

### Usage

[](#usage)

After you have the classes ready to be instantiate, you only need to register the bindings and call then.

```
use Codeburner\Container\Container;

$container = new Container;

// Regiser a "stdClass" class to a "std" key.
$container->set('std', 'stdClass');

// Accessing new "stdClass" objects.
$container->get('std');
```

#### Examples

[](#examples)

Usage examples are comming soon.

Bindings
--------

[](#bindings)

Bindings are the objects stored in the container. The container implements the [PSR-11](https://github.com/php-fig/fig-standards/blob/master/proposed/container.md) providing the `get($id)` and `has($id)` methods to access the bindings, and define the `set($id, $concrete)` to store objects.

```
class ClassA {
	public function __construct(stdClass $dependency) {

	}
}

$container->set('my-a', 'ClassA');

if ($container->has('my-a')) {
	$container->get('my-a');
}
```

### Binding Types

[](#binding-types)

#### Resolvable Bindings

[](#resolvable-bindings)

Resolvable bindings will return a new instance in every access.

```
$container->set('app.model.posts', App\Model\Post::class);

$obj1 = $container->get('app.model.posts'); // App\Model\Post#1
$obj2 = $container->get('app.model.posts'); // App\Model\Post#2
```

#### Resolved Bindings

[](#resolved-bindings)

Resolved bindings are no more than singletons, every access will return the same instance.

```
// you can define by passing a third parameter to set
$container->set('database', App\Database::class, true);
// or using the `singleton` method
$container->singleton('database', App\Database::class);

$obj1 = $container->get('database'); // App\Database#1
$obj2 = $container->get('database'); // App\Database#1
```

### Binding Ways

[](#binding-ways)

#### Strings

[](#strings)

The simplest way to define a binding, you only need to give a class name as string.

```
class ClassNameTest {

}

$container->set('someobj', ClassNameTest::class);
```

#### Closures

[](#closures)

Some times you need to set some attributes or make some initial logic on objects, you can do it with a closure binding.

```
$container->set('someobj', function ($container) {
	$obj = new stdClass;
	$obj->attribute = 1;

	return $obj;
});
```

#### Instances

[](#instances)

If you need to attach an existent instance, you should use the `set` or `instance` method.

```
$obj = new stdClass;

// you can set instances directly by the set method
$container->set('std', $obj);
// or use the `instance` method
$container->instance('std', $obj);
```

### Resolving Bindings

[](#resolving-bindings)

The great goal of the container is to automatically inject all class dependencies, if you only need to create an instance of a class without binding then into container use the `make` method.

```
class Post {
	public function __construct(Category $category) {
		$this->category = $category;
	}
}

class Category {
	public function __construct() {
		$this->id = rand();
	}
}

$post = $container->make(Post::class);

echo $post->category->id;
```

#### Setting Dependencies Manually

[](#setting-dependencies-manually)

Sometimes you want to define that some class will receive a specific object of another class on instantiation.

```
class Post {
	public function __construct(Category $category) {
		$this->category = $category;
	}
}

class Category {
	public function __construct() {
		$this->id = rand();
	}
}

$category = new Category;
$category->id = 1;

$container->setTo(Post::class, Category::class, $category);
$post = $container->make(Post::class);

echo $post->category->id; // 1
```

`make($abstract, $parameters = [], $force = false)` accepts a second parameter to defined resolved dependencies, and a third to ensure that a new object will be created.

```
$post = $container->make(Post::class, [Category::class => new Category], true);
```

#### Executing Closures

[](#executing-closures)

If you have a closure with dependencies you can use the `call($closure, $parameters = [])` method to resolve then.

```
$container->call(function (User $user, Posts $posts) {
    // ...
});
```

And as well as `make`, you can pass an array of resolved dependencies.

```
$container->call(function (User $user, Posts $posts) {}, [User::class => new User]);
```

### Extending Bindings

[](#extending-bindings)

Some times you need to modify a binding, to do that use the `extend` method. They receive the old binding object and a container reference.

```
$container->set('app.services.mail', App\Services\MailService::class);

$container->extend('app.services.mail', function ($instance, $container) {
	$instance->environment('development');

    $instance->setHtmlWrapper($container->get('app.wrappers.html'));

	return $instance;
});
```

Exceptions
----------

[](#exceptions)

The [Codeburner](http://github.com/codeburnerframework) Container implements [PSR-11](https://github.com/php-fig/fig-standards/blob/master/proposed/container.md) providing two types of exceptions, the `Psr\Container\Exception\NotFoundException` and `Psr\Container\Exception\ContainerException`.

- [ContainerException](https://github.com/codeburnerframework/container/blob/master/src/exceptions/ContainerException.php)
    - [NotFoundException](https://github.com/codeburnerframework/container/blob/master/src/exceptions/NotFoundException.php)

API
---

[](#api)

- [Container](https://github.com/codeburnerframework/container/blob/master/src/container.php)
    - `call(closure $closure, array $parameters = []) : mixed` Execute a closure resolving its dependencies
    - `make(string $abstract, array $parameters = [], bool $force = false) : mixed` Resolve something in the container
    - `flush() : Container` Renew the container
    - `get(string $abstract) : mixed` Get something stored in the container
    - `has(string $abstract) : bool` Verify if something is stored in the container
    - `set(string $abstract, $concrete, bool $shared = false) : Container` Store something in the container
    - `setIf(string $abstract, $concrete, bool $shared = false) : Container` Store something in the container if it does not already exists
    - `setTo(string $abstract, string $dependencyName, $dependency) : Container` Define a resolved dependency to something in the container
    - `singleton(string $abstract, $concrete) : Container` Store a new singleton object
    - `instance(string $abstract, $concrete) : Container` Store a new instantiated class
    - `isSingleton(string $abstract) : bool` Verify if something in the container is a singleton
    - `isInstance(string $abstract) : bool` Verify if something in the container is a instance
    - `extend(string $abstract, closure $extender) : Container` Wrap something instantiation
    - `share(string $abstract) : Container` Convert something to a singleton

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity60

Established project with proven stability

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 ~297 days

Total

2

Last Release

3446d ago

Major Versions

v1.0.0 → v2.0.02016-12-11

PHP version history (2 changes)v1.0.0PHP &gt;=5.4.0

v2.0.0PHP &gt;=7.0.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/d95f71c9d0a396641dbe1b8a2c809fd6564f94414197622110adf93010b38789?d=identicon)[alexrohleder](/maintainers/alexrohleder)

---

Tags

containerioccodeburner

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[php-di/php-di

The dependency injection container for humans

2.8k48.9M994](/packages/php-di-php-di)[slince/di

A flexible dependency injection container

20260.4k6](/packages/slince-di)[capsule/di

A PSR-11 compliant autowiring dependency injection container.

2857.5k2](/packages/capsule-di)[godruoyi/easy-container

A small PHP 5.3 dependency injection container extended from Laravel container.

334.9k2](/packages/godruoyi-easy-container)[miladrahimi/phpcontainer

Dependency injection (IoC) container for PHP projects

1322.7k2](/packages/miladrahimi-phpcontainer)

PHPackages © 2026

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