PHPackages                             yii1tech/config - 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. [Database &amp; ORM](/categories/database)
4. /
5. yii1tech/config

ActiveLibrary[Database &amp; ORM](/categories/database)

yii1tech/config
===============

Provides support for Yii1 application runtime configuration

1.0.1(2y ago)62.5k↓33.3%BSD-3-ClausePHPPHP &gt;=7.1

Since May 29Pushed 2y ago1 watchersCompare

[ Source](https://github.com/yii1tech/config)[ Packagist](https://packagist.org/packages/yii1tech/config)[ GitHub Sponsors](https://github.com/klimov-paul)[ Patreon](https://www.patreon.com/klimov_paul)[ RSS](/packages/yii1tech-config/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (3)Used By (0)

 [ ![](https://avatars.githubusercontent.com/u/134691944) ](https://github.com/yii1tech)

Application Runtime Configuration Extension for Yii 1
=====================================================

[](#application-runtime-configuration-extension-for-yii-1)

This extension introduces persistent configuration repository for Yii 1. Its usage in particular provides support for application runtime configuration, loading config from database.

For license information check the [LICENSE](LICENSE.md)-file.

[![Latest Stable Version](https://camo.githubusercontent.com/75c2de4c472ebb96b28a2b5ce516e1234030c63164e75cc1ba33f629b2a6704c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f79696931746563682f636f6e6669672e737667)](https://packagist.org/packages/yii1tech/config)[![Total Downloads](https://camo.githubusercontent.com/aae252418ef72e3fa24573733c407a7e22234e658600e908f51d5e1438443c10/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f79696931746563682f636f6e6669672e737667)](https://packagist.org/packages/yii1tech/config)[![Build Status](https://github.com/yii1tech/config/workflows/build/badge.svg)](https://github.com/yii1tech/config/actions)

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

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist yii1tech/config

```

or add

```
"yii1tech/config": "*"
```

to the "require" section of your composer.json.

Usage
-----

[](#usage)

This extension allows reconfiguring already created Yii application instance using config extracted from external storage like relational database. It allows to reconfigure any application property, component or module. Configuration is performed by `\yii1tech\config\Manager` component, which should be added to the application configuration. For example:

```
[
    'behaviors' => [
        'configFromManagerBehavior' => [
            'class' => yii1tech\config\ConfiguresAppFromConfigManager::class,
        ],
        // ...
    ],
    'components' => [
        'configManager' => [
            'class' => yii1tech\config\Manager::class,
            'items' => [
                'appName' => [
                    'path' => 'name',
                    'label' => 'Application Name',
                    'rules' => [
                        ['required'],
                    ],
                ],
                'dateFormat' => [
                    'path' => 'components.format.dateFormat',
                    'label' => 'HTML representing not set value',
                    'rules' => [
                        ['required'],
                    ],
                ],
            ],
        ],
        ...
    ],
];
```

In order to apply configuration defined via `\yii1tech\config\Manager` - `yii1tech\config\ConfiguresAppFromConfigManager` application behavior is used. It automatically updates the application configuration before request processing begins. You can apply config manually to the application or any `\CModule` descendant, using following code:

```
$configManager = Yii::app()->get('configManager');
$configManager->configure(Yii::app());
```

**Heads up!** Behavior `yii1tech\config\ConfiguresAppFromConfigManager` automatically suppresses any error or exception, which appears during values restoration. This is done to avoid application blocking in case storage is not yet ready for usage, for example: database table does not yet exist. Storage failure error will appear only at the application log. You should manually test value restoration is working at your application to avoid unexpected behavior.

Configuration items specification
----------------------------------

[](#configuration-items-specification-)

Application parts, which should be reconfigured are determined by `\yii1tech\config\Manager::$items`, which is a list of `\yii1tech\config\Item`. Each configuration item determines the configuration path - a list of keys in application configuration array, which leads to the target value. For example: path 'components.format.dateFormat' (or `['components', 'format', 'dateFormat']`) points to the property 'dateFormat' of `\CFormatter` component, path 'name' points to `\CApplication::$name` and so on.

> Note: if no path is specified it will be considered as a key inside `\CModule::$params` array, which matches configuration item id (name of key in `\yii1tech\config\Manager::$items` array).

Configuration item may also have several properties, which supports creation of web interface for configuration setup. These are:

- 'path' - array|string, application component config path.
- 'label' - string, input label.
- 'description' - string, configuration parameter description or input hint.
- 'rules' - array, value validation rules.
- 'cast' - string, native type for the value to be cast to.
- 'options' - array, additional descriptive options for this item.

> Tip: since runtime configuration may consist of many items and their declaration may cost a lot of code, it can be moved into a separated file and specified by this file name.

Here are some examples of item specifications:

```
