2017 © Pedro Peláez
 

library slim-config

A slim middleware to read configuration from different files based on hassankhan/config

image

davidepastore/slim-config

A slim middleware to read configuration from different files based on hassankhan/config

  • Sunday, September 11, 2016
  • by DavidePastore
  • Repository
  • 3 Watchers
  • 23 Stars
  • 2,177 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 4 Forks
  • 1 Open issues
  • 3 Versions
  • 15 % Grown

The README.md

Slim Framework Config

![Latest version][ico-version] [Build Status][link-github-actions] ![Coverage Status][ico-scrutinizer] Quality Score ![Total Downloads][ico-downloads] PSR2 Conformance, (*1)

A file configuration loader that supports PHP, INI, XML, JSON, and YML files for the Slim Framework. It internally uses hassankhan/config., (*2)

Install

Via Composer, (*3)

``` bash $ composer require davidepastore/slim-config, (*4)


Requires Slim 3.0.0 or newer. ## Usage In most cases you want to register `DavidePastore\Slim\Config` for a single route, however, as it is middleware, you can also register it for all routes. ### Register per route ```php $app = new \Slim\App(); // Fetch DI Container $container = $app->getContainer(); // Register provider $container['config'] = function () { //Create the configuration return new \DavidePastore\Slim\Config\Config('config.json'); }; $app->get('/api/myEndPoint',function ($req, $res, $args) { //Here you have your configuration $config = $this->config->getConfig(); $secret = $config->get('security.secret'); })->add($container->get('config')); $app->run();

Register for all routes

$app = new \Slim\App();

// Fetch DI Container
$container = $app->getContainer();

// Register provider
$container['config'] = function () {
  //Create the configuration
  return new \DavidePastore\Slim\Config\Config('config.json');
};

// Register middleware for all routes
// If you are implementing per-route checks you must not add this
$app->add($container->get('config'));

$app->get('/foo', function ($req, $res, $args) {
  //Here you have your configuration
  $config = $this->config->getConfig();
  $secret = $config->get('security.secret');
});

$app->post('/bar', function ($req, $res, $args) {
  //Here you have your configuration
  $config = $this->config->getConfig();
  $ttl = $config->get('app.timeout', 3000);
});

$app->run();

Where are the benefits?

The configuration is loaded from the filesystem only when the given route is called in the per route usage. In the other case (_all routes_) the config should be general and used in the whole routes, because it's read in every request., (*5)

Just the tip of the iceberg!

You can read the hassankhan/config documentation here for more info., (*6)

Testing

bash $ phpunit, (*7)

Contributing

Please see CONTRIBUTING for details., (*8)

Credits

The Versions

11/09 2016

dev-master

9999999-dev

A slim middleware to read configuration from different files based on hassankhan/config

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

by Davide Pastore

middleware framework php json xml configuration ini config yaml slim

14/08 2016

v0.1.1

0.1.1.0

A slim middleware to read configuration from different files based on hassankhan/config

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

by Davide Pastore

middleware framework php json xml configuration ini config yaml slim

16/03 2016

v0.1.0

0.1.0.0

A slim middleware to read configuration from different files based on hassankhan/config

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

by Davide Pastore

middleware framework php json xml configuration ini config yaml slim