brightnucleus/config-52

Minimal, reusable Config component (without namespaces)

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

This package is auto-updated.

Last update: 2021-09-15 22:39:46 UTC


README

Config component that does not use namespaces, to be used in PHP 5.2 projects.

Latest Stable Version Total Downloads Latest Unstable Version License

Table Of Contents

Introduction

Bright Nucleus Config 5.2 is a Config component similar to brightnucleus/config, but it does not use PHP namespaces, so that it can be used in projects that need to work on PHP 5.2.

As it uses Composer, it will need PHP 5.3.2+ to use during development. However, there's a PHP 5.2 autoloader file that is generated, so that you only need PHP 5.2+ at runtime.

This is a very reduced form of a Config component, though, and is meant to provide a very basic way for PHP 5.2 libraries to read existing config files. There's no default values, no validation, no fancy convenience functions.

Installation

To include the library in your project, you can use Composer:

composer require brightnucleus/config-52

Alternatively, you can copy the classes inside of your application and make sure that your application can find them.

Basic Usage

To use the component within your project, you should first load the 5.2 autoloader:

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

Here's an example of how to use the class once it's been loaded:

<?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();

Contributing

All feedback / bug reports / pull requests are welcome.

License

This code is released under the MIT license. For the full copyright and license information, please view the LICENSE file distributed with this source code.