2017 © Pedro Peláez
 

library config

Simple Config library, that handle PHP arrays, YAML and INI files as configs and can dump all configs into one PHP file as Cache.

image

requtize/config

Simple Config library, that handle PHP arrays, YAML and INI files as configs and can dump all configs into one PHP file as Cache.

  • Thursday, March 1, 2018
  • by requtize
  • Repository
  • 1 Watchers
  • 3 Stars
  • 594 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 2 % Grown

The README.md

Config

This library provides configurational files system, that alows You to combine multiple files and multiple formats into one object and accessing to it from simple array DOT notation., (*1)

  1. Merging multiple files into one object
  2. Imports files in multiple formats in the same way: PHP, INI, YAML
  3. Import files from another files
  4. Simple dot notation for accessing arrays
  5. Cache system, for save parsed files into one

Installation

Via composer.json

{
    "require": {
        "requtize/config": "^1.2.0"
    }
}

Via Composer CLI

composer require requtize/config:^1.2.0

Dot notation

Dot notation is created for accessing multidimentional arrays (PHP) in simple way. If we want to access to some value, we need separate each index by dot. Following code should to explain that:, (*2)

$array = [
    'one' => [
        'two' => [
            'three' => 'value'
        ]
    ]
];

// PHP access
$array['one']['two']['three'];

// Dot notation access
$config->get('one.two.three');

Code

// Without cache system
$config = new Config();
// With cache system
$config = new Config('config-filepath.php');

// Import files - multiple formats in the same way
$config->import('filename.php');
$config->import('filename.ini');
$config->import('filename.yaml');
// Or import as array
$config->import([ 'filename.php', 'filename.ini', 'filename.yaml' ]);

// Get value - each index in multidimensional array separate by dot
// Default value will be returned if given key(s) will not be existed
$value = $config->get('some.deep.index.in-config.file', 'default value');

// Set value in current request live (and in cache).
$config->set('key', 'some value to save');

// Key exists?
$config->has('key') ? 'yes' : 'no';

// Get all data in configs (in all files)
$config->all();

Importing other files in config file

If you want to import other files, You musn't write any PHP to do this. Just use imports.files index in any file, and type files names in each index You want to import. Importing can be used for imports other formats in the same way. Remember that the files are searched relative to file you place importing rules!, (*3)

return [
    // Other data...
    'imports' => [
        'filepath.php',
        '../../global-config/main.ini',
        './some-yaml.file.yaml'
    ]
    // Other data...
];
# Other data...
imports:
    "filepath.php"
    "../../global-config/main.ini"
    "./some-yaml.file.yaml"
# Other data...
; Other data...
[imports]
0 = "filepath.php"
1 = "../../global-config/main.ini"
2 = "./some-yaml.file.yaml"
; Other data...

@todo

  • Prefixes for imported files to allow import files from different place: '%root%/config.file.php', '%server-config%/some.file.ini'
  • XML files support
  • You want some more...?

Licence

This code is licensed under MIT License., (*4)

The Versions

01/03 2018

dev-master

9999999-dev https://github.com/requtize/config

Simple Config library, that handle PHP arrays, YAML and INI files as configs and can dump all configs into one PHP file as Cache.

  Sources   Download

MIT

The Requires

 

settings php configuration config conf setting

01/03 2018

1.2.0

1.2.0.0 https://github.com/requtize/config

Simple Config library, that handle PHP arrays, YAML and INI files as configs and can dump all configs into one PHP file as Cache.

  Sources   Download

MIT

The Requires

 

settings php configuration config conf setting

07/10 2017

1.1.0

1.1.0.0 https://github.com/requtize/config

Simple Config library, that handle PHP arrays, YAML and INI files as configs and can dump all configs into one PHP file as Cache.

  Sources   Download

MIT

The Requires

 

settings php configuration config conf setting

19/10 2016

1.0.0

1.0.0.0 https://github.com/requtize/config

Simple Config library, that handle PHP arrays, YAML and INI files as configs and can dump all configs into one PHP file as Cache.

  Sources   Download

MIT

The Requires

 

settings php configuration config conf setting

26/04 2016

0.0.1

0.0.1.0 https://github.com/requtize/config

Simple Config library, that handle PHP arrays, YAML and INI files as configs and can dump all configs into one PHP file as Cache.

  Sources   Download

MIT

The Requires

 

settings php configuration config conf setting