dev-master
9999999-dev
MIT
The Requires
by William Rex
dev-include-env
dev-include-env
MIT
The Requires
by William Rex
Parses YAML files and adds them into Slim's config singleton. Uses Symfony's YAML Component to parse files (http://github.com/symfony/Yaml). Allows other YAML files to be imported and parameters to be set and used., (*2)
Install composer in your project., (*3)
curl -s https://getcomposer.org/installer | php
Create a composer.json
file in your project root:, (*4)
{ "require": { "techsterx/slim-config-yaml": "1.*" } }
Install via composer:, (*5)
php composer.phar install
Add this line to your application's index.php
file:, (*6)
<?php require 'vendor/autoload.php';
Download and extract src/ directory into your project directory and require
it in your
application's index.php
file., (*7)
<?php require 'Slim\Slim.php'; require 'Yaml.php'; $app = new \Slim\Slim(); \BurningDiode\Slim\Config\Yaml::getInstance()->addFile('/path/to/some/file');
Slim Config - YAML uses a static method to get the currenct instance.
If an instance doesn't exist, a new one will be created.
Use the getInstance()
method to get the current instance., (*8)
$slimYaml = \BurningDiode\Slim\Config\Yaml::getInstance();
_()
is the shorthand equivalent of getInstance()
., (*9)
$slimYaml = \BurningDiode\Slim\Config\Yaml::_();
To add a single file, use the addFile()
method., (*10)
\BurningDiode\Slim\Config\Yaml::getInstance()->addFile('/path/to/some/file.yaml');
You can also chain multiple addFile()
methods togethor., (*11)
\BurningDiode\Slim\Config\Yaml::getInstance() ->addFile('/path/to/some/file.yaml') ->addFile('/path/to/another/file.yaml');
You can import a whole directory of YAML files., (*12)
\BurningDiode\Slim\Config\Yaml::getInstance()->addDirectory('/path/to/directory');
You can chain with the addDirectory()
method as well., (*13)
\BurningDiode\Slim\Config\Yaml::getInstance() ->addDirectory('/path/to/directory') ->addFile('/path/to/some/file.yaml');
Specify some global parameters to be used by all YAML files processed., (*14)
\BurningDiode\Slim\Config\Yaml::_() ->addParameters(array('app.root' => dirname(__FILE__))) ->addDirectory('/path/to/config/directory') ->addFile('/path/to/file/outside/of/config/directory.yml');
You can specify parameters in YAML files that will be replaced using keywords. Parameters are only available to the resource currently being processed., (*15)
config.yaml, (*16)
parameters: key1: value1 key2: value2 application: keya: %key1% keyb: %key2%
app.php, (*17)
\BurningDiode\Slim\Config\Yaml::_()->addFile('config.yml'); $config = $app->config('application'); print_r($config);
Output:, (*18)
Array ( [key1] => value1 [key2] => value2 )
You can import other YAML files which can be useful to keep all your common parameters in one file and used in others., (*19)
parameters.yml, (*20)
parameters: db_host: localhost db_user: username db_pass: password db_dbase: database
database.yml, (*21)
imports: - { resource: parameters.yml } database: hostname: %db_host% username: %db_user% password: %db_pass% database: %db_dbase%
app.php, (*22)
\BurningDiode\Slim\Config\Yaml::_()->addFile('database.yml'); $db_config = $app->config('database'); print_r($db_config);
Output:, (*23)
Array ( [hostname] => localhost [username] => username [password] => password [database] => database )
Slim Config - YAML is released under the [MIT public license] (https://raw.githubusercontent.com/techsterx/slim-config-yaml/master/LICENSE)., (*24)
MIT
MIT