A Configuration Loader for PHP Packages
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
ExampleConfigurationFiles
TestConfigurationFiles
docs
src/Configurator
tests
.gitattributes
.gitignore
.styleci.yml
.travis.yml
LICENSE
README.md
changelog.txt
composer.json
phpunit.xml

README.md

Configurator

A Configuration Loader for PHP Packages

Build Status Latest Stable Version License Coverage Status StyleCI Total Downloads Latest Unstable Version

This package is a standalone library to allow you to have easy setup and access to configuration variables in your own php packages.

Supports

PHP

  • 5.6
  • 7.0
  • HHVM

Install

composer require eig/configurator

Usage

Include the Configurator class in your application:

use eig\Configurator\Configurator as Config;

Create a variable for the configurator object and an array of the configuration files to load (per the file variable documentation): (these are recommended to be class level variables)

    $config;
    $files = [
        [
            'source' => 'ArrayConfigurationExample.php',
            'path' => '/ExampleConfigurationFiles/',
            'pathType' => 'relative', // This option can be 'relative' or 'absolute'
            'type' => 'array',   // This can be 'array, json, yaml, or dir'. To add other types see documentation on adding 
            'alias' => 'example-array' // custom ConfigurationFileLoaders
        ],
        [
            'source' => 'ArrayConfigurationExample.json',
            'path' => '/ExampleConfigurationFiles/',
            'pathType' => 'relative',
            'type' => 'json',
            'alias' => 'example-json'
        ]
        [
            'source' => 'ArrayConfigurationExample.yaml',
            'path' => '/ExampleConfigurationFiles/',
            'pathType' => 'relative',
            'type' => 'yaml',
            'alias' => 'example-yaml'
        ]
        [
            'source' => '',  // With dir types this option should be empty
            'path' => '/ExampleConfigurationFiles/Subdir',
            'pathType' => 'relative',
            'type' => 'dir',
            'alias' => 'example-dir',
            'fileTypes' => ['array', 'json', 'yaml'] // This option is unique to 'dir' types and limits what type of 
                                                     // configuration files to load from the dir.
        ]
     ];

Instantiate a new Configurator Object with your array of configuration files to load:

$this->config = new Config($this->files);

Now you can reference your configuration variable loaded from the files supplied with array notation on the config object:

$this->config['app']['name'];

Facade

To use the library through a Facade use eig\Configurator\Facades\Configurator Then in your code you can load and access your configuration values like so:


/**
* This mehtod is required first to access any configuration values
* Failing to load first will return a null to any calls to items() or get()
*/

Configurator::load($files, $options = null);

/**
* This method will return all items that are loaded as an array.
*/
Configurator::items(); 

/**
* This method will return the item you specify just like using the array notation on a
* regular Configurator instance
*/
Configurator::get($fileKey, $valueKey);

Contributing

To contribute to this project clone the github repository create a new branch with the feature you are creating or bug you are fixing. Write tests to prove your feature or bugfix works then submit a pull request on github.

Roadmap

Roadmap