承接 mizmoz/config 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

mizmoz/config

Composer 安装命令:

composer require mizmoz/config

包简介

Mizmoz Config

README 文档

README

Aims

  • Be lightweight
  • Configs are just php files which return arrays
  • Environment set using .environment file
  • Overridable by environment variables
  • Lazy load config files

Getting Started

Composer Installation

composer require mizmoz/config

Basic Usage

Set the environment

Create a file in the root of the project called .environment which should contain the current platform

To set as development:

echo 'development' > /my/project/root/.environment

Alternatively use system environment

export ENVIRONMENT=development

Load a configuration from an array
$config = new Config(['app' => ...]);
$config->get('app...');
Load configuration from a directory of configs
$config = Config::fromDirectory('./config', '.php');
$config->get('app...');
Load configuration from a directory whilst handling different environments
# In a config db.php
return [
    'type' => 'mongo',
    'hostname' => 'db.servers.com',
];

# In another config file for development db.development.php
return \Mizmoz\Config\Extend::production('db', [
    'host' => 'localhost',
]);

# Setup the config from directory
$config = Config::fromEnvironment(Environment::create(__DIR__));
$config->get('db.type'); // mongo
$config->get('db.hostname'); // localhost
Override the config values
# Using the envrionment override to ensure any values that come from the environment variables are treated as priority
# Assuming we do something like:
# export MM_DB_PORT=3333
$config = new Config([
    'db' => [
        'default' => 'mysql',
        'port' => 3306,
    ]
]);

$config->addOverride(new Env);

# Access the value of 3333
$config->get('db.port');
# The same can be done for cli arguments so:
# php my-script.php MM_DB_PORT=5555
$config = new Config([
    'db' => [
        'default' => 'mysql',
        'port' => 3306,
    ]
]);

$config->addOverride(new Args);

# Access the value of 5555
$config->get('db.port');
# These can be chained with last priority so using the above example:
# Returns 5555
$config->addOverride(new Env)
    ->addOverride(new Args)
    ->get('db.port');
Accessing the configs
$config = new Config([
    'db' => [
        'default' => 'mysql',
        'mysql' => 3306,
    ]
]);

# Basic accessing using dot notation
$config->get('db.default');

# Using the __invoke magic method
$config('db');

# Accessing with other config values referenced
$config->get('db.${db.default}');

# Accessing with relative references
$config->get('db.${.default}');

Roadmap

  • Add support for duplicating values such as website address which might be re-used for multiple params.
    • Need to figure out a way to do this without introducing any significant overhead when returning a config tree

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-08-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固