Download the PHP package mouf/alias-container without Composer
On this page you can find all versions of the php package mouf/alias-container. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mouf/alias-container
More information about mouf/alias-container
Files in mouf/alias-container
Package alias-container
Short Description This package contains a really minimalist dependency injection container that can be used to create aliases of instances in existing containers.
License MIT
Homepage http://mouf-php.com
Informations about the package alias-container
Alias-Container
This package contains a really minimalist dependency injection container that can be used to create aliases of instances in existing containers. Alias-container is compatible with container-interop and is meant to be used in conjunction with other containers. By itself, Alias-container does not store any entry. It can only be used to create aliases of instances stored in other containers.
You can use AliasContainer to add support for alias for any container that does not support this feature.
Installation
Before using AliasContainer in your project, add it to your composer.json
file:
Defining aliases in the container
Creating an alias container is a matter of creating an AliasContainer
instance.
The AliasContainer
class takes 2 parameters:
- a delegate-lookup container (e.g. the container we will look aliases into)
- the list of aliases, as an associative array of strings
The list of entries is an associative array.
- The key is the identifier of the alias to create
- The value is the identifier of the entry that will be aliased
Fetching entries from the container
Fetching entries from the container is as simple as calling the get
method:
Adding aliases to the container
You can add new aliases using the set
method.
set
method.Removing aliases from the container
You can add new aliases using the remove
method.
Why the need for this package?
This package is part of a long-term effort to bring interoperability between DI containers. The ultimate goal is to make sure that multiple containers can communicate together by sharing entries (one container might use an entry from another container, etc...)