{"id":15168767,"url":"https://github.com/yiisoft/composer-config-plugin","last_synced_at":"2025-10-01T02:31:00.629Z","repository":{"id":42431674,"uuid":"249150359","full_name":"yiisoft/composer-config-plugin","owner":"yiisoft","description":"Composer plugin for config assembling","archived":true,"fork":false,"pushed_at":"2022-07-06T05:06:01.000Z","size":505,"stargazers_count":31,"open_issues_count":19,"forks_count":15,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-04-15T03:05:33.886Z","etag":null,"topics":["composer-plugin","configuration-management","hacktoberfest"],"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},"funding":{"open_collective":"yiisoft","github":["yiisoft"]}},"created_at":"2020-03-22T09:25:47.000Z","updated_at":"2023-11-30T22:03:10.000Z","dependencies_parsed_at":"2022-09-22T14:40:52.441Z","dependency_job_id":null,"html_url":"https://github.com/yiisoft/composer-config-plugin","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Fcomposer-config-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Fcomposer-config-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Fcomposer-config-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Fcomposer-config-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yiisoft","download_url":"https://codeload.github.com/yiisoft/composer-config-plugin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219865487,"owners_count":16554152,"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":["composer-plugin","configuration-management","hacktoberfest"],"created_at":"2024-09-27T06:41:40.811Z","updated_at":"2025-10-01T02:31:00.245Z","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    \u003cimg src=\"logo.png\" height=\"126px\"\u003e\n    \u003ch1 align=\"center\"\u003eComposer Config Plugin\u003c/h1\u003e\n    \u003cbr\u003e\n\u003c/p\u003e\n\nComposer plugin for config assembling.\n\n\u003e ⚠️ The plugin is no longer supported in favor of [yiisoft/config](https://github.com/yiisoft/config).\n\n[![Latest Stable Version](https://poser.pugx.org/yiisoft/composer-config-plugin/v/stable)](https://packagist.org/packages/yiisoft/composer-config-plugin)\n[![Total Downloads](https://poser.pugx.org/yiisoft/composer-config-plugin/downloads)](https://packagist.org/packages/yiisoft/composer-config-plugin)\n[![Build status](https://github.com/yiisoft/composer-config-plugin/workflows/build/badge.svg)](https://github.com/yiisoft/composer-config-plugin/actions)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/yiisoft/composer-config-plugin/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/yiisoft/composer-config-plugin/?branch=master)\n[![Code Coverage](https://scrutinizer-ci.com/g/yiisoft/composer-config-plugin/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/yiisoft/composer-config-plugin/?branch=master)\n\nThis [Composer] plugin provides assembling\nof configurations distributed with composer packages.\nIt allows putting configuration needed to use a package right inside of\nthe package thus implementing a plugin system. The package becomes a plugin\nholding both the code and its configuration.\n\n### Documentation\n\n- [English](docs/en/README.md)\n- [Russian](docs/ru/README.md)\n\n## How it works?\n\n- Scans installed packages for `config-plugin` extra option in their\n  `composer.json`.\n- Loads `.env` files to set `$_ENV` variables.\n- Requires `constants` files to set constants.\n- Requires `params` files.\n- Requires config files.\n- Options collected during earlier steps could and should be used in later\n  steps, e.g. `$_ENV` should be used for constants and parameters, which\n  in turn should be used for configs.\n- File processing order is crucial to achieve expected behavior: options\n  in root package have priority over options from included packages. It is described\n  below in **File processing order** section.\n- Collected configs are written as PHP files in\n  `vendor/yiisoft/composer-config-plugin-output`\n  directory along with information needed to rebuild configs on demand.\n- Then assembled configs are ready to be loaded into application using `require`.\n\n**Read more** about the general idea behind this plugin in [English] or\n[Russian].\n\n[composer]: https://getcomposer.org/\n[English]:  https://hiqdev.com/pages/articles/app-organization\n[Russian]:  https://habrahabr.ru/post/329286/\n\n## Installation\n\n```sh\ncomposer require \"yiisoft/composer-config-plugin\"\n```\n\nOut of the box this plugin supports configs in PHP and JSON formats.\n\nTo enable additional formats require:\n\n- [vlucas/phpdotenv] - for `.env` files.\n- [symfony/yaml] - for YAML files, `.yml` and `.yaml`.\n\n[vlucas/phpdotenv]: https://github.com/vlucas/phpdotenv\n[symfony/yaml]: https://github.com/symfony/yaml\n\n## Usage\n\nList your config files in `composer.json` like the following:\n\n```json\n\"extra\": {\n    \"config-plugin-output-dir\": \"path/relative-to-composer-json\",\n    \"config-plugin\": {\n        \"envs\": \"db.env\",\n        \"params\": [\n            \"config/params.php\",\n            \"?config/params-local.php\"\n        ],\n        \"common\": \"config/common.php\",\n        \"web\": [\n            \"$common\",\n            \"config/web.php\"\n            \"../src/Modules/*/config/web.php\"\n        ],\n        \"other\": \"config/other.php\"\n    }\n},\n```\n\n### Markers \n\n- `?` - marks optional files. Absence of files not marked with it will cause exception.\n    ```\n    \"params\": [\n       \"params.php\",\n       \"?params-local.php\"\n    ]\n    ```\n  It's okay if `params-local.php` will not found, but it's not okay if `params.php` will be absent.\n  \n- `*` - marks wildcard path. It means zero or more matches by wildcard mask.\n  ```\n  \"web\": [\n     \"../src/Modules/*/config/web.php\"\n  ]\n  ```\n  It will collect all `web.php` in any subfolders of `src/Modules/` in `config` folder.\n\n- `$` - reference to another config.\n  ```\n  \"params\": [\n     \"params.php\",\n     \"?params-local.php\"\n  ],\n  \"params-console\": [\n     \"$params\",\n     \"params-console.php\"\n  ],\n  \"params-web\": [\n     \"$params\",\n     \"params-web.php\"\n  ]\n  ```\n  Output files `params-console.php` and `params-web.php` will contain `params.php` and `params-local.php`.\n\n***\n\nDefine your configs like the following:\n\n```php\n\u003c?php\n\nreturn [\n    'components' =\u003e [\n        'db' =\u003e [\n            'class' =\u003e \\my\\Db::class,\n            'name' =\u003e $params['db.name'],\n            'password' =\u003e $params['db.password'],\n        ],\n    ],\n];\n```\n\nA special variable `$params` is read from `params` config.\n\nTo load assembled configs in your application use `require`:\n\n```php\n$config = require Yiisoft\\Composer\\Config\\Builder::path('web');\n```\n\n### Using sub-configs\n\nIn some cases it is convenient to extract part of your config into another file. For example, we want to extract database\nconfiguration into `db.php`. To do it add the config to `composer.json`:\n\n```json\n\"extra\": {\n    \"config-plugin-output-dir\": \"path/relative-to-composer-json\",\n    \"config-plugin\": {\n        \"envs\": \"db.env\",\n        \"params\": [\n            \"config/params.php\",\n            \"?config/params-local.php\"\n        ],\n        \"common\": \"config/common.php\",\n        \"web\": [\n            \"$common\",\n            \"config/web.php\"\n        ],\n        \"other\": \"config/other.php\",\n        \"db\": \"config/db.php\"\n    }\n},\n```\n\nCreate `db.php`:\n\n```php\n\u003c?php\n\nreturn [\n    'class' =\u003e \\my\\Db::class,\n    'name' =\u003e $params['db.name'],\n    'password' =\u003e $params['db.password'],\n];\n```\n\nThen in the config use `Builder::require()`:\n\n```php\n\u003c?php\n\nuse Yiisoft\\Composer\\Config\\Builder;\n\nreturn [\n    'components' =\u003e [\n        'db' =\u003e Builder::require('db'),\n    ],\n];\n```\n\n### Refreshing config\n\nPlugin uses composer `POST_AUTOLOAD_DUMP` event i.e. composer runs this plugin on `install`, `update` and `dump-autoload`\ncommands. As the result configs are ready to be used right after package installation or update.\n\nWhen you make changes to any of configs you may want to reassemble configs manually. In order to do it run:\n\n```sh\ncomposer dump-autoload\n```\n\nAbove can be shortened to `composer du`.\n\nIf you need to force config rebuilding from your application, you can do it like the following:\n\n```php\n// Don't do it in production, assembling takes it's time\nif (getenv('APP_ENV') === 'dev') {\n    Yiisoft\\Composer\\Config\\Builder::rebuild();\n}\n```\n\n### File processing order\n\nConfig files are processed in proper order to achieve naturally expected\nbehavior:\n\n- Options in outer packages override options from inner packages.\n- Plugin respects the order your configs are listed in `composer.json` with.\n- Different types of options are processed in the following order:\n    - Environment variables from `envs`.\n    - Constants from `constants`.\n    - Parameters from `params`.\n    - Configs are processed last of all.\n\n### Debugging\n\nThere are several ways to debug config building internals.\n\n- Plugin can show detected package dependencies hierarchy by running:\n\n```sh\ncomposer dump-autoload --verbose\n```\n\nAbove can be shortened to `composer du -v`.\n\n- You can see the assembled configs in the output directory which is\n`vendor/yiisoft/composer-config-plugin-output` by default and can be configured\nwith `config-plugin-output-dir` extra option in `composer.json`.\n\n## Known issues\n\nThis plugin treats configs as simple PHP arrays. No specific\nstructure or semantics are expected and handled.\nIt is simple and straightforward, but I'm in doubt...\nWhat about errors and typos?\nI think about adding config validation rules provided together with\nplugins. Will it solve all the problems?\n\n## License\n\nThis project is released under the terms of the BSD-3-Clause [license](LICENSE).\nRead more [here](http://choosealicense.com/licenses/bsd-3-clause).\n\nCopyright © 2016-2020, HiQDev (http://hiqdev.com/)\nCopyright © 2020, Yiisoft (https://www.yiiframework.com/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyiisoft%2Fcomposer-config-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyiisoft%2Fcomposer-config-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyiisoft%2Fcomposer-config-plugin/lists"}