2017 © Pedro Peláez
 

library zend-pimple-config

PSR-11 Pimple container configurator for ZF and Expressive applications

image

zendframework/zend-pimple-config

PSR-11 Pimple container configurator for ZF and Expressive applications

  • Wednesday, April 11, 2018
  • by zendframework
  • Repository
  • 13 Watchers
  • 4 Stars
  • 1,620 Installations
  • PHP
  • 2 Dependents
  • 2 Suggesters
  • 3 Forks
  • 0 Open issues
  • 11 Versions
  • 21 % Grown

The README.md

zend-pimple-config

Repository abandoned 2019-12-31

This repository has moved to laminas/laminas-pimple-config., (*1)

Build Status Coverage Status, (*2)

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

Installation

Run the following to install this library:, (*4)

$ composer require zendframework/zend-pimple-config

Configuration

To get a configured PSR-11 Pimple container, do the following:, (*5)

<?php
use Zend\Pimple\Config\Config;
use Zend\Pimple\Config\ContainerFactory;

$factory = new ContainerFactory();

$container = $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:, (*6)

  • services: an associative array that maps a key to a specific service instance.
  • invokables: an associative array that map a key to a constructor-less service; i.e., for services that do not require arguments to the constructor. The key and service name usually are the same; if they are not, the key is treated as an alias.
  • factories: an associative array that maps a service name to a factory class name, or any callable. Factory classes must be instantiable without arguments, and callable once instantiated (i.e., implement the __invoke() method).
  • aliases: an associative array that maps an alias to a service name (or another alias).
  • delegators: an associative array that maps service names to lists of delegator factory keys, see the Expressive delegators documentation for more details.
  • extensions: an associative array that maps service names to lists of extension factory names, see the the section below.
  • shared: associative array that map a service name to a boolean, in order to indicate the service manager if it should cache or not a service created through the get method, independant of the shared_by_default setting.
  • shared_by_default: boolean that indicates whether services created through the get method should be cached. This is true by default.

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

$config = $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., (*8)

An extension factory has the following signature:, (*9)

use Psr\Container\ContainerInterface;

public function __invoke(
    $service,
    ContainerInterface $container,
    $name
);

The parameters passed to the extension factory are the following:, (*10)

  • $service is the real service instance.
  • $container is the container that is used while creating the extension for the requested service.
  • $name is the name of the service being requested.

Here is an example extension factory:, (*11)

use Psr\Container\ContainerInterface;

class 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:, (*12)

use Psr\Container\ContainerInterface;

class 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:, (*13)

new 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., (*14)

Using with Expressive

Replace contents of config/container.php with the following:, (*15)

<?php

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

$config  = require __DIR__ . '/config.php';
$factory = new ContainerFactory();

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

The Versions

11/04 2018

dev-develop

dev-develop

PSR-11 Pimple container configurator for ZF and Expressive applications

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

container zendframework zf expressive pimple psr-11

11/04 2018

dev-master

9999999-dev

PSR-11 Pimple container configurator for ZF and Expressive applications

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

container zendframework zf expressive pimple psr-11

11/04 2018

1.1.0

1.1.0.0

PSR-11 Pimple container configurator for ZF and Expressive applications

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

container zendframework zf expressive pimple psr-11

21/03 2018

dev-feature/shared

dev-feature/shared

PSR-11 Pimple container configurator for ZF and Expressive applications

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

container zendframework zf expressive pimple psr-11

15/03 2018

1.0.0

1.0.0.0

PSR-11 Pimple container configurator for ZF and Expressive applications

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

container zendframework zf expressive pimple psr-11

15/03 2018

dev-release-1.0.0

dev-release-1.0.0

PSR-11 Pimple container configurator for ZF and Expressive applications

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

container zendframework zf expressive pimple psr-11

08/02 2018

dev-hotfix/invokable-alias

dev-hotfix/invokable-alias

PSR-11 Pimple container configurator for ZF and Expressive applications

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

container zendframework zf expressive pimple psr-11

07/02 2018

1.0.0alpha1

1.0.0.0-alpha1

PSR-11 Pimple container configurator for ZF and Expressive applications

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

container zendframework zf expressive pimple psr-11

14/12 2017

dev-hotfix/php-coveralls

dev-hotfix/php-coveralls

PSR-11 Pimple container configurator for ZF and Expressive applications

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

container zendframework zf expressive pimple psr-11

21/11 2017

0.2.0

0.2.0.0 https://github.com/zendframework/zend-pimple-config

PSR-11 Pimple container configurator for ZF and Expressive applications

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

container zendframework zf expressive pimple psr-11

27/09 2017

0.1.0

0.1.0.0 https://github.com/webimpress/zend-pimple-config

PSR-11 Pimple container configurator for ZF applications

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

container zendframework zf pimple psr-11