Download the PHP package psx/dependency without Composer
On this page you can find all versions of the php package psx/dependency. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download psx/dependency
More information about psx/dependency
Files in psx/dependency
Package dependency
Short Description Simple and fast DI container
License Apache-2.0
Homepage https://phpsx.org
Informations about the package dependency
Dependency
About
A simple and fast PSR-11 compatible DI container with features to autowire, tag
and inject services. Instead of YAML or config files services are simply defined
at a class by adding i.e. a getMyService
method.
Usage
Container
It is possible to extend the Container
class. All getXXX
methods are service
definitions which can be accessed through the get
method.
Autowire
The following example shows how you can use the autowiring feature:
The autowire resolver checks all arguments of the constructor of the AutowireService
class and tries to resolve each type based on the return type of the method
definitions in the container. Please take a look at test cases to see a complete
example.
It is also possible to provide a factory resolver which allow to resolve i.e. repository classes:
Tags
The following example shows how to get services which are annotated by a specific tag:
To tag you service you need to add the #Tag
attribute to your service
definition method. Then it is possible to use the tag resolver to receive all
services which have added a specific tag.
Compiler
If you have created a large container it is possible to compile this container into an optimized class which improves the performance.
Object builder
The object builder resolves properties with an #Inject
attribute and tries
to inject the fitting service to the property. If no explicit service name was
provided the property name is used. Note usually it is recommended to use simple
constructor injection, this class is designed for cases where this is not
feasible.
The object builder can use a cache instance to cache all defined service keys in production.
Factory
It is also possible to set services on a container in the "Pimple" way. Through this you can easily extend or overwrite existing containers. Note it is not possible to use theses services for autowiring. In general it is recommended to create a custom container and extend from the default container to add new services.