{"id":19112892,"url":"https://github.com/chipslays/container","last_synced_at":"2025-10-18T05:13:01.069Z","repository":{"id":210177914,"uuid":"725940314","full_name":"chipslays/container","owner":"chipslays","description":"📦 Yet another dependency injection container implementation with PSR-11 compliant for PHP 8.","archived":false,"fork":false,"pushed_at":"2024-04-10T04:59:26.000Z","size":13,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-03T04:52:30.137Z","etag":null,"topics":["container","di-container","php-container","php-di","php-di-container"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chipslays.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-12-01T07:31:53.000Z","updated_at":"2024-04-10T04:46:38.000Z","dependencies_parsed_at":null,"dependency_job_id":"95f17889-2cfc-4331-adb8-7b5c6945ecfc","html_url":"https://github.com/chipslays/container","commit_stats":{"total_commits":35,"total_committers":1,"mean_commits":35.0,"dds":0.0,"last_synced_commit":"ff1d23cc2da1c09f3de544b55b8bef2cf4651bd4"},"previous_names":["chipslays/container"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chipslays%2Fcontainer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chipslays%2Fcontainer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chipslays%2Fcontainer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chipslays%2Fcontainer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chipslays","download_url":"https://codeload.github.com/chipslays/container/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240170056,"owners_count":19759141,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["container","di-container","php-container","php-di","php-di-container"],"created_at":"2024-11-09T04:34:27.079Z","updated_at":"2025-10-18T05:13:00.987Z","avatar_url":"https://github.com/chipslays.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 📦 DI Container\n\nYet another implementation of dependency injection container with PSR-11 compliant for PHP \u003e8.0.\n\n## Installation\n\n```bash\ncomposer require please/container\n```\n\n## Basic usage\n\nThis example always returns a new instance of `Mailer`.\n\n```php\nuse Please\\Container\\Container;\nuse Please\\Container\\Support\\Getter;\n\n$container = new Container;\n\n$container-\u003ebind(Mailer::class, function (Getter $get) {\n    return new Mailer::($get('user'), $get('password', 'qwerty')); // qwerty - default value\n});\n\n/** @var Mailer */\n$mailer = $container-\u003eget(Mailer::class, [\n  'user' =\u003e 'admin',\n  // and password `qwerty` (default value)\n]);\n```\n\nThis example always return a same time.\n\n```php\nuse Please\\Container\\Container;\n\n$container = new Container;\n\n$container-\u003esingleton('random', fn () =\u003e rand());\n\necho $container-\u003eget('random'); // 1234567890\necho $container-\u003eget('random'); // 1234567890\n```\n\n## Examples\n\nYou can find usage examples [here](/examples).\n\n## Documentation\n\nYou can bind any abstract aliases.\n\n```php\nuse Please\\Container\\Container;\n\n$container = new Container;\n\n$container-\u003ebind(Foo::class);\n$container-\u003eget(Foo::class); // ok\n$container-\u003eget('foo'); // error\n\n// if you pass a class string\n// it is also automatically bind as `Foo::class`\n$container-\u003ebind('foo', Foo::class);\n$container-\u003eget(Foo::class); // ok\n$container-\u003eget('foo'); // ok\n\n// array of aliases\n$container-\u003ebind([Foo::class, 'foo', 'another-foo-alias'], Foo::class);\n$container-\u003eget(Foo::class); // ok\n$container-\u003eget('foo'); // ok\n$container-\u003eget('another-foo-alias'); // ok\n```\n\nYou can bind any primitive data types.\n\n```php\n$container-\u003ebind('foo', 'bar');\n$container-\u003ebind('foo', 1337);\n$container-\u003ebind('foo', 13.37);\n$container-\u003ebind('foo', true || false);\n$container-\u003ebind('foo', ['bar', 'baz']);\n$container-\u003ebind('foo', new stdClass);\n$container-\u003ebind('foo', fopen('php://stdout', 'r'));\n\n$container-\u003ebind('baz', null);\n$container-\u003eget('baz') // returns `baz`\n```\n\nGenerates a singleton instance of a class.\n\n\u003e Singleton method always returns same value or instance like typical singleton pattern.\n\n```php\n$container-\u003esingleton('timestamp', fn () =\u003e time());\n\n// or use bind class and `shared` parameter\n$container-\u003ebind('timestamp', fn () =\u003e time(), shared: true);\n```\n\nCheck if the container has a binding or instance for the given abstract.\n\n```php\n$container-\u003ebind('foo', 'bar');\n$container-\u003ehas('foo'); // true\n$container-\u003ehas('baz'); // false\n```\n\n## Singleton Pattern\n\nIf you really need to, you can use the container as a singleton.\n\n```php\nuse Please\\Container\\Container as BaseContainer;\nuse Please\\Container\\Support\\Traits\\Singleton;\n\nclass Container extends BaseContainer\n{\n    use Singleton;\n}\n\n...\n\n$container = Container::getInstance();\n\n...\n```\n\nYou can also check singleton example [here](/examples/singleton.php).\n\n## License\nOpen-sourced software licensed under the [MIT license](https://opensource.org/license/mit/).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchipslays%2Fcontainer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchipslays%2Fcontainer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchipslays%2Fcontainer/lists"}