{"id":26965443,"url":"https://github.com/parable-php/di","last_synced_at":"2025-07-31T09:10:38.906Z","repository":{"id":57035801,"uuid":"144151524","full_name":"parable-php/di","owner":"parable-php","description":"Parable DI is a no-nonsense dependency injection container.","archived":false,"fork":false,"pushed_at":"2025-02-01T08:33:51.000Z","size":55,"stargazers_count":5,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-03T07:22:57.079Z","etag":null,"topics":["dependency","dependency-injection","deps","di","parable","parable-di","php8","service-container"],"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/parable-php.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-08-09T12:45:39.000Z","updated_at":"2025-02-01T08:28:00.000Z","dependencies_parsed_at":"2022-08-24T14:11:12.209Z","dependency_job_id":null,"html_url":"https://github.com/parable-php/di","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/parable-php/di","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parable-php%2Fdi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parable-php%2Fdi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parable-php%2Fdi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parable-php%2Fdi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/parable-php","download_url":"https://codeload.github.com/parable-php/di/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parable-php%2Fdi/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268016961,"owners_count":24181657,"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","status":"online","status_checked_at":"2025-07-31T02:00:08.723Z","response_time":66,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["dependency","dependency-injection","deps","di","parable","parable-di","php8","service-container"],"created_at":"2025-04-03T07:21:28.373Z","updated_at":"2025-07-31T09:10:38.881Z","avatar_url":"https://github.com/parable-php.png","language":"PHP","readme":"# Parable DI Container\n\n[![Workflow Status](https://github.com/parable-php/di/workflows/Tests/badge.svg)](https://github.com/parable-php/di/actions?query=workflow%3ATests)\n[![Latest Stable Version](https://poser.pugx.org/parable-php/di/v/stable)](https://packagist.org/packages/parable-php/di)\n[![Latest Unstable Version](https://poser.pugx.org/parable-php/di/v/unstable)](https://packagist.org/packages/parable-php/di)\n[![License](https://poser.pugx.org/parable-php/di/license)](https://packagist.org/packages/parable-php/di)\n\nParable DI is a no-nonsense dependency injection container that gets the job done.\n\n## Install\n\nPhp 8.0+ and [composer](https://getcomposer.org) are required.\n\n```bash\n$ composer require parable-php/di\n```\n\n## Usage\n\nExample usage of a straightforward situation:\n\n```php\nuse \\Parable\\Di\\Container;\n\n$container = new Container();\n\n$app = $container-\u003eget(App::class);\n$app-\u003erun();\n```\n\nExample usage of an interface-hinted dependency being mapped:\n\n```php\nuse \\Parable\\Di\\Container;\n\n$container = new Container();\n\nclass App\n{\n    public function __construct(ThatInterface $classWithThatInterface)\n    {\n    }\n    \n    public function run()\n    {\n        echo \"Run? RUN!\";\n    }\n}\n\n$container-\u003emap(ThatInterface::class, ClassWithThatInterface::class);\n\n$app = $container-\u003eget(App::class);\n$app-\u003erun();\n```\n\nThe above situation can also be solved by instantiating and then storing `ClassWithThatInterface` under `ThatInterface`.\n\nExample usage of a class that needs the di itself, in case you need to do dynamic DI:\n\n```php\nuse \\Parable\\Di\\Container;\n\n$container = new Container();\n\nclass App\n{\n    public $container;\n    public function __construct(\n        public Container $container\n    ) {}\n}\n\n$app = $container-\u003eget(App::class);\nvar_dump($app-\u003econtainer-\u003ehas(App::class)); // output: bool(true)\n```\n\nFor all other use cases, simply check the tests in `tests/ContainerTest.php`.\n\n## API\n\n- `get(string $name): object` - creates or gets instance\n- `has(string $name): bool` - check if instance is stored\n- `assertHas(string $name): void` - check and throw exception if instance is not stored\n- `build(string $name): object` - build instance with stored deps, don't store\n- `buildAll(string $name): object` - build instance with new deps, don't store\n- `map(string $requested, string $replacement): void` - allow pre-emptively defining a replacement class to be instantiated when the requested name is retrieved or built. Use for lazy-loading classes, i.e. for interface deps.\n- `unmap(string $requested): void` - removes the mapping _and_ clears any previously mapped instances\n- `getDependenciesFor(string $name, [int $storedDependencies]): array` - get dependencies for instance, with stored (default) or new deps \n- `store(object $instance, [string $name]): void` - store instance under name, or under instance name by default\n- `clear(string $name): void` - clear instance\n- `clearExcept(array $keep): void` - clear all except provided names, throws if any of the instances to keep doesn't exist\n- `clearAll(): void` - clear all\n\nWhere `object` refers to any instance of any class.\n\n## Contributing\n\nAny suggestions, bug reports or general feedback is welcome. Use github issues and pull requests, or find me over at [devvoh.com](https://devvoh.com).\n\n## License\n\nAll Parable components are open-source software, licensed under the MIT license.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparable-php%2Fdi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fparable-php%2Fdi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparable-php%2Fdi/lists"}