brightnucleus/config-52

最小化、可重用的 Config 组件(无命名空间)

v0.1.0 2016-03-31 10:29 UTC

This package is auto-updated.

Last update: 2024-09-16 05:14:23 UTC


README

不使用命名空间的 Config 组件,适用于 PHP 5.2 项目。

Latest Stable Version Total Downloads Latest Unstable Version License

目录

简介

Bright Nucleus Config 5.2 是一个类似于 brightnucleus/config 的 Config 组件,但它不使用 PHP 命名空间,因此可以在需要运行 PHP 5.2 的项目中使用。

由于其使用 Composer,因此在开发过程中需要 PHP 5.3.2+。然而,会生成一个 PHP 5.2 的自动加载器文件,因此您只需要 PHP 5.2+ 在运行时。

尽管这是一个非常简化的 Config 组件形式,但它旨在为 PHP 5.2 库提供一种非常基础的读取现有配置文件的方式。没有默认值、没有验证、没有花哨的便利函数。

安装

要将库包含到您的项目中,您可以使用 Composer

composer require brightnucleus/config-52

或者,您可以复制应用程序内部的类,并确保您的应用程序可以找到它们。

基本用法

要在您的项目中使用此组件,您应该首先加载 5.2 自动加载器

require dirname(__FILE__) . '/vendor/autoload_52.php';

以下是一个示例,说明如何加载后使用该类

<?php

use BrightNucleus_ConfigInterface as ConfigInterface;
use BrightNucleus_Config          as Config;

class WorldGreeter {

    /** @var  @var ConfigInterface */
    protected $config;

    public function __construct(ConfigInterface $config) {
        $this->config = $config;
    }

    public function greet() {
        $hello = $this->config->getKey('hello');
        $world = $this->config->getKey('world');
        echo "$hello $world";
    }
}

$config_file = dirname(__FILE__) . '/config/greetings.php';
$config      = new Config(include($config_file));

$worldGreeter = new WorldGreeter($config);
$worldGreeter->greet();

贡献

欢迎所有反馈/错误报告/拉取请求。

许可证

此代码在 MIT 许可证下发布。有关完整的版权和许可证信息,请查看与此源代码一起分发的 LICENSE 文件。