GithubHelp home page GithubHelp logo

yaconf's Introduction

##Yaconf - Yet Another Configurations Container

A PHP Persistent Configurations Container

Requirement

  • PHP 7+

Introduction

Yaconf is a configurations container, it parses ini files, and store the result in PHP when PHP is started.

###Features

  • Fast, Light
  • Zero-copy while accesses configurations
  • Support sections, sections inheritance
  • Configurations reload after file is changed

Install

Compile Yaconf in Linux

$ /path/to/php7/phpize
$ ./configure --with-php-config=/path/to/php7/php-config/
$ make && make install

Runtime Configure

  • yaconf.directory // path to directory which all ini configuration files are putted
  • yaconf.check_delay // in which interval Yaconf will detects the file's change

APIs

mixed Yaconf::get(string $name, mixed $default = NULL)

bool Yaconf::has(string $name)

Example

Directory

Assuming we place all configurations files in /tmp/yaconf/, thus we added this into php.ini

yaconf.directory=/tmp/yaconf

INI Files

Assuming there are two files in /tmp/yaconf

foo.ini

name="yaconf"
year=2015
features[]="fast"
features.1="light"
features.plus="zero-copy"
features.constant=PHP_VERSION
features.env=${HOME}

and bar.ini

[base]
parent="yaconf"
children="NULL"

[children:base]
children="set"

Run

lets access the configurations

foo.ini
php7 -r 'var_dump(Yaconf::get("foo"));'
/*
array(3) {
  ["name"]=>
  string(6) "yaconf"
  ["year"]=>
  string(4) "2015"
  ["features"]=>
  array(5) {
    [0]=>
    string(4) "fast"
    [1]=>
    string(5) "light"
    ["plus"]=>
    string(9) "zero-copy"
    ["constant"]=>
    string(9) "7.0.0-dev"
	["env"] =>
	string(16) "/home/huixinchen"
  }
}
*/

As you can see, Yaconf supports string, map(array), ini, env variable and PHP constants.

you can also access configurations like this:

php7 -r 'var_dump(Yaconf::get("foo.name"));'
//string(6) "yaconf"

php7 -r 'var_dump(Yaconf::get("foo.features.1"));'
//string(5) "light"

php7 -r 'var_dump(Yaconf::get("foo.features")["plus"]);'
//string(9) "zero-copy"
bar.ini

Now lets see the sections and sections inheritance:

php7 -r 'var_dump(Yaconf::get("bar"));'
/*
array(2) {
  ["base"]=>
  array(2) {
    ["parent"]=>
    string(6) "yaconf"
    ["children"]=>
    string(4) "NULL"
  }
  ["children"]=>
  array(2) {
    ["parent"]=>
    string(6) "yaconf"
    ["children"]=>
    string(3) "set"
  }
}
*/

Children section has inherited values in base sections, and children is able to override the values they want.

yaconf's People

Contributors

laruence avatar leeeboo avatar

Watchers

James Cloos avatar  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.