Giter VIP home page Giter VIP logo

config-2's Introduction

Config

Build Status Latest Stable Version Total Downloads License

PHP configurations loading library. It is made to enable your application to have different configurations depending on the environment it is running in. For example, your application can have different configurations for unit tests, development, staging and production. A good practice would be to not include your production or staging configurations in your version control. To do this, simply add a .gitignore file to your configs/environment directory with the following lines:

*
!.gitignore

Requirements

This library uses PHP 5.4+.

Installation

It is recommended that you install the Config library through composer. To do so, add the following lines to your composer.json file.

{
    "require": {
       "sinergi/config": "dev-master"
    }
}

Usage

Setup the configurations directory:

use Sinergi\Config\Config;

$config = new Config(__DIR__ . "/configs");

Optionally, you can also setup the environment. Setting up the environment will merge normal configurations with configurations in the environment directory. For example, if you setup the environment to be prod, the configurations from the directory configs/prod/* will be loaded on top of the configurations from the directory configs/*. Consider the following example:

$config->setEnvironment('prod');

You can than use the configurations like this:

$config->get('app.timezone');

Getter

The configuration getter uses a simple syntax: file_name.array_key.

For example:

$config->get('app.timezone');

You can optionally set a default value like this:

$config->get('app.timezone', "America/New_York");

You can use the getter to access multidimensional arrays in your configurations:

$config->get('database.connections.default.host');

Setter

Alternatively, you can set configurations from your application code:

$config->set('app.timezone', "Europe/Berlin");

You can set entire arrays of configurations:

$config->set('database', [
    'host' => "localhost",
    'dbname' => "my_database",
    'user' => "my_user",
    'password' => "my_password"
]);

Examples

See more examples in the examples folder.

Example of a configuration file:

return [
    'timezone' => "America/New_York"
];

config-2's People

Contributors

gabrielbull avatar nyholm avatar white-poto 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.