PHPackages                             hiqdev/composer-config-plugin - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. hiqdev/composer-config-plugin

Abandoned → [yiisoft/composer-config-plugin](/?search=yiisoft%2Fcomposer-config-plugin)Composer-plugin[Utility &amp; Helpers](/categories/utility)

hiqdev/composer-config-plugin
=============================

Composer plugin for config assembling

0.4.0(6y ago)9068.9k17[1 PRs](https://github.com/hiqdev/composer-config-plugin/pulls)20BSD-3-ClausePHPPHP &gt;=7.1CI failing

Since May 18Pushed 2mo ago12 watchersCompare

[ Source](https://github.com/hiqdev/composer-config-plugin)[ Packagist](https://packagist.org/packages/hiqdev/composer-config-plugin)[ Docs](https://github.com/hiqdev/composer-config-plugin)[ RSS](/packages/hiqdev-composer-config-plugin/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (20)Used By (20)

 [![](logo.png)](logo.png)

Composer Config Plugin
======================

[](#composer-config-plugin)

Composer plugin for config assembling.

> ⚠️ The plugin is no longer supported in favor of [yiisoft/config](https://github.com/yiisoft/config).

[![Latest Stable Version](https://camo.githubusercontent.com/9d914af420b8466765bdad924e88ac9502df199f78c96591d06001fe2ea0d526/68747470733a2f2f706f7365722e707567782e6f72672f796969736f66742f636f6d706f7365722d636f6e6669672d706c7567696e2f762f737461626c65)](https://packagist.org/packages/yiisoft/composer-config-plugin)[![Total Downloads](https://camo.githubusercontent.com/4c942fb03fba21d50ad87e55dc91fbe519af4cb60749c2824f2d415ea5408bf9/68747470733a2f2f706f7365722e707567782e6f72672f796969736f66742f636f6d706f7365722d636f6e6669672d706c7567696e2f646f776e6c6f616473)](https://packagist.org/packages/yiisoft/composer-config-plugin)[![Build status](https://github.com/yiisoft/composer-config-plugin/workflows/build/badge.svg)](https://github.com/yiisoft/composer-config-plugin/actions)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/80e6164280f49039cdb84f0b76676690e6ccc2ccac977950b30c6f9a7483a783/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f796969736f66742f636f6d706f7365722d636f6e6669672d706c7567696e2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/yiisoft/composer-config-plugin/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/c8293dfabcb6e0fb37437c5feff66c0f19dffb17d1007b8d426421755492495e/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f796969736f66742f636f6d706f7365722d636f6e6669672d706c7567696e2f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/yiisoft/composer-config-plugin/?branch=master)

This [Composer](https://getcomposer.org/) plugin provides assembling of configurations distributed with composer packages. It allows putting configuration needed to use a package right inside of the package thus implementing a plugin system. The package becomes a plugin holding both the code and its configuration.

### Documentation

[](#documentation)

- [English](docs/en/README.md)
- [Russian](docs/ru/README.md)

How it works?
-------------

[](#how-it-works)

- Scans installed packages for `config-plugin` extra option in their `composer.json`.
- Loads `.env` files to set `$_ENV` variables.
- Requires `constants` files to set constants.
- Requires `params` files.
- Requires config files.
- Options collected during earlier steps could and should be used in later steps, e.g. `$_ENV` should be used for constants and parameters, which in turn should be used for configs.
- File processing order is crucial to achieve expected behavior: options in root package have priority over options from included packages. It is described below in **File processing order** section.
- Collected configs are written as PHP files in `vendor/yiisoft/composer-config-plugin-output`directory along with information needed to rebuild configs on demand.
- Then assembled configs are ready to be loaded into application using `require`.

**Read more** about the general idea behind this plugin in [English](https://hiqdev.com/pages/articles/app-organization) or [Russian](https://habrahabr.ru/post/329286/).

Installation
------------

[](#installation)

```
composer require "yiisoft/composer-config-plugin"
```

Out of the box this plugin supports configs in PHP and JSON formats.

To enable additional formats require:

- [vlucas/phpdotenv](https://github.com/vlucas/phpdotenv) - for `.env` files.
- [symfony/yaml](https://github.com/symfony/yaml) - for YAML files, `.yml` and `.yaml`.

Usage
-----

[](#usage)

List your config files in `composer.json` like the following:

```
"extra": {
    "config-plugin-output-dir": "path/relative-to-composer-json",
    "config-plugin": {
        "envs": "db.env",
        "params": [
            "config/params.php",
            "?config/params-local.php"
        ],
        "common": "config/common.php",
        "web": [
            "$common",
            "config/web.php"
            "../src/Modules/*/config/web.php"
        ],
        "other": "config/other.php"
    }
},
```

### Markers

[](#markers)

- `?` - marks optional files. Absence of files not marked with it will cause exception.

    ```
    "params": [
       "params.php",
       "?params-local.php"
    ]

    ```

    It's okay if `params-local.php` will not found, but it's not okay if `params.php` will be absent.
- `*` - marks wildcard path. It means zero or more matches by wildcard mask.

    ```
    "web": [
       "../src/Modules/*/config/web.php"
    ]

    ```

    It will collect all `web.php` in any subfolders of `src/Modules/` in `config` folder.
- `$` - reference to another config.

    ```
    "params": [
       "params.php",
       "?params-local.php"
    ],
    "params-console": [
       "$params",
       "params-console.php"
    ],
    "params-web": [
       "$params",
       "params-web.php"
    ]

    ```

    Output files `params-console.php` and `params-web.php` will contain `params.php` and `params-local.php`.

---

Define your configs like the following:

```
