{"id":18834296,"url":"https://github.com/chubbyphp/chubbyphp-container","last_synced_at":"2025-11-08T07:04:39.827Z","repository":{"id":56952656,"uuid":"223486316","full_name":"chubbyphp/chubbyphp-container","owner":"chubbyphp","description":"A minimal Dependency Injection Container (DIC) which implements PSR-11.","archived":false,"fork":false,"pushed_at":"2024-08-10T20:00:23.000Z","size":52,"stargazers_count":14,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-10T22:31:37.373Z","etag":null,"topics":["chubbyphp-container","container","psr-11","servicefactory"],"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/chubbyphp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2019-11-22T21:05:46.000Z","updated_at":"2024-12-04T00:08:47.000Z","dependencies_parsed_at":"2024-02-04T19:18:51.025Z","dependency_job_id":null,"html_url":"https://github.com/chubbyphp/chubbyphp-container","commit_stats":{"total_commits":57,"total_committers":3,"mean_commits":19.0,"dds":0.3157894736842105,"last_synced_commit":"a69189097174e9dfb562a61806b726064509ca73"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chubbyphp%2Fchubbyphp-container","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chubbyphp%2Fchubbyphp-container/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chubbyphp%2Fchubbyphp-container/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chubbyphp%2Fchubbyphp-container/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chubbyphp","download_url":"https://codeload.github.com/chubbyphp/chubbyphp-container/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230487844,"owners_count":18233865,"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":["chubbyphp-container","container","psr-11","servicefactory"],"created_at":"2024-11-08T02:11:49.373Z","updated_at":"2025-11-08T07:04:39.787Z","avatar_url":"https://github.com/chubbyphp.png","language":"PHP","readme":"# chubbyphp-container\n\n[![CI](https://github.com/chubbyphp/chubbyphp-container/actions/workflows/ci.yml/badge.svg)](https://github.com/chubbyphp/chubbyphp-container/actions/workflows/ci.yml)\n[![Coverage Status](https://coveralls.io/repos/github/chubbyphp/chubbyphp-container/badge.svg?branch=master)](https://coveralls.io/github/chubbyphp/chubbyphp-container?branch=master)\n[![Mutation testing badge](https://img.shields.io/endpoint?style=flat\u0026url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fchubbyphp%2Fchubbyphp-container%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/chubbyphp/chubbyphp-container/master)\n[![Latest Stable Version](https://poser.pugx.org/chubbyphp/chubbyphp-container/v)](https://packagist.org/packages/chubbyphp/chubbyphp-container)\n[![Total Downloads](https://poser.pugx.org/chubbyphp/chubbyphp-container/downloads)](https://packagist.org/packages/chubbyphp/chubbyphp-container)\n[![Monthly Downloads](https://poser.pugx.org/chubbyphp/chubbyphp-container/d/monthly)](https://packagist.org/packages/chubbyphp/chubbyphp-container)\n\n[![bugs](https://sonarcloud.io/api/project_badges/measure?project=chubbyphp_chubbyphp-container\u0026metric=bugs)](https://sonarcloud.io/dashboard?id=chubbyphp_chubbyphp-container)\n[![code_smells](https://sonarcloud.io/api/project_badges/measure?project=chubbyphp_chubbyphp-container\u0026metric=code_smells)](https://sonarcloud.io/dashboard?id=chubbyphp_chubbyphp-container)\n[![coverage](https://sonarcloud.io/api/project_badges/measure?project=chubbyphp_chubbyphp-container\u0026metric=coverage)](https://sonarcloud.io/dashboard?id=chubbyphp_chubbyphp-container)\n[![duplicated_lines_density](https://sonarcloud.io/api/project_badges/measure?project=chubbyphp_chubbyphp-container\u0026metric=duplicated_lines_density)](https://sonarcloud.io/dashboard?id=chubbyphp_chubbyphp-container)\n[![ncloc](https://sonarcloud.io/api/project_badges/measure?project=chubbyphp_chubbyphp-container\u0026metric=ncloc)](https://sonarcloud.io/dashboard?id=chubbyphp_chubbyphp-container)\n[![sqale_rating](https://sonarcloud.io/api/project_badges/measure?project=chubbyphp_chubbyphp-container\u0026metric=sqale_rating)](https://sonarcloud.io/dashboard?id=chubbyphp_chubbyphp-container)\n[![alert_status](https://sonarcloud.io/api/project_badges/measure?project=chubbyphp_chubbyphp-container\u0026metric=alert_status)](https://sonarcloud.io/dashboard?id=chubbyphp_chubbyphp-container)\n[![reliability_rating](https://sonarcloud.io/api/project_badges/measure?project=chubbyphp_chubbyphp-container\u0026metric=reliability_rating)](https://sonarcloud.io/dashboard?id=chubbyphp_chubbyphp-container)\n[![security_rating](https://sonarcloud.io/api/project_badges/measure?project=chubbyphp_chubbyphp-container\u0026metric=security_rating)](https://sonarcloud.io/dashboard?id=chubbyphp_chubbyphp-container)\n[![sqale_index](https://sonarcloud.io/api/project_badges/measure?project=chubbyphp_chubbyphp-container\u0026metric=sqale_index)](https://sonarcloud.io/dashboard?id=chubbyphp_chubbyphp-container)\n[![vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=chubbyphp_chubbyphp-container\u0026metric=vulnerabilities)](https://sonarcloud.io/dashboard?id=chubbyphp_chubbyphp-container)\n\n\n## Description\n\nA minimal Dependency Injection Container (DIC) which implements PSR-11. [DI Container Benchmark][3].\n\nThere is a laminas service manager adapter at [chubbyphp/chubbyphp-laminas-config][4].\n\n## Requirements\n\n * php: ^8.2\n * [psr/container][2]: ^2.0.2\n\n## Installation\n\nThrough [Composer](http://getcomposer.org) as [chubbyphp/chubbyphp-container][1].\n\n```sh\ncomposer require chubbyphp/chubbyphp-container \"^2.3\"\n```\n\n## Usage\n\nThere are two PSR-11 implementations:\n\n * `Chubbyphp\\Container\\Container` prototype (each get will return a new instance) and shared services\n * `Chubbyphp\\Container\\MinimalContainer` shared services\n\n### MinimalContainer / Container\n\n#### Factories\n\n```php\n\u003c?php\n\nuse App\\Service\\MyService;\nuse Chubbyphp\\Container\\MinimalContainer;\nuse Psr\\Container\\ContainerInterface;\nuse Psr\\Log\\LoggerInterface;\n\n$container = new MinimalContainer();\n$container-\u003efactories([\n    MyService::class =\u003e static function (ContainerInterface $container): MyService {\n        return new MyService($container-\u003eget(LoggerInterface::class));\n    },\n]);\n```\n\n#### Factory\n\n```php\n\u003c?php\n\nuse App\\Service\\MyService;\nuse Chubbyphp\\Container\\MinimalContainer;\nuse Psr\\Container\\ContainerInterface;\nuse Psr\\Log\\LoggerInterface;\n\n$container = new MinimalContainer();\n\n// new\n$container-\u003efactory(MyService::class, static function (ContainerInterface $container): MyService {\n    return new MyService($container-\u003eget(LoggerInterface::class));\n});\n\n// existing (replace)\n$container-\u003efactory(MyService::class, static function (ContainerInterface $container): MyService {\n    return new MyService($container-\u003eget(LoggerInterface::class));\n});\n\n// existing (extend)\n$container-\u003efactory(\n    MyService::class,\n    static function (ContainerInterface $container, callable $previous): MyService {\n        $myService = $previous($container);\n        $myService-\u003esetLogger($container-\u003eget(LoggerInterface::class));\n\n        return $myService;\n    }\n);\n```\n\n#### Factory with Parameter\n\n```php\n\u003c?php\n\nuse Chubbyphp\\Container\\MinimalContainer;\nuse Chubbyphp\\Container\\Parameter;\n\n$container = new MinimalContainer();\n$container-\u003efactory('key', new Parameter('value'));\n```\n\n#### Get\n\n```php\n\u003c?php\n\nuse App\\Service\\MyService;\nuse Chubbyphp\\Container\\MinimalContainer;\n\n$container = new MinimalContainer();\n\n$myService = $container-\u003eget(MyService::class);\n```\n\n#### Has\n\n```php\n\u003c?php\n\nuse App\\Service\\MyService;\nuse Chubbyphp\\Container\\MinimalContainer;\n\n$container = new MinimalContainer();\n$container-\u003ehas(MyService::class);\n```\n\n### Container\n\nAll methods of the `MinimalContainer` and the following:\n\n#### Prototype Factories\n\n**each get will return a new instance**\n\n```php\n\u003c?php\n\nuse App\\Service\\MyService;\nuse Chubbyphp\\Container\\Container;\nuse Psr\\Container\\ContainerInterface;\nuse Psr\\Log\\LoggerInterface;\n\n$container = new Container();\n$container-\u003eprototypeFactories([\n    MyService::class =\u003e static function (ContainerInterface $container): MyService {\n        return new MyService($container-\u003eget(LoggerInterface::class));\n    },\n]);\n```\n\n#### Prototype Factory\n\n**each get will return a new instance**\n\n```php\n\u003c?php\n\nuse App\\Service\\MyService;\nuse Chubbyphp\\Container\\Container;\nuse Psr\\Container\\ContainerInterface;\nuse Psr\\Log\\LoggerInterface;\n\n$container = new Container();\n\n// new\n$container-\u003eprototypeFactory(\n    MyService::class,\n    static function (ContainerInterface $container): MyService {\n        return new MyService($container-\u003eget(LoggerInterface::class));\n    }\n);\n\n// existing (replace)\n$container-\u003eprototypeFactory(\n    MyService::class,\n    static function (ContainerInterface $container): MyService {\n        return new MyService($container-\u003eget(LoggerInterface::class));\n    }\n);\n\n// existing (extend)\n$container-\u003eprototypeFactory(\n    MyService::class,\n    static function (ContainerInterface $container, callable $previous): MyService {\n        $myService = $previous($container);\n        $myService-\u003esetLogger($container-\u003eget(LoggerInterface::class));\n\n        return $myService;\n    }\n);\n```\n\n## Migration\n\n* [From Pimple][5]\n\n## Copyright\n\n2025 Dominik Zogg\n\n[1]: https://packagist.org/packages/chubbyphp/chubbyphp-container\n[2]: https://packagist.org/packages/psr/container\n[3]: https://kocsismate.github.io/php-di-container-benchmarks/benchmark.html\n[4]: https://github.com/chubbyphp/chubbyphp-laminas-config\n[5]: doc/MigrateFromPimple.md\n","funding_links":[],"categories":["PHP"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchubbyphp%2Fchubbyphp-container","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchubbyphp%2Fchubbyphp-container","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchubbyphp%2Fchubbyphp-container/lists"}