1. Go to this page and download the library: Download yiisoft/config library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
yiisoft / config example snippets
use Yiisoft\Config\Config;
use Yiisoft\Config\ConfigPaths;
$config = new Config(
new ConfigPaths(dirname(__DIR__)),
);
$web = $config->get('web');
use Yiisoft\Config\Config;
use Yiisoft\Config\ConfigPaths;
$config = new Config(
new ConfigPaths(dirname(__DIR__)),
);
if ($config->has('web')) {
$web = $config->get('web');
}
$config = new Config(
new ConfigPaths(__DIR__ . '/configs'),
null,
[],
'custom-params' // Group name for `$params`
);
'routes' => $config->get('routes');
use Yiisoft\Config\Config;
use Yiisoft\Config\ConfigPaths;
$config = new Config(
new ConfigPaths(dirname(__DIR__), 'path/to/config/directory'),
);
$web = $config->get('web');
use Yiisoft\Config\Config;
use Yiisoft\Config\ConfigPaths;
$config = new Config(
new ConfigPaths(dirname(__DIR__)),
'dev',
);
$app = $config->get('app');
use Yiisoft\Config\Config;
use Yiisoft\Config\ConfigPaths;
use Yiisoft\Config\Modifier\ReverseMerge;
$config = new Config(
new ConfigPaths(dirname(__DIR__)),
'dev',
[
ReverseMerge::groups('events', 'events-web', 'events-console'),
],
);
$events = $config->get('events-console'); // merged reversed
use Yiisoft\Config\Config;
use Yiisoft\Config\ConfigPaths;
use Yiisoft\Config\Modifier\RemoveFromVendor;
$config = new Config(
new ConfigPaths(dirname(__DIR__)),
'dev',
[
// Remove elements `key-for-remove` and `nested→key→for-remove` from all groups in all vendor packages
RemoveFromVendor::keys(
['key-for-remove'],
['nested', 'key', 'for-remove'],
),
// Remove elements `a` and `b` from all groups in package `yiisoft/auth`
RemoveFromVendor::keys(['a'], ['b'])
->package('yiisoft/auth'),
// Remove elements `c` and `d` from groups `params` and `web` in package `yiisoft/view`
RemoveFromVendor::keys(['c'], ['d'])
->package('yiisoft/view', 'params', 'web'),
// Remove elements `e` and `f` from all groups in package `yiisoft/auth`
// and from groups `params` and `web` in package `yiisoft/view`
RemoveFromVendor::keys(['e'], ['f'])
->package('yiisoft/auth')
->package('yiisoft/view', 'params', 'web'),
],
);
$params = $config->get('params');
use Yiisoft\Config\Config;
use Yiisoft\Config\ConfigPaths;
use Yiisoft\Config\Modifier\RemoveFromVendor;
$config = new Config(
new ConfigPaths(dirname(__DIR__)),
'dev',
[
RemoveFromVendor::groups([
// Remove group `params` from all vendor packages
'*' => 'params',
// Remove groups `common` and `web` from all vendor packages
'*' => ['common', 'web'],
// Remove all groups from package `yiisoft/auth`
'yiisoft/auth' => '*',
// Remove groups `params` from package `yiisoft/http`
'yiisoft/http' => 'params',
// Remove groups `params` and `common` from package `yiisoft/view`
'yiisoft/view' => ['params', 'common'],
]),
],
);
use Yiisoft\Config\Config;
use Yiisoft\Config\ConfigPaths;
use Yiisoft\Config\Modifier\RecursiveMerge;
use Yiisoft\Config\Modifier\RemoveFromVendor;
use Yiisoft\Config\Modifier\ReverseMerge;
$config = new Config(
new ConfigPaths(dirname(__DIR__)),
'dev',
[
RecursiveMerge::groups('params', 'events', 'events-web', 'events-console'),
ReverseMerge::groups('events', 'events-web', 'events-console'),
RemoveFromVendor::keys(
['key-for-remove'],
['nested', 'key', 'for-remove'],
),
],
);