{"id":37015795,"url":"https://github.com/codeburnerframework/container","last_synced_at":"2026-01-14T01:36:26.897Z","repository":{"id":32924871,"uuid":"36520498","full_name":"codeburnerframework/container","owner":"codeburnerframework","description":"The faster IoC container package for you build applications for the web.","archived":false,"fork":false,"pushed_at":"2016-12-18T21:44:15.000Z","size":107,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-13T10:49:27.825Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codeburnerframework.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-29T17:58:33.000Z","updated_at":"2022-04-07T23:58:43.000Z","dependencies_parsed_at":"2022-08-19T19:40:51.510Z","dependency_job_id":null,"html_url":"https://github.com/codeburnerframework/container","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/codeburnerframework/container","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeburnerframework%2Fcontainer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeburnerframework%2Fcontainer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeburnerframework%2Fcontainer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeburnerframework%2Fcontainer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codeburnerframework","download_url":"https://codeload.github.com/codeburnerframework/container/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeburnerframework%2Fcontainer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28408654,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T00:40:43.272Z","status":"ssl_error","status_checked_at":"2026-01-14T00:40:42.636Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-01-14T01:36:26.210Z","updated_at":"2026-01-14T01:36:26.889Z","avatar_url":"https://github.com/codeburnerframework.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Codeburner Container\n\n[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](LICENSE)\n[![Build Status](https://img.shields.io/travis/codeburnerframework/container/master.svg)](https://travis-ci.org/codeburnerframework/container)\n[![Code Coverage](https://scrutinizer-ci.com/g/codeburnerframework/container/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/codeburnerframework/container/?branch=master)\n[![Quality Score](https://img.shields.io/scrutinizer/g/codeburnerframework/container.svg)](https://scrutinizer-ci.com/g/codeburnerframework/container)\n\n[![SensioLabsInsight](https://insight.sensiolabs.com/projects/9af2c429-cc7f-4c71-8eac-e3c3ddd4c1d2/big.png)](https://insight.sensiolabs.com/projects/9af2c429-cc7f-4c71-8eac-e3c3ddd4c1d2)\n\nThe faster IoC container package for you build blazing fast applications for the web.\n\nThanks 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.\n\n##Instalation\n\nAdd `codeburner/container` to your `composer.json` file, and update or install composer dependencies.\n\n```json\n{\n    \"require\": {\n        \"codeburner/container\": \"^2.0\"\n    }\n}\n```\n\nor via CLI:\n\n```bash\n$ composer require codeburner/container --save\n```\n\n##Usage\n\n- [Introduction](#introduction)\n\t- [Performance](#performance)\n\t- [Concepts](#concepts)\n\t- [Usage](#usage)\n        - [Examples](#examples)\n- [Bindings](#bindings)\n\t- [Binding Types](#binding-types)\n\t\t- [Resolvable Bindings](#resolvable-bindings)\n\t\t- [Resolved Bindings](#resolved-bindings)\n\t- [Binding Ways](#binding-ways)\n\t\t- [Strings](#strings)\n\t\t- [Closures](#closures)\n\t\t- [Instances](#instances)\n\t- [Resolving Bindings](#resolving-bindings)\n\t\t- [Setting Dependencies Manually](#setting-dependencies-manually)\n\t- [Extending Bindings](#extending-bindings)\n- [Exceptions](#exceptions)\n- [API](#api)\n\n## Introduction\nWelcome 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.\n\n### Performance\n[Codeburner](http://github.com/codeburnerframework) project create packages with performance in focus, and the benchmarks are comming!\n\n### Concepts\nThe 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.\n\n### Usage\nAfter you have the classes ready to be instantiate, you only need to register the bindings and call then.\n\n```php\nuse Codeburner\\Container\\Container;\n\n$container = new Container;\n\n// Regiser a \"stdClass\" class to a \"std\" key.\n$container-\u003eset('std', 'stdClass');\n\n// Accessing new \"stdClass\" objects.\n$container-\u003eget('std');\n```\n\n#### Examples\nUsage examples are comming soon.\n\n## Bindings\nBindings 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.\n\n```php\nclass ClassA {\n\tpublic function __construct(stdClass $dependency) {\n\n\t}\n}\n\n$container-\u003eset('my-a', 'ClassA');\n\nif ($container-\u003ehas('my-a')) {\n\t$container-\u003eget('my-a');\n}\n```\n\n### Binding Types\n\n#### Resolvable Bindings\nResolvable bindings will return a new instance in every access.\n\n```php\n$container-\u003eset('app.model.posts', App\\Model\\Post::class);\n\n$obj1 = $container-\u003eget('app.model.posts'); // App\\Model\\Post#1\n$obj2 = $container-\u003eget('app.model.posts'); // App\\Model\\Post#2\n```\n\n#### Resolved Bindings\nResolved bindings are no more than singletons, every access will return the same instance.\n\n```php\n// you can define by passing a third parameter to set\n$container-\u003eset('database', App\\Database::class, true);\n// or using the `singleton` method\n$container-\u003esingleton('database', App\\Database::class);\n\n$obj1 = $container-\u003eget('database'); // App\\Database#1\n$obj2 = $container-\u003eget('database'); // App\\Database#1\n```\n\n### Binding Ways\n#### Strings\nThe simplest way to define a binding, you only need to give a class name as string.\n\n```php\nclass ClassNameTest {\n\n}\n\n$container-\u003eset('someobj', ClassNameTest::class);\n```\n\n#### Closures\nSome times you need to set some attributes or make some initial logic on objects, you can do it with a closure binding.\n\n```php\n$container-\u003eset('someobj', function ($container) {\n\t$obj = new stdClass;\n\t$obj-\u003eattribute = 1;\n\n\treturn $obj;\n});\n```\n\n#### Instances\nIf you need to attach an existent instance, you should use the `set` or `instance` method.\n\n```php\n$obj = new stdClass;\n\n// you can set instances directly by the set method\n$container-\u003eset('std', $obj);\n// or use the `instance` method\n$container-\u003einstance('std', $obj);\n```\n\n### Resolving Bindings\nThe 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.\n\n```php\nclass Post {\n\tpublic function __construct(Category $category) {\n\t\t$this-\u003ecategory = $category;\n\t}\n}\n\nclass Category {\n\tpublic function __construct() {\n\t\t$this-\u003eid = rand();\n\t}\n}\n\n$post = $container-\u003emake(Post::class);\n\necho $post-\u003ecategory-\u003eid;\n```\n\n#### Setting Dependencies Manually\nSometimes you want to define that some class will receive a specific object of another class on instantiation.\n\n```php\nclass Post {\n\tpublic function __construct(Category $category) {\n\t\t$this-\u003ecategory = $category;\n\t}\n}\n\nclass Category {\n\tpublic function __construct() {\n\t\t$this-\u003eid = rand();\n\t}\n}\n\n$category = new Category;\n$category-\u003eid = 1;\n\n$container-\u003esetTo(Post::class, Category::class, $category);\n$post = $container-\u003emake(Post::class);\n\necho $post-\u003ecategory-\u003eid; // 1\n```\n\n`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.\n\n```php\n$post = $container-\u003emake(Post::class, [Category::class =\u003e new Category], true);\n```\n\n#### Executing Closures\nIf you have a closure with dependencies you can use the `call($closure, $parameters = [])` method to resolve then.\n\n```php\n$container-\u003ecall(function (User $user, Posts $posts) {\n    // ...\n});\n```\nAnd as well as `make`, you can pass an array of resolved dependencies.\n\n```php\n$container-\u003ecall(function (User $user, Posts $posts) {}, [User::class =\u003e new User]);\n```\n\n### Extending Bindings\nSome times you need to modify a binding, to do that use the `extend` method. They receive the old binding object and a container reference.\n\n```php\n$container-\u003eset('app.services.mail', App\\Services\\MailService::class);\n\n$container-\u003eextend('app.services.mail', function ($instance, $container) {\n\t$instance-\u003eenvironment('development');\n\n    $instance-\u003esetHtmlWrapper($container-\u003eget('app.wrappers.html'));\n\n\treturn $instance;\n});\n```\n\n## Exceptions\nThe [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`.\n\n- [ContainerException](https://github.com/codeburnerframework/container/blob/master/src/exceptions/ContainerException.php)\n    - [NotFoundException](https://github.com/codeburnerframework/container/blob/master/src/exceptions/NotFoundException.php)\n\n## API\n\n- [Container](https://github.com/codeburnerframework/container/blob/master/src/container.php)\n    - `call(closure $closure, array $parameters = []) : mixed` Execute a closure resolving its dependencies\n    - `make(string $abstract, array $parameters = [], bool $force = false) : mixed` Resolve something in the container\n    - `flush() : Container` Renew the container\n    - `get(string $abstract) : mixed` Get something stored in the container\n    - `has(string $abstract) : bool` Verify if something is stored in the container\n    - `set(string $abstract, $concrete, bool $shared = false) : Container` Store something in the container\n    - `setIf(string $abstract, $concrete, bool $shared = false) : Container` Store something in the container if it does not already exists\n    - `setTo(string $abstract, string $dependencyName, $dependency) : Container` Define a resolved dependency to something in the container\n    - `singleton(string $abstract, $concrete) : Container` Store a new singleton object\n    - `instance(string $abstract, $concrete) : Container` Store a new instantiated class\n    - `isSingleton(string $abstract) : bool` Verify if something in the container is a singleton\n    - `isInstance(string $abstract) : bool` Verify if something in the container is a instance\n    - `extend(string $abstract, closure $extender) : Container` Wrap something instantiation\n    - `share(string $abstract) : Container` Convert something to a singleton\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeburnerframework%2Fcontainer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodeburnerframework%2Fcontainer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeburnerframework%2Fcontainer/lists"}