2017 © Pedro Peláez
 

library slim-config-yaml

image

techsterx/slim-config-yaml

  • Tuesday, August 30, 2016
  • by techsterx
  • Repository
  • 2 Watchers
  • 3 Stars
  • 3,633 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 9 Versions
  • 1 % Grown

The README.md

Slim Config - YAML

Build Status StyleCI Total Downloads Latest Stable Version License, (*1)

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)

Getting Started

Installation

Composer

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';

Manual Install

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');

Methods

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');

Using Parameters

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
)

Importing Files

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
)

License

Slim Config - YAML is released under the [MIT public license] (https://raw.githubusercontent.com/techsterx/slim-config-yaml/master/LICENSE)., (*24)

The Versions

30/08 2016

dev-master

9999999-dev

  Sources   Download

MIT

The Requires

 

by William Rex

13/04 2015

v1.0.6

1.0.6.0

  Sources   Download

MIT

The Requires

 

by William Rex

13/04 2015

dev-include-env

dev-include-env

  Sources   Download

MIT

The Requires

 

by William Rex

06/04 2015

v1.0.5

1.0.5.0

  Sources   Download

MIT

The Requires

 

by William Rex

14/02 2015

v1.0.4

1.0.4.0

  Sources   Download

MIT

The Requires

 

by William Rex

19/12 2014

v1.0.3

1.0.3.0

  Sources   Download

MIT

The Requires

 

by William Rex

25/04 2014

v1.0.1

1.0.1.0

  Sources   Download

MIT

The Requires

 

by William Rex

25/04 2014

v1.0.2

1.0.2.0

  Sources   Download

MIT

The Requires

 

by William Rex

17/04 2014

v1.0.0

1.0.0.0

  Sources   Download

MIT

The Requires

 

by William Rex