donsimon/alt-brite-config 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

donsimon/alt-brite-config

Composer 安装命令:

composer require donsimon/alt-brite-config

包简介

A simple PHP INI (or plain array) configuration class with dot-notation access

README 文档

README

A simple PHP INI (or plain array) configuration class with dot-notation access

  • Parses both INI files and PHP arrays
  • Deals allows for configuration inheritance
  • Available via Composer / Packagist

Usage

You need a configuration file. Example .ini contents:

[default]

database.host = bar
database.user = foo
database.pass = baz

service.api_key = 123456

email = test@dev.com

[staging:default]

database.user = foo2
database.pass = baz2

[production:staging]

database.user = foo1
database.pass = baz1
email = test@production.com

Or alternatively, if you prefer plain PHP arrays:

<?php

$config['default']['database']['host'] = 'bar';
$config['default']['database']['user'] = 'foo';
$config['default']['database']['pass'] = 'baz';

$config['default']['service']['api_key'] = '123456';
$config['default']['email'] = 'test@dev.com';

$config['production']['extends'] = 'staging';
$config['production']['database']['user'] = 'foo1';
$config['production']['database']['pass'] = 'baz1';
$config['production']['email'] = 'test@production.com';

$config['staging']['extends'] = 'default';
$config['staging']['database']['user'] = 'foo2';
$config['staging']['database']['pass'] = 'baz2';

If you want to use the 'registry', register your configuration file during bootstrap:

<?php

use Brite\Config\Config;

// Registering as the 'default' config means you can grab the config
// without specifying a name.
Config::register('default', __DIR__ . '/test_config/config.php', 'staging');

Then access your configuration when required:

<?php

use Brite\Config\Config;

// This grabs the config registered as 'default'
$config = Config::instance();

echo $config->get('database.host');
// output: "bar"
echo $config->get('database.user');
// output: "foo1"

Alternatively, if you have multiple configuration files, you may name your configuration something other than 'default' during bootstrap, and access it via:

<?php

use Brite\Config\Config;

// This grabs the config registered as 'database'
$dbConfig = Config::instance('database');

echo $dbConfig->get('host');
echo $dbConfig->get('user');

However, we all know that global access is bad, right? You can create your own instance to contain your configuration, rather than using a global static registry:

<?php

use Brite\Config\IniConfig;

$config = new IniConfig('/path/to/file.ini', 'staging');

// Now register $config with your registry

... and that's it. Simple!

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-06-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固