Download the PHP package tyler/envase without Composer
On this page you can find all versions of the php package tyler/envase. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package envase
Short Description Tiny PHP PSR ContainerInterface Implementation
License MIT
Informations about the package envase
Envase
Very tiny PHP implementation of the PSR-11 Container.
"Envase" is Spanish for Container.
About
Envase container is extremely easy to configure and use. It features a
static registry as well as the ability to resolve classes and their dependencies using autowiring. Like a lot of container implementations
when you call get
it will only resolve the instance the first time and any future call will return the original resolved instance.
Installation
Usage
Basic
Closures
So we can lazy load class instances at the time of first use
you can add definitions as Closures that will be invoked the first time
get
is called.
Note: The next time get is called for 'foo' the resolved instance will be returned
Autowiring
By default (might change later) if you ask the container for an object
it will resolve all of the __construct
dependencies recursively with
the container. IF a constructor argument is a primitive type it will attempt to resolve it by name from the container;
In this case $foo
will be an instance of class Foo
and will have the
properties $bar = instance of Bar
and $dirToSomething = '/path/to/somewhere'
Injectable Properties
If a property on a class being resolved by the container has the #[Inject]
attribute, the container
will use that to set that properties value.
If you set this property form the constructor, Injected properties will override the constructor set
If a key or object can't be resovled the container will throw a NotFoundException
Making objects
IF you need to make a new instance of a class you can call the containers
make
method. Note, this will only make a new instance of that class, all
dependencies will be resolved from the container;