Download the PHP package tsufeki/hmcontainer without Composer
On this page you can find all versions of the php package tsufeki/hmcontainer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package hmcontainer
HMContainer
HMContainer is a dependency injection container for PHP.
Installation
With Composer:
Usage
Create a container:
Add a value (constant parameter):
Retrieve it (HMContainer implements PSR-11):
Container is frozen during first get()
or freeze()
call and no new items can
be added afterwards.
Definition objects
There are to ways to add items to the container: convenience methods Container::setValue()
,
::setClass()
etc. or through creating Definition
objects yourself and calling
Container::set()
. I.e. those two lines are equivalent:
Multi-valued keys
Add multiple items to be retrieved as an array:
Class instantiation and autowiring
Add a class which will be instantiated once, during first get()
:
Dependencies can be automatically deduced (autowired) if you use class names as DI keys:
Autowiring key is guessed from parameter type hint, @param
tag type or special @Inject
tag:
Multi items are supported as well:
Mark parameter with @Optional
to have null
injected when dependency can't
be found:
Mix manual dependencies and autowiring by putting some null
s in dependency
array:
Using Definition
s as dependencies is also supported:
Aliases
Add an alias to other key:
Lazy items
Add a lazy item, it will return parameterless callable:
Custom definitions
You can add your custom instantiators by implementing
Definition interface and using
set()
method:
Serialization
Container can be serialized and unserialized for caching with standard PHP
serialize()
and unserialize()
, but only if you use serializable factories.
License
MIT - see LICENCE.
All versions of hmcontainer with dependencies
phpdocumentor/reflection-docblock Version ^4.2.0
phpdocumentor/type-resolver Version ^0.4.0
psr/container Version ^1.0