snapshotpl/zf-snap-var-config
最新稳定版本:4.1.0
Composer 安装命令:
composer require snapshotpl/zf-snap-var-config
包简介
Variables in array
README 文档
README
Variables in array.
Additional provides module for Laminas for configurations.
Usage
Sometimes you want to use same values in other places in your config. What are you doing?
<?php $myIp = '127.0.0.1'; return [ 'db' => $myIp, 'memcache' => $myIp, ];
Of course it's working, but when you want to share $myIp between separate config files thats challange! ZfSnapVarConfig make a magic here!
$data = [ 'ips' => [ 'local' => '127.0.0.1', 'memcache' => '127.0.0.2', 'smtp' => '127.0.0.3' ], 'email' => new ZfSnapVarConfig\Value\Env('ADMIN_EMAIL'), 'db' => ZfSnapVarConfig\Value\Path::fromString('ips/local'), 'memcache' => ZfSnapVarConfig\Value\Path::fromString('ips|memcache', '|'), 'email' => [ 'smtp' => ZfSnapVarConfig\Value\Path::fromArray(['ips', 'smtp']), 'default-mail' => ZfSnapVarConfig\Value\Path::fromString('email'), 'reply-to' => ZfSnapVarConfig\Value\Path::fromString('email'), 'other-address' => new ZfSnapVarConfig\Value\Path('ips', 'smtp'), ], ]; $service = new ZfSnapVarConfig\VarConfigService(); $replaced = $service->replace($data); // or $service($data); assertSame([ 'ips' => [ 'local' => '127.0.0.1', 'memcache' => '127.0.0.2', 'smtp' => '127.0.0.3' ], 'email' => 'your@email.com', 'db' => '127.0.0.1', 'memcache' => '127.0.0.2', 'email' => [ 'smtp' => '127.0.0.3', 'default-mail' => 'your@email.com', 'reply-to' => 'your@email.com', 'other-address' => '127.0.0.3', ], ], $replaced);
On this moment you can use selectors:
ZfSnapVarConfig\Value\PathZfSnapVarConfig\Value\EnvZfSnapVarConfig\Value\Callback
You can write your own value manipulator. Just implement ZfSnapVarConfig\Value and create instance in your config.
How to install?
Via composer.json
composer require snapshotpl/zf-snap-var-config
If you want to use this library as Laminas module add ZfSnapVarConfig to your application.config.php file.
统计信息
- 总下载量: 80.48k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2014-12-22