{"id":15023629,"url":"https://github.com/jimchenwyu/composer-config-plugin","last_synced_at":"2026-03-16T21:31:30.310Z","repository":{"id":56999034,"uuid":"191081167","full_name":"JimChenWYU/composer-config-plugin","owner":"JimChenWYU","description":"Composer plugin for config assembling. Fork from https://github.com/hiqdev/composer-config-plugin","archived":false,"fork":false,"pushed_at":"2019-06-11T05:47:28.000Z","size":214,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-19T18:43:48.865Z","etag":null,"topics":["assembling","composer","config","php55","plugin"],"latest_commit_sha":null,"homepage":null,"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/JimChenWYU.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2019-06-10T02:17:23.000Z","updated_at":"2019-08-10T08:47:54.000Z","dependencies_parsed_at":"2022-08-21T14:50:20.906Z","dependency_job_id":null,"html_url":"https://github.com/JimChenWYU/composer-config-plugin","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JimChenWYU%2Fcomposer-config-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JimChenWYU%2Fcomposer-config-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JimChenWYU%2Fcomposer-config-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JimChenWYU%2Fcomposer-config-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JimChenWYU","download_url":"https://codeload.github.com/JimChenWYU/composer-config-plugin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243324266,"owners_count":20273098,"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":["assembling","composer","config","php55","plugin"],"created_at":"2024-09-24T19:59:15.994Z","updated_at":"2025-12-28T01:17:32.451Z","avatar_url":"https://github.com/JimChenWYU.png","language":"PHP","funding_links":[],"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. Fork from https://github.com/hiqdev/composer-config-plugin\n\n[![Latest Stable Version](https://poser.pugx.org/jimchen/composer-config-plugin/v/stable)](https://packagist.org/packages/jimchen/composer-config-plugin)\n[![Build Status](https://img.shields.io/travis/JimChenWYU/composer-config-plugin.svg)](https://travis-ci.org/JimChenWYU/composer-config-plugin)\n[![Scrutinizer Code Coverage](https://img.shields.io/scrutinizer/coverage/g/JimChenWYU/composer-config-plugin.svg)](https://scrutinizer-ci.com/g/JimChenWYU/composer-config-plugin/)\n[![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/JimChenWYU/composer-config-plugin.svg)](https://scrutinizer-ci.com/g/JimChenWYU/composer-config-plugin/)\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\nHow 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 `defines` 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/hiqdev/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## Requirement\n\n+ PHP \u003e= 5.5\n+ Composer\n\n**Notice**: If your php version is larger than or equal to 7.0, please use [hiqdev/composer-config-plugin](https://github.com/hiqdev/composer-config-plugin) instead.\n\n## Installation\n\n```sh\ncomposer require \"jimchen/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\": {\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    }\n},\n```\n\n`?` marks optional files. Absence of files not marked with it will cause exception.\n\n`$common` is inclusion - `common` config will be merged into `web`.\n\nDefine your configs like the following:\n\n```php\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\nTo load assembled configs in your application use `require`:\n\n```php\n$config = require hiqdev\\composer\\config\\Builder::pathHasDefault('web', __DIR__ . '/../web.php');\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 rebuildign 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 (ENVIRONMENT === 'dev') {\n    hiqdev\\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 `dotenv`\n    - Constants from `defines`\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 list of configs and files that plugin has detected and uses\nto build configs. It is located in `vendor/hiqdev/composer-config-plugin/output/__files.php`.\n\n- You can see the assembled configs in\n`vendor/hiqdev/composer-config-plugin-output` directory.\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\nAnonymous functions must be used in multiline form only:\n\n```php\nreturn [\n    'works' =\u003e function () {\n        return 'value';\n    },\n    // this will not work\n    'noway' =\u003e function () { return 'value'; },\n];\n```\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-2018, Jim Chen\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjimchenwyu%2Fcomposer-config-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjimchenwyu%2Fcomposer-config-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjimchenwyu%2Fcomposer-config-plugin/lists"}