{"id":14966402,"url":"https://github.com/yiisoft/injector","last_synced_at":"2025-04-07T05:15:47.300Z","repository":{"id":34934177,"uuid":"191938470","full_name":"yiisoft/injector","owner":"yiisoft","description":"PSR-11 compatible injector","archived":false,"fork":false,"pushed_at":"2024-09-07T09:21:16.000Z","size":298,"stargazers_count":43,"open_issues_count":6,"forks_count":18,"subscribers_count":20,"default_branch":"master","last_synced_at":"2024-10-29T14:35:40.450Z","etag":null,"topics":["dependency-injection","hacktoberfest","injector","psr-11","yii3"],"latest_commit_sha":null,"homepage":"https://www.yiiframework.com/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yiisoft.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"open_collective":"yiisoft","github":["yiisoft"]}},"created_at":"2019-06-14T12:21:22.000Z","updated_at":"2024-09-07T09:21:18.000Z","dependencies_parsed_at":"2023-12-13T03:37:39.742Z","dependency_job_id":"da056cfc-eb55-4219-b5f1-7eeeda75282a","html_url":"https://github.com/yiisoft/injector","commit_stats":{"total_commits":156,"total_committers":14,"mean_commits":"11.142857142857142","dds":0.5769230769230769,"last_synced_commit":"b2ef2371c4fc63f32be1f27a233588ccc54ca886"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":"yiisoft/package-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Finjector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Finjector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Finjector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Finjector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yiisoft","download_url":"https://codeload.github.com/yiisoft/injector/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246086742,"owners_count":20721404,"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":["dependency-injection","hacktoberfest","injector","psr-11","yii3"],"created_at":"2024-09-24T13:36:20.018Z","updated_at":"2025-03-30T22:11:48.231Z","avatar_url":"https://github.com/yiisoft.png","language":"PHP","funding_links":["https://opencollective.com/yiisoft","https://github.com/sponsors/yiisoft"],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/yiisoft\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://yiisoft.github.io/docs/images/yii_logo.svg\" height=\"100px\" alt=\"Yii\"\u003e\n    \u003c/a\u003e\n    \u003ch1 align=\"center\"\u003eYii Injector\u003c/h1\u003e\n    \u003cbr\u003e\n\u003c/p\u003e\n\n[![Latest Stable Version](https://poser.pugx.org/yiisoft/injector/v)](https://packagist.org/packages/yiisoft/injector)\n[![Total Downloads](https://poser.pugx.org/yiisoft/injector/downloads)](https://packagist.org/packages/yiisoft/injector)\n[![Build status](https://github.com/yiisoft/injector/actions/workflows/build.yml/badge.svg?branch=master)](https://github.com/yiisoft/injector/actions/workflows/build.yml?query=branch%3Amaster)\n[![Code Coverage](https://codecov.io/gh/yiisoft/injector/graph/badge.svg?token=UX1E0SFD1P)](https://codecov.io/gh/yiisoft/injector)\n[![Mutation testing badge](https://img.shields.io/endpoint?style=flat\u0026url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyiisoft%2Finjector%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/injector/master)\n[![Static analysis](https://github.com/yiisoft/injector/actions/workflows/static.yml/badge.svg?branch=master)](https://github.com/yiisoft/injector/actions/workflows/static.yml?query=branch%3Amaster)\n[![type-coverage](https://shepherd.dev/github/yiisoft/injector/coverage.svg)](https://shepherd.dev/github/yiisoft/injector)\n\nA [dependency injection](https://en.wikipedia.org/wiki/Dependency_injection)\nimplementation based on autowiring and\n[PSR-11](https://www.php-fig.org/psr/psr-11/) compatible dependency injection containers.\n\n#### Features\n\n- Injects dependencies when calling functions and creating objects\n- Works with any dependency injection container (DIC) that is [PSR-11](https://www.php-fig.org/psr/psr-11/) compatible\n- Accepts additional dependencies and arguments passed as array\n- Allows passing arguments *by parameter name* in the array\n- Resolves object type dependencies from the container and the passed array\n   by [parameter type declaration](https://www.php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration)\n- Resolves [variadic arguments](https://www.php.net/manual/en/functions.arguments.php#functions.variable-arg-list)\n   i.e. `function (MyClass ...$a)`\n\n## Requirements\n\n- PHP 7.4 or higher.\n\n## Installation\n\nThe package could be installed with [Composer](https://getcomposer.org):\n\n```shell\ncomposer require yiisoft/injector\n```\n\n## About\n\nInjector can automatically resolve and inject dependencies when calling\nfunctions and creating objects.\n\nIt therefore uses [Reflection](https://www.php.net/manual/en/book.reflection.php) to analyze the\nparameters of the function to call, or the constructor of the class to\ninstantiate and then tries to resolve all arguments by several strategies.\n\nThe main purpose is to find dependency objects - that is arguments of type\nobject that are declared with a classname or an interface - in a (mandatory)\n[PSR-11](https://www.php-fig.org/psr/psr-11/) compatible *dependency injection\ncontainer* (DIC). The container must therefore use the class or interface name\nas ID.\n\nIn addition, an array with arguments can be passed that will also be scanned for\nmatching dependencies. To make things really flexible (and not limited to\nobjects), arguments in that array can optionally use a function parameter name\nas key. This way basically any callable can be invoked and any object\nbe instantiated by the Injector even if it uses a mix of object dependencies and\narguments of other types.\n\n## Basic Example\n\n```php\nuse Yiisoft\\Injector\\Injector;\n\n// A function to call\n$fn = function (\\App\\Foo $a, \\App\\Bar $b, int $c) { /* ... */ };\n\n// Arbitrary PSR-11 compatible object container\n$container = new \\some\\di\\Container([\n    'App\\Foo' =\u003e new Foo(), // will be used as $a\n]);\n\n// Prepare the injector\n$injector = new Injector($container);\n\n// Use the injector to call the function and resolve dependencies\n$result = $injector-\u003einvoke($fn, [\n    'c' =\u003e 15,  // will be used as $c\n    new Bar(),  // will be used as $b\n]);\n```\n\n### Caching reflection objects\n\nEnable caching of reflection objects to improve performance by calling `withCacheReflections(true)`:\n\n```php\nuse Yiisoft\\Injector\\Injector;\n\n$injector = (new Injector($container))\n    -\u003ewithCacheReflections(true);\n```\n\nBy default, caching is disabled.\n\n## Documentation\n\n- Guide: [English](docs/guide/en/README.md), [Português - Brasil](docs/guide/pt-BR/README.md), [Русский](docs/guide/ru/README.md)\n- [Internals](docs/internals.md)\n\nIf you need help or have a question, the [Yii Forum](https://forum.yiiframework.com/c/yii-3-0/63) is a good place for that.\nYou may also check out other [Yii Community Resources](https://www.yiiframework.com/community).\n\n## License\n\nThe Yii Injector is free software. It is released under the terms of the BSD License.\nPlease see [`LICENSE`](./LICENSE.md) for more information.\n\nMaintained by [Yii Software](https://www.yiiframework.com/).\n\n## Support the project\n\n[![Open Collective](https://img.shields.io/badge/Open%20Collective-sponsor-7eadf1?logo=open%20collective\u0026logoColor=7eadf1\u0026labelColor=555555)](https://opencollective.com/yiisoft)\n\n## Follow updates\n\n[![Official website](https://img.shields.io/badge/Powered_by-Yii_Framework-green.svg?style=flat)](https://www.yiiframework.com/)\n[![Twitter](https://img.shields.io/badge/twitter-follow-1DA1F2?logo=twitter\u0026logoColor=1DA1F2\u0026labelColor=555555?style=flat)](https://twitter.com/yiiframework)\n[![Telegram](https://img.shields.io/badge/telegram-join-1DA1F2?style=flat\u0026logo=telegram)](https://t.me/yii3en)\n[![Facebook](https://img.shields.io/badge/facebook-join-1DA1F2?style=flat\u0026logo=facebook\u0026logoColor=ffffff)](https://www.facebook.com/groups/yiitalk)\n[![Slack](https://img.shields.io/badge/slack-join-1DA1F2?style=flat\u0026logo=slack)](https://yiiframework.com/go/slack)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyiisoft%2Finjector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyiisoft%2Finjector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyiisoft%2Finjector/lists"}