zendframework/zend-pimple-config

Name: zend-pimple-config

Owner: Zend Framework

Description: Pimple container configurator based on ZF ServiceManager configuration

Created: 2017-09-27 20:31:23.0

Updated: 2018-04-11 17:55:54.0

Pushed: 2018-04-11 20:36:30.0

Homepage:

Size: 88

Language: PHP

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

zend-pimple-config

Build Status Coverage Status

This library provides utilities to configure a PSR-11 compatible Pimple container using zend-servicemanager configuration, for purposes of usage within Expressive.

Installation

Run the following to install this library:

mposer require zendframework/zend-pimple-config
Configuration

To get a configured PSR-11 Pimple container, do the following:

p
Zend\Pimple\Config\Config;
Zend\Pimple\Config\ContainerFactory;

tory = new ContainerFactory();

tainer = $factory(
new Config([
    'dependencies' => [
        'services'          => [],
        'invokables'        => [],
        'factories'         => [],
        'aliases'           => [],
        'delegators'        => [],
        'extensions'        => [],
        'shared'            => [],
        'shared_by_default' => true,
    ],
    // ... other configuration
])

The dependencies sub associative array can contain the following keys:

Please note, that the whole configuration is available in the $container on config key:

fig = $container->get('config');
extensions

The extensions configuration is only available with the Pimple container. If you are using Aura.Di or zend-servicemanager, you can use delegators instead. It is recommended to use delegators if you'd like to keep the highest compatibility and might consider changing the container library you use in the future.

An extension factory has the following signature:

Psr\Container\ContainerInterface;

ic function __invoke(
$service,
ContainerInterface $container,
$name

The parameters passed to the extension factory are the following:

Here is an example extension factory:

Psr\Container\ContainerInterface;

s ExtensionFactory

public function __invoke($service, ContainerInterface $container, $name)
{
    // do something with $service

    return $service;
}

You can also return a different instance from the extension factory:

Psr\Container\ContainerInterface;

s ExtensionFactory

public function __invoke($service, ContainerInterface $container, $name)
{
    return new Decorator($service);
}

Please note that when configuring extensions, you must provide a list of extension factories for the service, and not a single extension factory name:

Config([
'dependencies' => [
    'invokables' => [
        'my-service' => MyInvokable\Service::class,
    ],
    'extensions' => [
        'my-service' => [
            Extension1Factory::class,
            Extension2Factory::class,
            // ...
        ],
    ],
],

Service extensions are called in the same order as defined in the list.

Using with Expressive

Replace contents of config/container.php with the following:

p

Zend\Pimple\Config\Config;
Zend\Pimple\Config\ContainerFactory;

fig  = require __DIR__ . '/config.php';
tory = new ContainerFactory();

rn $factory(new Config($config));

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.