{"id":20903500,"url":"https://github.com/phly/phly-configfactory","last_synced_at":"2025-08-04T16:41:25.532Z","repository":{"id":46085722,"uuid":"233848830","full_name":"phly/phly-configfactory","owner":"phly","description":"Factory for pulling nested configuration arrays from the config service","archived":false,"fork":false,"pushed_at":"2024-11-25T21:02:32.000Z","size":109,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"1.4.x","last_synced_at":"2025-04-20T01:34:48.763Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/phly.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"docs/CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":"docs/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":"docs/SUPPORT.md","governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-01-14T13:35:00.000Z","updated_at":"2023-02-06T20:02:54.000Z","dependencies_parsed_at":"2024-11-25T21:40:42.702Z","dependency_job_id":null,"html_url":"https://github.com/phly/phly-configfactory","commit_stats":{"total_commits":30,"total_committers":3,"mean_commits":10.0,"dds":0.4666666666666667,"last_synced_commit":"4aa670ded163fac95bd5104a72eb5a783dfa7a46"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phly%2Fphly-configfactory","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phly%2Fphly-configfactory/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phly%2Fphly-configfactory/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phly%2Fphly-configfactory/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phly","download_url":"https://codeload.github.com/phly/phly-configfactory/tar.gz/refs/heads/1.4.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253877265,"owners_count":21977632,"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":[],"created_at":"2024-11-18T13:13:43.292Z","updated_at":"2025-05-13T04:33:17.301Z","avatar_url":"https://github.com/phly.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# phly-configfactory\n\n[![Build Status](https://secure.travis-ci.org/phly/phly-configfactory.svg?branch=master)](https://secure.travis-ci.org/phly/phly-configfactory)\n[![Coverage Status](https://coveralls.io/repos/github/phly/phly-configfactory/badge.svg?branch=master)](https://coveralls.io/github/phly/phly-configfactory?branch=master)\n\nThis library provides a re-usable factory for pulling configuration from nested\nkeys.\n\n\u003e This library was previously released as [phly/phly-expressive-configfactory](https://github.com/phly/phly-expressive-configfactory).\n\u003e This version is a fork, modified to support [Laminas](https://getlaminas.org).\n\n## Installation\n\nRun the following to install this library:\n\n```bash\n$ composer require phly/phly-configfactory\n```\n\n## Usage\n\nAssign the factory `Phly\\ConfigFactory\\ConfigFactory` to services named with the\nfollowing structure:\n\n```text\nconfig-\u003cdot.separated.config.keys\u003e\n```\n\nAs an example, if you have the following structure:\n\n```php\nreturn [\n    'cache' =\u003e [\n        'adapters' =\u003e [\n            'blog' =\u003e [\n                'connection' =\u003e 'tcp://localhost:6349',\n                'username'   =\u003e 'www-data',\n                'prefix'     =\u003e 'blog',\n            ],\n        ],\n    ],\n];\n```\n\nand you wanted the \"blog\" adapter configuration, you would assign the dependency\nas follows:\n\n```php\nreturn [\n    'dependencies' =\u003e [\n        'factories' =\u003e [\n            'config-cache.adapters.blog' =\u003e \\Phly\\ConfigFactory\\ConfigFactory,\n        ],\n    ],\n];\n```\n\n### Return empty or raise exception\n\nBy default, if no configuration at the expected key is found, the factory\nreturns an empty array. If you want it to instead raise an exception, you can\nassign the factory as follows:\n\n```php\nreturn [\n    'dependencies' =\u003e [\n        'factories' =\u003e [\n            'config-cache.adapters.blog' =\u003e new \\Phly\\ConfigFactory\\ConfigFactory(false),\n        ],\n    ],\n];\n```\n\n\u003e This operation is safe, as `ConfigFactory` implements `__set_state()`,\n\u003e allowing it to be serialized safely with `var_export()`.\n\nThe exception will indicate the key hierarchy it was attempting to retrieve.\n\n### Using configuration in factories\n\nIn your factories, you will refer to the metaname when retrieving the service.\nFollowing our example above:\n\n```php\nuse Psr\\Container\\ContainerInterface;\n\nclass BlogCacheFactory\n{\n    public function __invoke(ContainerInterface $container)\n    {\n        return new Cache($container-\u003eget('config-cache.adapters.blog'));\n    }\n}\n```\n\n### Abstract Factory\n\nIf you are using [laminas-servicemanager](https://docs.laminas.dev/laminas-servicemanager),\nyou can use the class `Phly\\ConfigFactory\\ConfigAbstractFactory` as an abstract\nfactory. This allows you to omit adding a factory entry for every configuration\nsegment you want to retrieve. Instead, you can add the following:\n\n```php\nreturn [\n    'dependencies' =\u003e [\n        'abstract_factories' =\u003e [\n            \\Phly\\ConfigFactory\\ConfigAbstractFactory::class,\n\n            // OR\n\n            new \\Phly\\ConfigFactory\\ConfigAbstractFactory(false),\n        ],\n    ],\n];\n```\n\nWhen present, it will handle any services with the prefix `config-`, and operate\nin the same way as the `ConfigFactory`.\n\n### Caveats\n\nYou should only specify keys that will return an array. Most containers only\nallow returning an array or object from factories, and will raise an exception\notherwise. For those requiring an object, Mezzio generally casts to an\n`ArrayObject` instance, making this safe.\n\n## Support\n\n* [Issues](https://github.com/phly/phly-configfactory/issues/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphly%2Fphly-configfactory","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphly%2Fphly-configfactory","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphly%2Fphly-configfactory/lists"}