{"id":15027195,"url":"https://github.com/webdevcave/yadic-php","last_synced_at":"2026-01-30T23:41:50.305Z","repository":{"id":246136769,"uuid":"816542238","full_name":"WebdevCave/yadic-php","owner":"WebdevCave","description":"Yet another dependency injection container for PHP","archived":false,"fork":false,"pushed_at":"2024-07-06T02:38:59.000Z","size":107,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-15T20:42:20.901Z","etag":null,"topics":["autowiring","dependency-injection","hydration","object-hydration","php","php81","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/WebdevCave.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"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}},"created_at":"2024-06-18T00:51:21.000Z","updated_at":"2024-07-06T02:35:50.000Z","dependencies_parsed_at":"2024-06-28T15:00:50.252Z","dependency_job_id":"a875d6bf-4b6b-40c7-8b14-f0278917e933","html_url":"https://github.com/WebdevCave/yadic-php","commit_stats":null,"previous_names":["webdevcave/yadic-php"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebdevCave%2Fyadic-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebdevCave%2Fyadic-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebdevCave%2Fyadic-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebdevCave%2Fyadic-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WebdevCave","download_url":"https://codeload.github.com/WebdevCave/yadic-php/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240254186,"owners_count":19772387,"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":["autowiring","dependency-injection","hydration","object-hydration","php","php81","service-container"],"created_at":"2024-09-24T20:05:56.493Z","updated_at":"2026-01-30T23:41:50.244Z","avatar_url":"https://github.com/WebdevCave.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Yet another dependency injection container for PHP\n\n![StyleCi](https://github.styleci.io/repos/816542238/shield)\n[![Latest Stable Version](https://poser.pugx.org/webdevcave/yadic/v/stable?format=flat-square)](https://packagist.org/packages/webdevcave/yadic)\n[![Latest Unstable Version](https://poser.pugx.org/webdevcave/yadic/v/unstable?format=flat-square)](https://packagist.org/packages/webdevcave/yadic)\n[![Total Downloads](https://poser.pugx.org/webdevcave/yadic/downloads?format=flat-square)](https://packagist.org/packages/webdevcave/yadic)\n[![License](https://poser.pugx.org/webdevcave/yadic/license?format=flat-square)](https://packagist.org/packages/webdevcave/yadic)\n[![codecov](https://codecov.io/github/WebdevCave/yadic-php/graph/badge.svg?token=6GLECJQG16)](https://codecov.io/github/WebdevCave/yadic-php)\n\nThis is a simple to use, yet powerful service container that provides a seamless way to automate dependency injection\nfeaturing auto-wiring and object hydration.\n\n```bash\ncomposer require webdevcave/yadic\n```\n\nAlternatively, you can clone the repository or download the source files directly and include them in your project.\n\n## Usage\n\n### Autowiring\n\n```php\n\u003c?php\n\nrequire_once __DIR__.'/vendor/autoload.php';\n\nuse Webdevcave\\Yadic\\Annotations\\Provides;\nuse Webdevcave\\Yadic\\Annotations\\Singleton;\nuse Webdevcave\\Yadic\\ServiceContainer;\n\ninterface StorageInterface\n{\n    public function store(mixed $data): bool;\n}\n\n#[Provides('storage')]\n#[Provides(StorageInterface::class)]\n#[Singleton]\nclass Storage implements StorageInterface\n{\n    public function store(mixed $data): bool\n    {\n        //store data...\n\n        return true;\n    }\n}\n\nclass MyController\n{\n    public function __construct(\n        private StorageInterface $storage\n    ) {\n    }\n\n    public function save(): bool\n    {\n        return $this-\u003estorage-\u003estore('my data...');\n    }\n}\n\n$container = new ServiceContainer();\n\n//No need to do this in a real world application:\n$container-\u003eaddAlias(StorageInterface::class, Storage::class);\n\n//Use this instead:\n//$container-\u003eloadDefinitionsFromDirectory($directory, $namespace); //Loads annotations from classes declared in a PSR4 directory\n//var_dump($container-\u003eget('storage')-\u003estore($data));\n\nvar_dump($container-\u003eget(MyController::class)-\u003esave()); //bool(true)\n```\n\n### Invoking a method ft. autowiring\n\n```php\n$arguments = ['nonInjectableArgument' =\u003e 'value']; //optional\n$container-\u003einvoke([$instance, 'methodName'], $arguments);\n```\n\n### Hydration\n\n```php\n//Class declarations:\n\nuse Webdevcave\\Yadic\\Annotations\\ArrayOf;\n\nclass Candidate\n{\n    public function __construct(\n        public ?string $name = null,\n        public ?int $age = null,\n        #[ArrayOf(Skill::class)]\n        public array $skills = []\n    ) {\n    }\n}\n\nclass Skill\n{\n    public function __construct(\n        public string $title,\n    ) {\n    }\n}\n\n// Hydration example 1:\n$data = [\n    'name'   =\u003e 'John Doe',\n    'age'    =\u003e 25,\n    'skills' =\u003e [\n        ['title' =\u003e 'PHP'],\n        ['title' =\u003e 'Java'],\n        ['title' =\u003e 'Rust'],\n        ['title' =\u003e 'React'],\n    ],\n];\n$instance = $container-\u003ehydrate(Candidate::class, $data);\n\n//Results output\n/*\nprint_r($instance);\nThis test printed output: \nCandidate Object\n(\n    [name] =\u003e John Doe\n    [age] =\u003e 25\n    [skills] =\u003e Array\n        (\n            [0] =\u003e Skill Object\n                (\n                    [title] =\u003e PHP\n                )\n\n            [1] =\u003e Skill Object\n                (\n                    [title] =\u003e Java\n                )\n\n            [2] =\u003e Skill Object\n                (\n                    [title] =\u003e Rust\n                )\n\n            [3] =\u003e Skill Object\n                (\n                    [title] =\u003e React\n                )\n\n        )\n\n)\n */\n\n// Hydration example 2:\n$data = [\n    [\n        'name' =\u003e 'Foo',\n        //...\n    ],\n    [\n        'name' =\u003e 'Bar',\n        //...\n    ]\n];\n$instances = $container-\u003ehydrate(Candidate::class, $data);\n//Results output\n/*\nprint_r($instances);\nThis test printed output: \nArray\n(\n    [0] =\u003e Candidate Object\n        (\n            [name] =\u003e Foo\n            //...\n        )\n\n    [1] =\u003e Candidate Object\n        (\n            [name] =\u003e Bar\n            //...\n        )\n)\n */\n```\n\n## Contributing\n\nContributions are welcome! If you find any issues or have suggestions for improvements,\nplease open an issue or a pull request on GitHub.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebdevcave%2Fyadic-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebdevcave%2Fyadic-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebdevcave%2Fyadic-php/lists"}