定制 mkomorowski/php-config 二次开发

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

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

mkomorowski/php-config

Composer 安装命令:

composer require mkomorowski/php-config

包简介

Simple class supporting different configuration values based on the environment

README 文档

README

Latest Stable Version Build Status Coverage Status

A simple class supporting different configuration values based on the environment

Installation

The package can be installed via Composer by adding to the composer.json require block.

{
    "require": {
        "mkomorowski/php-config": "1.0"
    }
}

Then update application packages by running the command:

php composer.phar update

Configuration

Examples of files with application configuration options.

local.php

return array(
        'debug' => true,
        'database' => array(
            'host' => '127.0.0.1',
            'password' => 'password',
        ),
);

production.php

return array(
        'debug' => false,
        'database' => array(
            'host' => 'rds.amazon.com',
            'password' => 'password',
        ),
);

In the settings loader we are specifying the path to the directory with config files.

$loader = new mKomorowski\Config\Loader('/app/config');

Next we are defining the environment settings:

$environment = new mKomorowski\Config\Environments(array(
    'local' => array('local', 'MacBook.local'),
    'stage' => array('cent_os_stage')
));

Finally we initialize the Config class, passing settings and environments. The third paramater is an optional default environment.

$config = new mKomorowski\Config\Config($loader, $environment, 'stage');

We can change the default environment later by:

$config->setDefaultEnvironment('production');

Usage

To retrieve the settings just use:

$config->get('debug');

Accessing nested values is possible with dotted notation

$config->get('database.hostname');

If your hosts is signed to a specific environment it will return the appropriate value. If not it will look for default environment settings or return null if the key is not set.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-09-28

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固