{"id":26355723,"url":"https://github.com/zelenin/zend-expressive-config","last_synced_at":"2025-03-16T13:17:36.892Z","repository":{"id":57089778,"uuid":"52221955","full_name":"zelenin/zend-expressive-config","owner":"zelenin","description":"Zend Expressive config manager","archived":false,"fork":false,"pushed_at":"2017-08-29T13:01:06.000Z","size":37,"stargazers_count":7,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-14T00:03:49.363Z","etag":null,"topics":["annotations","config","expressive","manager","yaml","zend"],"latest_commit_sha":null,"homepage":null,"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/zelenin.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}},"created_at":"2016-02-21T18:48:39.000Z","updated_at":"2021-12-10T17:31:56.000Z","dependencies_parsed_at":"2022-08-20T15:30:27.546Z","dependency_job_id":null,"html_url":"https://github.com/zelenin/zend-expressive-config","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zelenin%2Fzend-expressive-config","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zelenin%2Fzend-expressive-config/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zelenin%2Fzend-expressive-config/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zelenin%2Fzend-expressive-config/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zelenin","download_url":"https://codeload.github.com/zelenin/zend-expressive-config/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243606959,"owners_count":20318314,"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":["annotations","config","expressive","manager","yaml","zend"],"created_at":"2025-03-16T13:17:36.423Z","updated_at":"2025-03-16T13:17:36.886Z","avatar_url":"https://github.com/zelenin.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Zend Expressive config manager [![Build Status](https://travis-ci.org/zelenin/zend-expressive-config.svg?branch=master)](https://travis-ci.org/zelenin/zend-expressive-config) [![Coverage Status](https://coveralls.io/repos/github/zelenin/zend-expressive-config/badge.svg?branch=master)](https://coveralls.io/github/zelenin/zend-expressive-config?branch=master)\n\n## Installation\n\n### Composer\n\nThe preferred way to install this extension is through [Composer](http://getcomposer.org/).\n\nEither run\n\n```\nphp composer.phar require zelenin/zend-expressive-config \"~2.1.0\"\n```\n\nor add\n\n```\n\"zelenin/zend-expressive-config\": \"~2.1.0\"\n```\n\nto the require section of your ```composer.json```\n\n## Usage\n\n### Config providers\n\n- PHP\n- Yaml\n- Arrays\n- Collections\n- Module config objects\n\n### Example\n\n```php\n\u003c?php\n\nuse Zelenin\\FooModule\\Config\\FooModuleConfig;\nuse Zelenin\\Zend\\Expressive\\Config\\ConfigManager;\nuse Zelenin\\Zend\\Expressive\\Config\\Provider\\ArrayProvider;\nuse Zelenin\\Zend\\Expressive\\Config\\Provider\\CacheProvider;\nuse Zelenin\\Zend\\Expressive\\Config\\Provider\\PhpProvider;\nuse Zelenin\\Zend\\Expressive\\Config\\Provider\\YamlProvider;\nuse Zelenin\\Zend\\Expressive\\Config\\Provider\\AnnotationProvider;\n\n$productionMode = true; // environment variable\n\n$providers =  [\n    new PhpProvider(__DIR__ . '/../config/autoload/*.global.php'),\n    new PhpProvider(__DIR__ . '/../config/autoload/*.local.php'),\n    new YamlProvider(__DIR__ . '/../config/autoload/*.global.yml'),\n    new YamlProvider(__DIR__ . '/../config/autoload/*.local.yml'),\n    new AnnotationProvider(__DIR__ . '/../src', __DIR__ . '/../data/cache/factories'),\n    new ArrayProvider(['foo' =\u003e 'bar']),\n    new FooModuleConfig(),\n];\n\nif ($productionMode) {\n    $providers = [new CacheProvider(__DIR__ . '/../data/cache/app-config.php', $providers)];\n}\n\n$manager = new ConfigManager($providers);\n$config = $manager-\u003egetConfig();\n```\n\nModule config example:\n\n```php\nnamespace Zelenin\\FooModule\\Config;\n\nuse Zelenin\\Zend\\Expressive\\Config\\Provider\\ModuleConfigProvider;\nuse Zelenin\\Zend\\Expressive\\Config\\Provider\\CollectionProvider;\nuse Zelenin\\Zend\\Expressive\\Config\\Provider\\PhpProvider;\nuse Zelenin\\Zend\\Expressive\\Config\\Provider\\YamlProvider;\n\nfinal class FooModuleConfig extends ModuleConfigProvider\n{\n    /**\n     * @return array\n     */\n    public function getConfig()\n    {\n        return [\n            'foo' =\u003e 'bar'\n        ];\n\n        // or\n\n        return require_once 'fooModuleConfig.php';\n\n        // or\n\n        return (new CollectionProvider([\n            new PhpProvider(__DIR__ . '/../Resources/config/*.global.php')),\n            new PhpProvider(__DIR__ . '/../Resources/config/*.local.php')),\n            new YamlProvider(__DIR__ . '/../Resources/config/*.global.yml'))\n            new YamlProvider(__DIR__ . '/../Resources/config/*.local.yml'))\n        ]))-\u003egetConfig();\n    }\n}\n```\n\n### Variables in YAML\n\nYou can resolve a variables like in the example below.\n\nConfig:\n```yml\ndependencies:\n    factories:\n        Zend\\Stratigility\\FinalHandler: 'Zend\\Expressive\\Container\\TemplatedErrorHandlerFactory'\n        Zend\\Expressive\\Template\\TemplateRendererInterface: 'Zend\\Expressive\\Twig\\TwigRendererFactory'\n\ntwig:\n    cache_dir: '%rootDir%/data/cache/twig'\n    assets_url: '/'\n    assets_version: 1\n    globals: []\n    extensions: []\n\ntemplates:\n    extension: 'html.twig'\n    paths:\n        application:\n            - '%moduleRootDir%/Resources/views'\n```\nProvider:\n```php\n\u003c?php\ndeclare(strict_types=1);\n\nnamespace Zelenin\\Application\\Config;\n\nuse ArrayObject;\nuse Zelenin\\Zend\\Expressive\\Config\\Provider\\CollectionProvider;\nuse Zelenin\\Zend\\Expressive\\Config\\Provider\\ModuleConfigProvider;\nuse Zelenin\\Zend\\Expressive\\Config\\Provider\\YamlProvider;\n\nfinal class Provider extends ModuleConfigProvider\n{\n    /**\n     * @return array\n     */\n    public function getConfig(): array\n    {\n        return $this-\u003eresolveVariables(\n            (new CollectionProvider([\n                new YamlProvider(__DIR__ . '/../Resources/config/*.global.yml'),\n                new YamlProvider(__DIR__ . '/../Resources/config/*.local.yml'),\n            ]))-\u003egetConfig()\n        );\n    }\n\n    /**\n     * @param array $config\n     *\n     * @return array\n     */\n    private function resolveVariables(array $config): array\n    {\n        $variableRegistry = $this-\u003egetVariablesRegistry();\n\n        array_walk_recursive($config, function (\u0026$value, $key) use ($variableRegistry) {\n            if (is_string($value)) {\n                if (preg_match('/%(.+)%/', $value, $matches)) {\n                    $variable = $matches[1];\n                    if (isset($variableRegistry[$variable])) {\n                        $value = preg_replace('/%(.+)%/', $variableRegistry[$variable], $value);\n                    }\n                }\n            }\n        });\n\n        return $config;\n    }\n\n    /**\n     * @return array\n     */\n    private function getVariablesRegistry(): array\n    {\n        return [\n            'rootDir' =\u003e realpath(__DIR__ . '/../../..'),\n            'moduleRootDir' =\u003e realpath(__DIR__ . '/..'),\n        ];\n    }\n}\n```\n\n### Annotations\n\nSupported annotations:\n\n- ```@Factory(id=Service::class)```\n- ```@Invokable(id=InvokableService::class)```\n- ```@Inject```\n- ```@Middleware(path=\"/path\")```\n- ```@Route(path=\"/path\", methods={\"GET\", \"POST\"}, name=\"route-name\")```\n\nNB: ```@Middleware``` and ```@Route``` works only with [```programmatic_pipeline=false```](https://docs.zendframework.com/zend-expressive/features/container/factories/)\n\nUsage: see examples in [Tests](https://github.com/zelenin/zend-expressive-config/tree/master/tests/Resources)\n\n\n## Author\n\n[Aleksandr Zelenin](https://github.com/zelenin/), e-mail: [aleksandr@zelenin.me](mailto:aleksandr@zelenin.me)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzelenin%2Fzend-expressive-config","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzelenin%2Fzend-expressive-config","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzelenin%2Fzend-expressive-config/lists"}