{"id":33967345,"url":"https://github.com/acelot/resolver","last_synced_at":"2025-12-12T23:42:30.419Z","repository":{"id":48564417,"uuid":"83388198","full_name":"acelot/resolver","owner":"acelot","description":"Dependency auto resolver for PHP 7 and 8","archived":false,"fork":false,"pushed_at":"2021-07-20T08:15:41.000Z","size":58,"stargazers_count":12,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-11-01T02:18:39.175Z","etag":null,"topics":["dependency-injection","inversion-of-control","php","psr-11"],"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/acelot.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-28T04:08:56.000Z","updated_at":"2021-10-11T11:40:29.000Z","dependencies_parsed_at":"2022-09-04T10:53:04.901Z","dependency_job_id":null,"html_url":"https://github.com/acelot/resolver","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/acelot/resolver","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acelot%2Fresolver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acelot%2Fresolver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acelot%2Fresolver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acelot%2Fresolver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/acelot","download_url":"https://codeload.github.com/acelot/resolver/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acelot%2Fresolver/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27695323,"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-12-12T02:00:06.775Z","response_time":129,"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-injection","inversion-of-control","php","psr-11"],"created_at":"2025-12-12T23:42:29.483Z","updated_at":"2025-12-12T23:42:30.409Z","avatar_url":"https://github.com/acelot.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Resolver\n\n[![Build Status](https://travis-ci.org/acelot/resolver.svg?branch=master)](https://travis-ci.org/acelot/resolver)\n[![Code Climate](https://img.shields.io/codeclimate/coverage/acelot/resolver.svg)](https://codeclimate.com/github/acelot/resolver)\n![](https://img.shields.io/badge/dependencies-zero-blue.svg)\n![](https://img.shields.io/badge/license-MIT-green.svg)\n\n**Resolver** is a dependency auto resolver for PHP 7 and 8. Supports PSR-11 `ContainerInterface`.\n\n### Installation\n\n```\ncomposer require acelot/resolver\n```\n\n### Why?\n\nImagine that you have a controller:\n\n```php\nclass UsersController\n{\n    public function __construct(UsersService $service)\n    {\n        // ...\n    }\n}\n```\n\nAs you can see the controller requires `UsersService` in constructor. To resolve this dependency you can just pass\nthe new instance of `UsersService`. Let's do this:\n\n```php\n$service = new UsersService();\n$controller = new UsersController($service);\n```\n\nIt doesn't work, because `UsersService`, in turn, requires `UsersRepository` to access the data.\n\n```php\nclass UsersService\n{\n    public function __construct(UsersRepository $repository)\n    {\n        // ...\n    }\n}\n```\n\nOkay, let's create the repository instance!\n\n```php\n$repository = new UsersRepository();\n$service = new UsersService($repository);\n$controller = new UsersController($service);\n```\n\nSadly, it still doesn't work, because we encountering the new dependency! The repository, surprisingly, requires\na database connection :)\n\n```php\nclass UsersRepository\n{\n    public function __construct(Database $db)\n    {\n        // ...\n    }\n}\n```\n\nYou say \"Eat this!\".\n\n```php\n$db = new Database('connection string here');\n$repository = new UsersRepository($db);\n$service = new UsersService($repository);\n$controller = new UsersController($service);\n```\n\nSuccess! We have finally created the instance of `UsersController`!\nNow imagine that you have ten or hundred controllers like this?!\nWith **Resolver** you can greatly simplify creation of classes.\nIn what turns this code using **Resolver**:\n\n```php\n$resolver = new Resolver([\n    Database::class =\u003e ObjectDefinition::define(Database::class)-\u003ewithArgument('connectionString', 'connection string here')\n]);\n\n$controller = $resolver-\u003eresolve(UsersController::class);\n```\n\nAnd it's all.\n\n\n### How it works?\n\n**Resolver** resolves the classes by using [Reflection](http://php.net/manual/ru/book.reflection.php).\nThrough reflection the **Resolver** finds out all dependencies of the class and all dependencies of\ndependencies and so on. When **Resolver** reaches the deepest dependency it starts creating instances\nof these one by one until the top class. The resolved classes are stored in local array to avoid re-resolving.\n\n### Available definitions\n\n- FactoryDefinition (short alias `factory()`)\n- ObjectDefinition (short alias `object()`)\n- ValueDefinition (short alias `value()`)\n\n### Instance sharing\n\nResolved definitions can be shared between calls via `-\u003eshared()` method. This method available in `FactoryDefinition` and `ObjectDefinition`. `ValueDefinition` is shared always by design.\n\n---\n\n**Resolver** (c) by Valeriy Protopopov.\n\n**Resolver** is licensed under a MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Facelot%2Fresolver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Facelot%2Fresolver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Facelot%2Fresolver/lists"}