{"id":19214206,"url":"https://github.com/igniphp/container","last_synced_at":"2026-03-11T16:39:27.314Z","repository":{"id":56989372,"uuid":"123429442","full_name":"igniphp/container","owner":"igniphp","description":"Igni container","archived":false,"fork":false,"pushed_at":"2018-03-20T16:58:02.000Z","size":12,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-20T19:36:49.849Z","etag":null,"topics":["container","dependency-injection","php","psr-11"],"latest_commit_sha":null,"homepage":null,"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/igniphp.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}},"created_at":"2018-03-01T12:03:21.000Z","updated_at":"2024-12-25T03:34:46.000Z","dependencies_parsed_at":"2022-08-21T09:40:44.727Z","dependency_job_id":null,"html_url":"https://github.com/igniphp/container","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igniphp%2Fcontainer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igniphp%2Fcontainer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igniphp%2Fcontainer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igniphp%2Fcontainer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/igniphp","download_url":"https://codeload.github.com/igniphp/container/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253831151,"owners_count":21971040,"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","dependency-injection","php","psr-11"],"created_at":"2024-11-09T14:09:28.210Z","updated_at":"2026-03-11T16:39:22.286Z","avatar_url":"https://github.com/igniphp.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ![Igni logo](https://github.com/igniphp/common/blob/master/logo/full.svg) ![Build Status](https://travis-ci.org/igniphp/container.svg?branch=master)\n\n## Igni Container\nLicensed under MIT License.\n\n**Igni** container is a `psr-container` compliant lightweight service locator pattern implementation.\n\n## List of features:\n- **Simple usage** if you are familiar with `psr-container` there is no learning-curve required for basic usage\n- **Context aware** you can define custom instances of services for given use-cases.\n- **Auto wiring** required dependencies are auto-injected into your service\n\n## Installation\n\n```\ncomposer install igniphp/container\n```\n\n### Basic usage\n\n```php\n\u003c?php\n$serviceLocator = new Igni\\Container\\ServiceLocator();\n$serviceLocator-\u003eset('my_awesome_service', new stdClass());\n\n$myService = $serviceLocator-\u003eget('my_awesome_service');\n\nvar_dump($myService === $serviceLocator-\u003eget('my_awesome_service')); // returns true\n```\n\n### Registering shared service\n\nShared services are services which are instantiated only once and reference is kept in the\nregistry that way every time service is requested from the container it will return the same\ninstance.\n\n```php\n\u003c?php\nuse Igni\\Container\\ServiceLocator;\n\nclass Service \n{\n    public $a;\n    \n    public function __construct(int $a = 1) \n    {\n        $this-\u003ea = $a;    \n    }\n}\n\n$serviceLocator = new ServiceLocator();\n$serviceLocator-\u003eshare(Service::class, function() { return new Service(2); });\n\nvar_dump($serviceLocator-\u003eget(Service::class)-\u003ea === 2); //true\nvar_dump($serviceLocator-\u003eget(Service::class) === $serviceLocator-\u003eget(Service::class)); // true\n```\n\n### Factored services\n\nFactored services are instantiated every time container is asked for the service.\n\n```php\n\u003c?php\nuse Igni\\Container\\ServiceLocator;\n\nclass Service \n{\n    public $a;\n    \n    public function __construct(int $a = 1) \n    {\n        $this-\u003ea = $a;    \n    }\n}\n\n$serviceLocator = new ServiceLocator();\n$serviceLocator-\u003efactory(Service::class, function() { return new Service(2); });\n\nvar_dump($serviceLocator-\u003eget(Service::class)-\u003ea === 2); //true\nvar_dump($serviceLocator-\u003eget(Service::class) === $serviceLocator-\u003eget(Service::class)); // false\n```\n\n### Auto-wiring\nAuto-wiring allows you to simply pass fully qualified class name and all type-hinted arguments for that class \nwill be resolved automatically by the container.\n\n\n```php\n\u003c?php\nuse Igni\\Container\\ServiceLocator;\n\nclass A\n{\n    \n}\n\nclass Service \n{\n    public $a;\n    public $number;\n    \n    public function __construct(int $number = 7, A $a) \n    {\n        $this-\u003enumber = $number;\n        $this-\u003ea = $a;    \n    }\n}\n\n$serviceLocator = new ServiceLocator();\n$serviceLocator-\u003eshare(A::class);\n$serviceLocator-\u003eshare(Service::class);\n\nvar_dump($serviceLocator-\u003eget(Service::class)-\u003ea instanceof A);// true\n```\n\nThat's all folks!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Figniphp%2Fcontainer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Figniphp%2Fcontainer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Figniphp%2Fcontainer/lists"}