{"id":14966335,"url":"https://github.com/yiisoft/factory","last_synced_at":"2025-04-03T02:10:10.831Z","repository":{"id":34958911,"uuid":"191130945","full_name":"yiisoft/factory","owner":"yiisoft","description":"Object factory that is able to resolve dependencies from PSR-11 container","archived":false,"fork":false,"pushed_at":"2024-07-31T13:31:09.000Z","size":347,"stargazers_count":34,"open_issues_count":4,"forks_count":14,"subscribers_count":19,"default_branch":"master","last_synced_at":"2024-10-29T14:35:36.381Z","etag":null,"topics":["factory","hacktoberfest","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-10T08:48:15.000Z","updated_at":"2024-07-31T13:31:12.000Z","dependencies_parsed_at":"2023-02-19T16:00:42.181Z","dependency_job_id":"bc8d595e-c5d5-46ae-9ab5-d0d99f1ec836","html_url":"https://github.com/yiisoft/factory","commit_stats":{"total_commits":195,"total_committers":16,"mean_commits":12.1875,"dds":0.6307692307692307,"last_synced_commit":"561e73cc5a535eb9189f3a6560525cf5545dcb4a"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":"yiisoft/package-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Ffactory","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Ffactory/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Ffactory/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Ffactory/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yiisoft","download_url":"https://codeload.github.com/yiisoft/factory/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246748370,"owners_count":20827304,"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":["factory","hacktoberfest","yii3"],"created_at":"2024-09-24T13:36:14.322Z","updated_at":"2025-04-03T02:10:10.777Z","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 Factory\u003c/h1\u003e\n    \u003cbr\u003e\n\u003c/p\u003e\n\n[![Latest Stable Version](https://poser.pugx.org/yiisoft/factory/v)](https://packagist.org/packages/yiisoft/factory)\n[![Total Downloads](https://poser.pugx.org/yiisoft/factory/downloads)](https://packagist.org/packages/yiisoft/factory)\n[![Build status](https://github.com/yiisoft/factory/actions/workflows/build.yml/badge.svg)](https://github.com/yiisoft/factory/actions/workflows/build.yml)\n[![Code coverage](https://codecov.io/gh/yiisoft/factory/graph/badge.svg)](https://codecov.io/gh/yiisoft/factory)\n[![Mutation testing badge](https://img.shields.io/endpoint?style=flat\u0026url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyiisoft%2Ffactory%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/factory/master)\n[![static analysis](https://github.com/yiisoft/factory/workflows/static%20analysis/badge.svg)](https://github.com/yiisoft/factory/actions?query=workflow%3A%22static+analysis%22)\n[![type-coverage](https://shepherd.dev/github/yiisoft/factory/coverage.svg)](https://shepherd.dev/github/yiisoft/factory)\n\nThis package provides abstract object factory allowing to create objects by given definition\nwith dependencies resolved by a [PSR-11](https://www.php-fig.org/psr/psr-11/) container.\n\n## Requirements\n\n- PHP 8.0 or higher.\n\n## Installation\n\nThe package could be installed with [Composer](https://getcomposer.org):\n\n```shell\ncomposer require yiisoft/factory\n```\n\n## General usage\n\nThe factory is useful if you need to create objects using [definition syntax](https://github.com/yiisoft/definitions)\nand/or want to configure defaults for objects created.\n\n```php\n$container = new PSR11DependencyInjectionContainer();\n$factoryConfig = [\n    EngineInterface::class =\u003e [\n        'class' =\u003e EngineMarkOne::class,\n        '__construct()' =\u003e [\n            'power' =\u003e 42,\n        ],\n    ]\n];\n\n$factory = new Factory($container, $factoryConfig);\n\n$one = $factory-\u003ecreate(EngineInterface::class);\n$two = $factory-\u003ecreate([\n    'class' =\u003e EngineInterface::class,\n    '__construct()' =\u003e [\n        'power' =\u003e 146,\n    ],\n]);\n```\n\nIn the code above we define factory config specifying that when we need `EngineInterface`, an instance of `EngineMarkOne`\nwill be created with `power` constructor argument equals to 42. We also specify that all the dependencies requested by\nthe object created should be resolved by `PSR11DependencyInjectionContainer`.\n\nFirst call to `create()` uses default configuration of `EngineInterface` as is. Second call specifies custom\nconfiguration for `power` constructor argument. In this case, configuration specified is merged with default\nconfiguration overriding its keys when the key name is the same.\n\n### Tuning for production\n\nBy default, the factory validates definitions right when they are set. In production environment, it makes sense to\nturn it off by passing `false` as a third constructor argument:\n\n```php\n$factory = new Factory($container, $factoryConfig, false);\n```\n\n### Strict factory\n\n`StrictFactory` differs in that it processes only configured definitions.\nWhen attempting to request an existing class that is not defined in the factory config,\na `NotFoundException` will be thrown.\n\n```php\n$container = new PSR11DependencyInjectionContainer();\n$factoryConfig = [\n    EngineInterface::class =\u003e [\n        'class' =\u003e EngineMarkOne::class,\n        '__construct()' =\u003e [\n            'power' =\u003e 42,\n        ],\n    ]\n];\n\n$factory = new Factory($factoryConfig, $container);\n\n$engine = $factory-\u003ecreate(EngineInterface::class);\n\n// Throws `NotFoundException`\n$factory-\u003ecreate(EngineMarkOne::class);\n```\n\n## Documentation\n\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 Factory 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%2Ffactory","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyiisoft%2Ffactory","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyiisoft%2Ffactory/lists"}