Download the PHP package pine3ree/pine3ree-mezzio-pimple-container without Composer
On this page you can find all versions of the php package pine3ree/pine3ree-mezzio-pimple-container. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package pine3ree-mezzio-pimple-container
pine3ree-mezzio-pimple-container
This package provides a factory for Pimple\Psr11\Container instances to be used in Mezzio applications
It is actually based on the abandoned library laminas-pimple-config modified in order to use a single pimple-psr-container. Most of the following text is taken from it.
Installation
Run the following to install this library:
Configuration
To get a configured PSR-11 Pimple container, do the following:
Usually the dependency configuration is part of the application configuration:
The dependencies
array can contain the following keys:
-
services
: an associative array that maps a key to a specific service instance (or pimple parameter value) -
invokables
: an associative array that map a key to a constructor-less service class; 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. The key can be omitted if equal to the service class. -
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 classes or callables. Delegator factories are commonly used to customize and/or decorate the original service. -
extensions
: an associative array that maps service names to lists of extension factory classes or callables, see the the section below. -
shared
: associative array that map a service name to a boolean, in order to indicate the container if it should cache or not a service created through the get method, overriding the shared_by_default setting. shared_by_default
: boolean that indicates whether services created through theget
method should be cached. This istrue
by default.
Please note: the
services
,invokables
andfactories
configurations cannot all be empty, that is at least one service must be configured.Please note that when injected by the factory the whole configuration is available in the
$container
on theconfig
key:
extensions
Since the
extensions
configuration is only available with the Pimple container, it is recommended to usedelegators
in order to keep the highest compatibility and allow easier switch to other container libraries.
An extension factory is an invokable object with the following signature:
The parameters passed to the extension factory are the following:
$service
is the real service instance.$container
is the psr-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:
You can also return a different instance from the extension factory:
Please note that when configuring extensions, you must provide a list of extension factories for the service, and not a single extension factory name:
Service extensions are called in the same order as defined in the list.
Using with Mezzio
Replace contents of config/container.php
with the following: