f3ath/pimple-config
Composer 安装命令:
composer require f3ath/pimple-config
包简介
Simple multi-environment configuration for Pimple with secret storage support
README 文档
README
Install
composer install f3ath/pimple-config
Configuration structure
Environment-specific config
A config is a file named <environment_name>.php which returns an array:
<?php // dev.php return [ 'debug' => true, 'foo' => [ 'bar' => 'baz' ] ];
To reduce duplication, here is some sort of "inheritance":
<?php // stage.php return array_replace_recursive(require __DIR__ . '/common.php', [ // inherit from common config 'debug' => false, ]);
Secret config
It is a healthy practice to store sensitive data like passwords outside of the repository. The simplest implementation
would be to store such files right on the server. These files may be edited directly, so they should not be php scripts,
since it's easy to accidentally remove the <?php header and expose their content. A natural choice in
this case is JSON. PimpleConfig supports a special secret_json key to include such files.
<?php // prod.php return array_replace_recursive(require __DIR__ . '/common.php', [ // inherit from common config 'secret_json' => '/etc/my_application/secret.json', 'debug' => false, ]);
Services
Pimple services are configured in the set of files in the services directory. In your configuration you define:
<?php // common.php return [ 'services' => [ 'application' => __DIR__ . '/services/application.php', 'storage' => __DIR__ . '/services/storage.php', 'controllers' => __DIR__ . '/services/controllers.php', ], ];
A service config is a php script which returns a special function:
<?php // services/application.php return function (\Pimple\Container $container, array $config, string $env) { $container['hello'] = function () use ($config, $env) { // here you create and return a service the Pimple way }; };
Register the configuration
<?php $pimple = new \Pimple\Container(); $env_name = 'prod'; $config_root = '/path-to-config'; $pimple->register(new \F3\PimpleConfig\Config($config_root, $env_name));
For more examples see the unit test.
Contribution
Please do!
f3ath/pimple-config 适用场景与选型建议
f3ath/pimple-config 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 63 次下载、GitHub Stars 达 2, 最近一次更新时间为 2017 年 03 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 f3ath/pimple-config 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 f3ath/pimple-config 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 63
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-03-07