{"id":20540579,"url":"https://github.com/utopia-php/di","last_synced_at":"2026-04-01T21:28:32.408Z","repository":{"id":229514494,"uuid":"776890267","full_name":"utopia-php/di","owner":"utopia-php","description":"Lite \u0026 fast micro PHP dependency injections library that is **easy to use**.","archived":false,"fork":false,"pushed_at":"2026-03-21T07:42:37.000Z","size":183,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":5,"default_branch":"main","last_synced_at":"2026-03-21T22:19:49.230Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/utopia-php.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-03-24T18:16:01.000Z","updated_at":"2026-03-21T07:42:16.000Z","dependencies_parsed_at":"2024-04-07T06:26:25.537Z","dependency_job_id":"61d2f09a-e5e1-4fe1-b811-1ecf6211572b","html_url":"https://github.com/utopia-php/di","commit_stats":null,"previous_names":["utopia-php/di"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/utopia-php/di","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/utopia-php%2Fdi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/utopia-php%2Fdi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/utopia-php%2Fdi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/utopia-php%2Fdi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/utopia-php","download_url":"https://codeload.github.com/utopia-php/di/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/utopia-php%2Fdi/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31292271,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-01T21:15:39.731Z","status":"ssl_error","status_checked_at":"2026-04-01T21:15:34.046Z","response_time":53,"last_error":"SSL_read: 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":"2024-11-16T01:16:23.535Z","updated_at":"2026-04-01T21:28:32.395Z","avatar_url":"https://github.com/utopia-php.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp\u003e\n    \u003cimg height=\"45\" src=\"docs/logo.png\" alt=\"Logo\"\u003e\n\u003c/p\u003e\n\n[![CI](https://github.com/utopia-php/di/actions/workflows/ci.yml/badge.svg)](https://github.com/utopia-php/di/actions/workflows/ci.yml)\n![Total Downloads](https://img.shields.io/packagist/dt/utopia-php/di.svg)\n[![Discord](https://img.shields.io/discord/564160730845151244?label=discord)](https://discord.gg/GSeTUeA)\n\nUtopia DI is a small PSR-11 compatible dependency injection container with parent-child scopes. It is designed to stay simple while still covering the dependency lifecycle used across the Utopia libraries. This library is maintained by the [Appwrite team](https://appwrite.io).\n\nAlthough this library is part of the Utopia Framework project it is dependency free, and can be used as standalone with any other PHP project or framework.\n\n## Getting Started\n\nInstall using Composer:\n\n```bash\ncomposer require utopia-php/di\n```\n\n```php\nrequire_once __DIR__.'/../vendor/autoload.php';\n\nuse Utopia\\DI\\Container;\n\n$di = new Container();\n\n$di-\u003eset('age', fn (): int =\u003e 25);\n\n$di-\u003eset(\n    'john',\n    fn (int $age): string =\u003e 'John Doe is '.$age.' years old.',\n    ['age']\n);\n\n$john = $di-\u003eget('john');\n```\n\nDependencies are resolved from the third `set()` argument and passed to the factory in that same order.\n\nRegister factories directly and list the dependency IDs they need.\n\n```php\n$di-\u003eset('config', fn (): array =\u003e [\n    'dsn' =\u003e 'mysql:host=localhost;dbname=app',\n    'username' =\u003e 'root',\n    'password' =\u003e 'secret',\n]);\n\n$di-\u003eset(\n    'db',\n    fn (array $config): PDO =\u003e new PDO(\n        $config['dsn'],\n        $config['username'],\n        $config['password']\n    ),\n    ['config']\n);\n```\n\nFactories are resolved once per container instance. A child container behaves in two distinct ways:\n\n- If the child does not define a key, it falls back to the parent and reuses the parent's resolved value.\n- If the child defines the same key locally, it resolves and caches its own value without changing the parent.\n\n```php\n$counter = 0;\n\n$di-\u003eset('requestId', function () use (\u0026$counter): string {\n    $counter++;\n\n    return 'request-'.$counter;\n});\n\n$di-\u003eget('requestId'); // \"request-1\"\n\n$child = new Container($di);\n\n$child-\u003eget('requestId'); // \"request-1\" (falls back to the parent cache)\n\n$child-\u003eset('requestId', function () use (\u0026$counter): string {\n    $counter++;\n\n    return 'request-'.$counter;\n});\n\n$child-\u003eget('requestId'); // \"request-2\" (child now uses its own local definition)\n$di-\u003eget('requestId'); // \"request-1\" (parent is unchanged)\n```\n\n## System Requirements\n\nUtopia DI requires PHP 8.2 or later. We recommend using the latest PHP version whenever possible.\n\n## More from Utopia\n\nOur ecosystem supports other thin PHP projects aiming to extend the core PHP Utopia libraries.\n\nEach project is focused on solving a single, very simple problem and you can use composer to include any of them in your next project.\n\nYou can find all libraries in [GitHub Utopia organization](https://github.com/utopia-php).\n\n## Contributing\n\nAll code contributions - including those of people having commit access - must go through a pull request and approved by a core developer before being merged. This is to ensure proper review of all the code.\n\nFork the project, create a feature branch, and send us a pull request.\n\nYou can refer to the [Contributing Guide](https://github.com/utopia-php/di/blob/master/CONTRIBUTING.md) for more info.\n\nFor security issues, please email security@appwrite.io instead of posting a public issue in GitHub.\n\n## Copyright and license\n\nThe MIT License (MIT) [http://www.opensource.org/licenses/mit-license.php](http://www.opensource.org/licenses/mit-license.php)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Futopia-php%2Fdi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Futopia-php%2Fdi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Futopia-php%2Fdi/lists"}