gonzalo123 / yaml2pimple
Build a Pimple/Container from a config file
Installs: 10 294
Dependents: 0
Suggesters: 0
Security: 0
Stars: 23
Watchers: 3
Forks: 7
Open Issues: 5
Requires
- pimple/pimple: ^3.0
- symfony/config: ^3.1
- symfony/yaml: ^3.1
This package is not auto-updated.
Last update: 2024-11-09 15:46:26 UTC
README
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();