2017 © Pedro PelĂĄez
 

library yml2pimple

Build a Pimple/Container from a config file

image

td7650/yml2pimple

Build a Pimple/Container from a config file

  • Wednesday, January 13, 2016
  • by td7650
  • Repository
  • 2 Watchers
  • 1 Stars
  • 1,312 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 11 Forks
  • 0 Open issues
  • 14 Versions
  • 0 % Grown

The README.md

2015-05-29 forked from gonzalo123/yml2pimple, (*1)

Pimple/Container builder

SensioLabsInsight, (*2)

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

# test import
imports:
  - { resource: test2.yml}

parameters:
  app_class: App
  name: Gonzalo
  deep:
    # parameters can contain other parameters
    first: 'From the deep (%app_class%)'
    second: [1,2,3]
    third: [a,b,c]

  desc1: |
   <br><strong>this is a example for a lazy constructed parameter combined from
   fragments defined later, its dynamic and is evaluated every time
   its accessed</strong>
  combined: '

Lazy Parameter example: %fragment1% %fragment2%, (*4)

' desc2: | <br><strong>this is a example for a lazy constructed parameter combined from fragments defined later, its like a singleton (the paramater name starts with an $) and is frozen after its first accessed</strong> $combined2: '

Lazy Parameter example2: %fragment1% %fragment2%, (*5)

' # used by ExpressionNormalizer to evaluate expression vars $_normalize: test: @service_container services: App: # class names can reference parameters class: %app_class% # prototype returns a new instance each time scope: prototype # the instance is constructed lazy with a proxy factory lazy: true arguments: [@Proxy, %name%] calls: - [setName, ['Test']] # this is a optional parameter - [setDummy, ['@?Dummy']] # a configurator can modify the instance configurator: ['@Configurator', configure] # add a aspect to method hello() aspects: - {pointcut: 'hello', advice:'Configurator:beforeHello'} Proxy: class: Proxy lazy: true # the instance is created by the factory class factory: ['Factory', 'create'] arguments: [@service_container] #arguments: [@Curl] Curl: class: Curl lazy: true Configurator: class: Test # we can access elements of arrays with the symfony property access style (via normalizer) arguments: ['%deep..first%', '?"hallo"~" Welt "~test["name"]'] Factory: class: Factory
use G\Yaml2Pimple\ContainerBuilder;

use G\Yaml2Pimple\Loader\YamlFileLoader;
use G\Yaml2Pimple\Loader\CacheLoader;

use G\Yaml2Pimple\Normalizer\ChainNormalizer;
use G\Yaml2Pimple\Normalizer\PimpleNormalizer;
use G\Yaml2Pimple\Normalizer\ExpressionNormalizer;

use Symfony\Component\Config\FileLocator;

use G\Yaml2Pimple\Proxy\ServiceProxyAdapter;
use G\Yaml2Pimple\Proxy\AspectProxyAdapter;

use G\Yaml2Pimple\Factory\ServiceFactory;
use G\Yaml2Pimple\Factory\ParameterFactory;
use G\Yaml2Pimple\Factory\ProxyParameterFactory;

$container      = new \Pimple();
$builder        = new ContainerBuilder($container);

$ymlLoader      = new YamlFileLoader(
    new FileLocator(__DIR__)
);
$cacheLoader    = new CacheLoader($ymlLoader, __DIR__ . '/cache/');

// set the normalizers 
$builder->setNormalizer(
    new ChainNormalizer(
        array(
            new PimpleNormalizer(),
            new ExpressionNormalizer()
        )
    )
);

$parameterFactory   = new ProxyParameterFactory();

$serviceFactory     = new ServiceFactory(
    new ServiceProxyAdapter(__DIR__ . '/cache/')
);

$serviceFactory->setAspectFactory(
    new AspectProxyAdapter( __DIR__ . '/cache/')
);

// set our loader helper
$builder->setLoader($cacheLoader);

// lazy service proxy factory
$builder->setServiceFactory($serviceFactory);

// lazy parameter proxy factory
$builder->setParameterFactory($parameterFactory);

$builder->load('test.yml');

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

echo $container['desc1'];
echo $container['combined'];
$container['fragment2'] = 'Test';
echo $container['combined'];

echo $container['desc2'];
$container['fragment2'] = 'world';
echo $container['combined2'];
$container['fragment2'] = 'Test';
echo $container['combined2'];

The Versions

29/10 2015
16/09 2015

1.2.x-dev

1.2.9999999.9999999-dev

Build a Pimple/Container from a config file

  Sources   Download

MIT

The Requires

 

by Thomas DrÀger

dependency injection container pimple

14/09 2015

1.1.x-dev

1.1.9999999.9999999-dev

Build a Pimple/Container from a config file

  Sources   Download

MIT

The Requires

 

by Thomas DrÀger

dependency injection container pimple

14/09 2015
07/06 2015

1.0.x-dev

1.0.9999999.9999999-dev

Build a Pimple/Container from a config file

  Sources   Download

MIT

The Requires

 

by Thomas DrÀger

dependency injection container pimple

31/05 2015

1.0.7

1.0.7.0

Build a Pimple/Container from a config file

  Sources   Download

MIT

The Requires

 

by Thomas DrÀger

dependency injection container pimple

31/05 2015

1.0.6

1.0.6.0

Build a Pimple/Container from a config file

  Sources   Download

MIT

The Requires

 

by Thomas DrÀger

dependency injection container pimple

31/05 2015

1.0.5

1.0.5.0

Build a Pimple/Container from a config file

  Sources   Download

MIT

The Requires

 

by Thomas DrÀger

dependency injection container pimple

31/05 2015

1.0.4

1.0.4.0

Build a Pimple/Container from a config file

  Sources   Download

MIT

The Requires

 

by Thomas DrÀger

dependency injection container pimple

31/05 2015

1.0.2

1.0.2.0

Build a Pimple/Container from a config file

  Sources   Download

MIT

The Requires

 

by Thomas DrÀger

dependency injection container pimple

31/05 2015

1.0.3

1.0.3.0

Build a Pimple/Container from a config file

  Sources   Download

MIT

The Requires

 

by Thomas DrÀger

dependency injection container pimple

30/05 2015

1.0.1

1.0.1.0

Build a Pimple/Container from a config file

  Sources   Download

MIT

The Requires

 

by Thomas DrÀger

dependency injection container pimple

30/05 2015

1.0.0

1.0.0.0

Build a Pimple/Container from a config file

  Sources   Download

MIT

The Requires

 

by Thomas DrÀger

dependency injection container pimple