定制 f3ath/pimple-config 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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!

统计信息

  • 总下载量: 63
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-03-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固