joebengalen/config

轻量级配置管理库。

1.0.0 2015-04-08 13:45 UTC

This package is not auto-updated.

Last update: 2024-09-14 15:27:14 UTC


README

Build Status Software License SensioLabsInsight

配置库可以用来存储配置选项,这些选项可以在应用中稍后使用。可以使用 setgethasremove 方法以及 \ArrayAccess 来控制配置选项。为了方便使用,支持点符号来访问嵌套数组。

源代码非常易于理解,并且在需要时可以扩展以支持更多功能。

安装

通过 Composer

$ composer require joebengalen/config

用法

<?php

require_once 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';

// Instantiate the config object.
$config = new \JoeBengalen\Config\Config();

// Load a php config file info the config object.
$config->load(__DIR__ . DIRECTORY_SEPARATOR . 'config.php');

// Set some more configurations.
$config->set([
    'database.host' => '127.0.0.1',
    'database.user' => 'root',
]);

// Show an array of all database configurations
var_dump($config->get('database'));

测试

使用 PHPUnit 进行测试。源代码覆盖率为100%。

存在一个包含phpunit默认设置的 phpunit.xml.dist 文件。

$ phpunit

注意:phpunit不包括在内。命令假设phpunit已全局安装。