2017 © Pedro Peláez
 

library yaml2pimple

Build a Pimple/Container from a config file

image

gonzalo123/yaml2pimple

Build a Pimple/Container from a config file

  • Sunday, April 23, 2017
  • by gonzalo123
  • Repository
  • 2 Watchers
  • 22 Stars
  • 6,828 Installations
  • PHP
  • 1 Dependents
  • 1 Suggesters
  • 11 Forks
  • 5 Open issues
  • 1 Versions
  • 2 % Grown

The README.md

Pimple/Container builder

Build Status, (*1)

Simple tool build pimple containers from a configuration file, (*2)

Imagine this simple application:, (*3)

use Pimple\Container;

$container         = new Container();
$container['name'] = 'Gonzalo';

$container['Curl']  = function () {
    return new Curl();
};
$container['Proxy'] = function ($c) {
    return new Proxy($c['Curl']);
};

$container['App'] = function ($c) {
    return new App($c['Proxy'], $c['name']);
};

$app = $container['App'];
echo $app->hello();

We define the dependencies with code. But we want to define dependencies using a yml file for example:, (*4)

parameters:
  name: Gonzalo

services:
  App:
    class:     App
    arguments: [@Proxy, %name%]
  Proxy:
    class:     Proxy
    arguments: [@Curl]
  Curl:
    class:     Curl

With this library we can create a pimple container from this yaml file (similar syntax than Symfony's Dependency Injection Container), (*5)

use Pimple\Container;
use G\Yaml2Pimple\ContainerBuilder;
use G\Yaml2Pimple\YamlFileLoader;
use Symfony\Component\Config\FileLocator;

$container = new Container();

$builder = new ContainerBuilder($container);
$locator = new FileLocator(__DIR__);
$loader = new YamlFileLoader($builder, $locator);
$loader->load('services.yml');

$app = $container['App'];
echo $app->hello();

The Versions

23/04 2017

dev-master

9999999-dev

Build a Pimple/Container from a config file

  Sources   Download

MIT

The Requires

 

dependency injection container pimple