Giter Club home page Giter Club logo

yml2pimple's Introduction

Pimple/Container builder

Build Status

Simple tool build pimple containers from a configuration file

Imagine this simple application:

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:

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)

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

yml2pimple's People

Contributors

gonzalo123 avatar cordoval avatar ponent avatar alexstansfield avatar

Stargazers

Francesco Bianco (yafb) avatar  avatar Andrii Volin avatar ney chang avatar Rafael Nery avatar a9b avatar Thansen avatar Alexey avatar Noritaka Kitamura avatar Marius avatar Rivsen Tan avatar Will Vaughn avatar Leonid Terentyev avatar dongww avatar Jens Kohl avatar Simon Mönch avatar Emil Kilhage avatar Jesus Urrutia avatar Kostas Bariotis avatar Benjamin Doherty avatar Jacob Dreesen avatar  avatar Robert avatar

Watchers

 avatar James Cloos avatar  avatar

yml2pimple's Issues

License

Looking to use this in a small mvc wrapper for silex. I was wondering what the license for the project?

Support alias

Allow create service that are just an alias for another one.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.