2017 © Pedro Peláez
 

library yafconf

image

lovelock/yafconf

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

A config wrapper for Yaf

Notice This is designed for Yaf, if you're using other framework, leave it., (*1)

Feautures

  1. Global environment setting support.
  2. Simple API.

Usage

1. Using composer

1. Add a method in Bootstrap

class Bootstrap extends Yaf\Bootstrap_Abstract
{

    public function _initLoader(Dispatcher $dispatcher)
    {
        require __DIR__ . '/../vendor/autoload.php';
    }
}

2. Download it via composer

composer require lovelock/yafconf, (*2)

2. Classic way

If you don't like composer, you can require it from your local directory as well. You may put it in your library path as you wish., (*3)

Pre-configuration

This project relies on two global constants, (*4)

  1. CONF_PATH This tells Conf where to find the .ini files., (*5)

  2. APP_ENV This tells Conf what directives to find in .ini files., (*6)

Api

1. Conf::get($key)

$key MUST be . seperated. I.E, a dot is used as a seperator of the configuration path and its real key. e.g:, (*7)

Conf::get('database.database.host')

will find the database.ini in CONF_PATH and fetch the value of the key database.host in the configuration., (*8)

It supports array as well, which means, if your configuration file is like this:, (*9)

; database.ini
[product]
database.dbtype=mysql
database.host=127.0.0.1
database.port=3306
database.dbname=ttlive
database.user=root
database.password=root
database.charset=utf8

[dev : product]
database.host=192.168.1.103

Conf::get('database.database') will give you an array, (*10)

array (
    'dbtype'   => 'mysql',
    'host'     => '127.0.0.1',
    'port'     => '3306',
    'dbname'   => 'ttlive',
    'user'     => 'root',
    'password' => 'root',
    'charset'  => 'utf8',
)

Further more, if you set the constant APP_ENV = dev, and the result array would be, (*11)

array (
    'dbtype'   => 'mysql',
    'host'     => '192.168.1.103',
    'port'     => '3306',
    'dbname'   => 'ttlive',
    'user'     => 'root',
    'password' => 'root',
    'charset'  => 'utf8',
)

TODO

  1. [ ] Add default value support.

The Versions

02/04 2018

1.0

1.0.0.0

  Sources   Download

08/08 2016

dev-master

9999999-dev

  Sources   Download

MIT

by Frost Wong

08/08 2016

1.5

1.5.0.0

  Sources   Download

MIT

by Frost Wong

08/08 2016

1.4

1.4.0.0

  Sources   Download

MIT

by Frost Wong

06/08 2016

1.3

1.3.0.0

  Sources   Download

MIT

by Jason Wang

06/08 2016

1.2

1.2.0.0

  Sources   Download

MIT

by Jason Wang