定制 minond/configurare 二次开发

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

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

minond/configurare

Composer 安装命令:

composer require minond/configurare

包简介

Configuration management

README 文档

README

Build Status Coverage Status Latest Stable Version Dependencies Status Scrutinizer Quality Score SensioLabsInsight

Sample usage

Initializing configuration

use Efficio\Configurare\Configuration;

$conf = new Configuration;
$conf->setDirectory('./config/');
# config/app.yml
name: 'My Application'
usa:
  utah:
    provo:
      author: 'Marcos Minond'

Configuring configuratio file formats and parsers

// available parsers
use Efficio\Configurare\Parser\Json;

$conf->setExtension('.json'); // default is '.yml'
$conf->setParser(new Json); // default is Efficio\Configurare\Parser\Yaml

Using custom formats

use Efficio\Configurare\Parser\Parser;

class CustomParser implements Parser
{
    /**
     * takes a raw string, parses it, and returns the array representing the
     * data
     * @param string $raw
     * @return array
     */
    public function decode($raw)
    {
        return unserialize($raw);
    }

    /**
     * takes an array or an object and converts it into a string that can be
     * saved in a file
     * @param mixed $obj
     * @return string
     */
    public function encode($obj)
    {
        return serialize($obj);
    }
}

$conf->setExtension('.custom');
$conf->setParser(new CustomParser);

Getting values

// looks for in ./config/app.yml
// this gets [ 'name': ]
echo $conf->get('app:name'); // => My Application

// this gets [ 'usa': 'utah': 'provo': 'author': ]
echo $conf->get('app:usa:utah:provo:author'); // => Marcos Minond

// you can also get nested configuration files
// looks in config/users/2014/jan.yml
echo $conf->get('users/2014/jan:activities:music');

Setting values

// if a key(s) already exists, just set it
$conf->set('app:name', 'My Other Application');

// if they do not then the write must be forced by passing a third parameter
// set to true
$conf->set('app:does:not:exists:yet', 'yes', true);
# config/app.yml
name: 'My Other Application'
usa:
  utah:
    provo:
      author: 'Marcos Minond'
does:
  not:
    exists:
      yet: 'yes'

Enviroments

Adding enviroments allows additional configuration files, which may or may not be tracked by version control, to be used. For example, you may commit a "default" config/app.yml configuration file which makes assumptions about the enviroments (ie. database connection information) and overwrite it using config/app.prod.yml. This "prod" file has data which is sensative and is only stored in the production server where your application is running. This allows you to use the same configuration retrieval code, get the correct configuration for your enviroments, AND not have to check that into source control.

// I can have one enviroment or multiple
$conf->setEnvironments([ 'dev', 'test' ]);

// the following files will be parsed and merged before the configuration
// value is sent back
// - config/database.yaml
// - config/database.dev.yaml
// - config/database.test.yaml
$conf->get('database:connection:username');

Caching

Configurare is compatible with the Cache package

use Efficio\Cache\NullCache;
$conf->setCache(new NullCache);

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPL-2.0
  • 更新时间: 2013-07-27

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固