Code Monkey home page Code Monkey logo

phalcon-config-loader's Introduction

ConfigLoader Build Status Dependency Status

ConfigLoader - it's manager configuration files for Phalcon. It allows you to create a configuration of various formats (ini, yaml, JSON, or any other, for which you will add adapter) via a single method.

$configYml = $configLoader->create('config.yml');
$configIni = $configLoader->create('config.ini');

// or use string
$string = 'foo = bar'
$configFromText = $configLoader->fromText($string, 'ini');

ConfigLoader is able to track %environment% in configuration files and replace it on our environment.

// Create ConfigLoader and specify the environment of our application
$configLoader = new ConfigLoader('prod');

// config.yml : test: %environment%
$configYml = $configLoader->create('config.yml');

echo $configYml->test;
// print: prod 

To add your adapter, you must call add () with transfer expansion and adapter class, which must inherit a class Phalcon\Config:

$config = $configLoader->add('xml', 'MyNamespace/XmlConfig');

Moreover, you can merge configuration files:

#config.ini
[test]
test = true
%res% = import.ini
exp = %res:import.ini
%class% = Test/Class::SERVICES
import-class =  %class:Test/Class::SERVICES
#import.ini
import = "test"
namespace Test;

class Class {
  const SERVICES = '/const.ini';
}
#const.ini
class = "class"

The result loading configuration from config.ini:

[                               
    'test' => [                 
        'test' => true,                             
        'import' => true,       
        'env' => 'dev',
        'exp' => [
            'import' => true,
            'env' => 'dev'
        ],
        'class' => "class",
        'impot-class' => [
            'class' => "class"
        ]
    ]                           
]                               

Declared variables in the parent file will not be replaced by variables from the child (only %res% or %class%):

# /app/config/config.ini
%res% = include.ini
[foo]
test = config-test
# /app/config/include.ini
[foo]
test = test
bar = bar
# result
[foo]
test = config-test
bar = bar

If you do not want to import resources (loading of the other configuration files in this configuration), the second parameter must pass a boolean false :

$config = $configLoader->create('config.ini', false);

phalcon-config-loader's People

Contributors

jimmdigrizli avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.