A PHP Generic Validator Service Object

1.1.4 2016-10-17 16:56 UTC


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.



  • 5.6
  • 7.0
  • HHVM


composer require eig/configurator


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)

    $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:



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.

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


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.