PHPackages                             td7650/yml2pimple - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. td7650/yml2pimple

ActiveLibrary[PSR &amp; Standards](/categories/psr-standards)

td7650/yml2pimple
=================

Build a Pimple/Container from a config file

1.0.7(10y ago)11.3kMITPHPPHP &gt;=5.3.3

Since May 30Pushed 10y ago1 watchersCompare

[ Source](https://github.com/td7650/yml2pimple)[ Packagist](https://packagist.org/packages/td7650/yml2pimple)[ RSS](/packages/td7650-yml2pimple/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (4)Versions (14)Used By (0)

2015-05-29 forked from gonzalo123/yml2pimple

Pimple/Container builder
========================

[](#pimplecontainer-builder)

[![SensioLabsInsight](https://camo.githubusercontent.com/75202dd0b93c2099f91b9b654ef38af966305735ec575b8f1b52b80430cd5ea7/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f65356639663466332d633864362d346230382d383263392d3635643034346364346630362f6d696e692e706e67)](https://insight.sensiolabs.com/projects/e5f9f4f3-c8d6-4b08-82c9-65d044cd4f06)

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

```
# 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: |
   this is a example for a lazy constructed parameter combined from
   fragments defined later, its dynamic and is evaluated every time
   its accessed
  combined: 'Lazy Parameter example: %fragment1% %fragment2%'

  desc2: |
   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
  $combined2: 'Lazy Parameter example2: %fragment1% %fragment2%'

  # 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'];
```

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 76.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~10 days

Recently: every ~27 days

Total

12

Last Release

3897d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3807d86a9ee27cfe3dc7fcd665c095cf6522356b55cc94b7c1a8c9a1c344d0a3?d=identicon)[td7650](/maintainers/td7650)

---

Top Contributors

[![td7650](https://avatars.githubusercontent.com/u/12662697?v=4)](https://github.com/td7650 "td7650 (93 commits)")[![gonzalo123](https://avatars.githubusercontent.com/u/39072?v=4)](https://github.com/gonzalo123 "gonzalo123 (23 commits)")[![cordoval](https://avatars.githubusercontent.com/u/328359?v=4)](https://github.com/cordoval "cordoval (5 commits)")

---

Tags

containerdependency-injectionpimple

### Embed Badge

![Health badge](/badges/td7650-yml2pimple/health.svg)

```
[![Health](https://phpackages.com/badges/td7650-yml2pimple/health.svg)](https://phpackages.com/packages/td7650-yml2pimple)
```

###  Alternatives

[mrclay/props-dic

Props is a simple DI container that allows retrieving values via custom property and method names

3611.7M3](/packages/mrclay-props-dic)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
