Parses YAML files and adds them to Slim's config application instance method.

Overview

Slim Config - YAML

Build Status StyleCI Total Downloads Latest Stable Version License

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.

Getting Started

Installation

Composer

Install composer in your project.

curl -s https://getcomposer.org/installer | php

Create a composer.json file in your project root:

{
	"require": {
		"techsterx/slim-config-yaml": "1.*"
	}
}

Install via composer:

php composer.phar install

Add this line to your application's index.php file:

<?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.

<?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.

$slimYaml = \BurningDiode\Slim\Config\Yaml::getInstance();

_() is the shorthand equivalent of getInstance().

$slimYaml = \BurningDiode\Slim\Config\Yaml::_();

To add a single file, use the addFile() method.

\BurningDiode\Slim\Config\Yaml::getInstance()->addFile('/path/to/some/file.yaml');

You can also chain multiple addFile() methods togethor.

\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.

\BurningDiode\Slim\Config\Yaml::getInstance()->addDirectory('/path/to/directory');

You can chain with the addDirectory() method as well.

\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.

\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.

config.yaml

parameters:
    key1: value1
    key2: value2
    
application:
    keya: %key1%
    keyb: %key2%

app.php

\BurningDiode\Slim\Config\Yaml::_()->addFile('config.yml');

$config = $app->config('application');

print_r($config);

Output:

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.

parameters.yml

parameters:
    db_host:  localhost
    db_user:  username
    db_pass:  password
    db_dbase: database

database.yml

imports:
    - { resource: parameters.yml }
    
database:
    hostname: %db_host%
    username: %db_user%
    password: %db_pass%
    database: %db_dbase%

app.php

\BurningDiode\Slim\Config\Yaml::_()->addFile('database.yml');

$db_config = $app->config('database');

print_r($db_config);

Output:

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).

You might also like...
A sample CakePHP api application using CakeDC/cakephp-api and swoole as server

CakePHP Application Skeleton composer create-project --prefer-dist cakephp/app Added sample data using https://github.com/annexare/Countries Created m

High-Performance Long-Living PHP Framework for modern enterprise application development
High-Performance Long-Living PHP Framework for modern enterprise application development

Documentation · Discord · Telegram · Twitter Spiral Framework is a High-Performance Long-Living Full-Stack framework and group of over sixty PSR-compa

Mako skeleton application.

Mako Framework Mako is a lightweight and easy to use PHP framework based on the MVC architectural design pattern. Check out the documentation and crea

A multithreaded application server for PHP, written in PHP.

appserver.io, a PHP application server This is the main repository for the appserver.io project. What is appserver.io appserver.io is a multithreaded

PHPLucidFrame (a.k.a LucidFrame) is an application development framework for PHP developers

PHPLucidFrame (a.k.a LucidFrame) is an application development framework for PHP developers. It provides logical structure and several helper utilities for web application development. It uses a functional architecture to simplify complex application development. It is especially designed for PHP, MySQL and Apache. It is simple, fast, lightweight and easy to install.

This package provides some basic methods to implement a self updating functionality for your Laravel application. Already bundled are some methods to provide a self-update mechanism via Github or some private repository via http.

This package provides some basic methods to implement a self updating functionality for your Laravel 5 application. Already bundled are some methods to provide a self-update mechanism via Github.

🚀 Developing Rocketseat's Next Level Week (NLW#05) Application using PHP/Swoole + Hyperf

Inmana PHP 🚀 Developing Rocketseat 's Next Level Week (NLW#05) Application using Swoole + Hyperf. This is the app of the Elixir track. I know PHP/Swo

Supercharge your Laravel application's performance.

Introduction Laravel Octane supercharges your application's performance by serving your application using high-powered application servers, including

PIP is a tiny application framework built for people who use a LAMP stack.

PIP is a tiny application framework built for people who use a LAMP stack. PIP aims to be as simple as possible to set up and use.

Comments
  • Cache

    Cache

    Hey,

    Does it support cache? If not, guidelines to implementation?

    I don't want to read the yaml files on every request so it would be nice to cache it into a PHP array for OPcode cache for X duration.

    Thanks!

    opened by Zyles 1
  • Twig multi-dimensional key's are not overwritten when importing

    Twig multi-dimensional key's are not overwritten when importing

    use case:

    config_prod.yml

    imports:
        - { resource: config.yml }
    framework:
        mode: development
        debug: true
        level1:
            level2.level2.2:
                level3: value
    

    config.yml

    imports:
      - { resource: parameters.yml }
    framework:
       templates.path: %templates.path%
    

    Result:

    $app->config('framework')
    

    results in

    array(
       'mode' => 'development',
       'debug' => true,
       'level1' => array(
          'level2.level2.2' => array(
             'level3' => 'value'
          )
       )
    )
    

    The templates.path setting is gone!

    opened by leroy0211 0
Releases(v1.0.6)
  • v1.0.6(Jul 10, 2015)

  • v1.0.5(Apr 6, 2015)

  • v1.0.4(Feb 14, 2015)

  • v1.0.3(Dec 19, 2014)

    Global Parameters will now be processed correctly when the config file does not contain local parameters. Fixed the addParameters() method overwriting global parameters instead of appending when called. Updated README for correct addParameters() usage.

    Source code(tar.gz)
    Source code(zip)
  • v1.0.2(Apr 25, 2014)

    Added ability to add global parameters, which will be accessible to all resources that are parsed. Call addParameters(array) before calling addFile() or addDirectory().

    \BurningDiode\Slim\Config\Yaml::_()->addParameters(array('key' => 'value'));
    \BurningDiode\Slim\Config\Yaml::_()->addFile(<path to file>);
    

    addParameters, addFile, and addDirectory now return the current instance, allowing these methods to be chained.

    \BurningDiode\Slim\Config\Yaml::_()->addParameters(array('app.root' => dirname(__FILE__)))
        ->addDirectory('app/config');
    
    Source code(tar.gz)
    Source code(zip)
  • v1.0.1(Apr 25, 2014)

    Updated namespace to \BurningDiode\Slim\Config.

    To parse all .yml files in a directory:

    \BurningDiode\Slim\Config\Yaml::_()->addDirectory(<directory path>);
    

    To parse just a single file:

    \BurningDiode\Slim\Config\Yaml::_()->addFile(<file path>);
    
    Source code(tar.gz)
    Source code(zip)
  • v1.0.0(Apr 17, 2014)

Kit is a lightweight, high-performance and event-driven web services framework that provides core components such as config, container, http, log and route.

Kit What is it Kit is a lightweight, high-performance and event-driven web services framework that provides core components such as config, container,

null 2 Sep 23, 2022
A simple PHP MVC framework without extra files and codes that you don't need

Welcome to (SPM) Simple PHP MVC, just what you need! This is a simple PHP MVC framework without extra files and codes that you don't need.

Van Hudson Galvoso 5 Sep 17, 2022
Files Course Laravel Microservice E-mail

Curso Laravel Microservices com RabbitMQ (micro e-mail) Saiba Mais Sobre o Curso Requisitos Este micro e-mail depende do microservice 01, portanto, pr

EspecializaTi 9 Oct 21, 2021
This Slim Framework middleware will compile LESS CSS files on-the-fly using the Assetic library

This Slim Framework middleware will compile LESS CSS files on-the-fly using the Assetic library. It supports minification and caching, also via Asseti

Gerard Sychay 22 Mar 31, 2020
Dictionary of attack patterns and primitives for black-box application fault injection and resource discovery.

FuzzDB was created to increase the likelihood of finding application security vulnerabilities through dynamic application security testing. It's the f

FuzzDB Project 7.1k Dec 27, 2022
A simple, secure, and scalable PHP application framework

Opulence Introduction Opulence is a PHP web application framework that simplifies the difficult parts of creating and maintaining a secure, scalable w

Opulence 732 Dec 30, 2022
Newsprint is a simple web application that will fetch the front page of a newspaper and display it on an eink display

Newsprint is a simple web application that will fetch the front page of a newspaper and display it on an eink display. The specific resolutions and sizes have been setup to work with a 32" eInk place & play display from Visionect but can be modified for other screen resolutions.

Greg Raiz 199 Dec 20, 2022
💾 High-performance PHP application server, load-balancer and process manager written in Golang. RR2 releases repository.

RoadRunner is an open-source (MIT licensed) high-performance PHP application server, load balancer, and process manager. It supports running as a serv

Spiral Scout 45 Nov 29, 2022
🤯 High-performance PHP application server, load-balancer and process manager written in Golang

RoadRunner is an open-source (MIT licensed) high-performance PHP application server, load balancer, and process manager. It supports running as a serv

Spiral Scout 6.9k Jan 3, 2023
Opulence is a PHP web application framework that simplifies the difficult parts of creating and maintaining a secure, scalable website.

Opulence Introduction Opulence is a PHP web application framework that simplifies the difficult parts of creating and maintaining a secure, scalable w

Opulence 733 Sep 8, 2022