Download the PHP package edvin/hbcontainer without Composer
On this page you can find all versions of the php package edvin/hbcontainer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package hbcontainer
HbContainer
A PSR-11 lightweight dependency injection container for all types of projects. Supports php 8.0 and newer.
Installation
With composer:
Resolving
HbContainer uses definitions
to define entries to be resolved by the container. The container can resolve any class that can be constructed with resolvable dependencies on its own. Resolved definitions are by default stored as weak references and can be set as singletons which will use a normal reference.
Getting entries
The HbContainer has three primary methods to get/call entries:
get
: Resolve and runtime-caches the resolved value for the next call.make
: Always resolve and return a new instance.call
: Resolve the provided argument as something to call and resolve its parameters.
The HbContainer takes an DefinitionSource
that contains several definitions that tell the container how to resolve the specific entry. The different types are:
DefinitionFactory
: An definition with an closure to return the item in its final state. The result is added to the singleton cache. Helper function:\HbLib\Container\factory
DefinitionClass
: An definition to construct a class with or without provided parameters. If any parameters are defined, the class is never runtime-cached. Helper function:\HbLib\Container\resolve
. Its optional to provide an class to this definition, and if none is provided it will assume the definition ID (index of the definition array) is the class name. See usage example below.DefinitionReference
: An definition to reference another definition entry, you may not provide parameters to this definition. Helper function:\HbLib\Container\reference
.DefinitionValue
: An definition to return some value. The value itself can be another definition. Helper function:\HbLib\Container\value
.
Interfaces
When depending on the container, it is recommended to depend on the provided interfaces:
\Psr\Container\ContainerInteface
: Provides theget
method.\HbLib\Container\FactoryInterface
: Provides themake
mehod.\HbLib\Container\InvokerInterface
: Provides thecall
mehod.
Usage
Compiling
The container supports compiling all resolved definitions to increase performance. The advantage of this in production environments is that the container does not need to look up all parameters everytime, but rather has all definitions and their dependencies resolved in one file.
How to
Compiling must be enabled on ContainerBuilder and some script must call writeCompiled:
Somewhere in your web app:
I do recommend that the ContainerBuilder::writeCompiled
call is performed in a separate cli command so that errors
does not affect your clients.
All versions of hbcontainer with dependencies
psr/container Version ^1.0|^2.0
laravel/serializable-closure Version ^1.3