Download the PHP package scruwi/container without Composer
On this page you can find all versions of the php package scruwi/container. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package container
My DI Container
It's my own implementation PSR-11 Container Interface.
Installation
Init
Resolvers
ClassResolver
- defines namespaces, that are allowed to autowireParameterResolver
- defines scalar parameters, that can be set to constructorsDefinitionResolver
- defines paths to definitions
You can implement your resolvers in a project if you need them. Look at the Interfaces
namespace.
ClassResolver
Only classes from defined namespaces can be autowired.
ParameterResolver
Typical usage:
Expected behaviour:
Parameter with default value does not have to be resolved by the config:
You can create a specific resolver in your way and use it in your project. Just implement ParameterResolverInterface
and specify it during container construct.
DefinitionResolver
Attach definitions to container.
Definition, there is no more than a factory that creates an object in a specific way. There is one
specific ReflectionClassDefinition
that constructs classes by their reflections. All autowired classes use that factory
to create their object.
You should create as many definitions in your project as you need and specify them during container construct or attach
them later by $container->addDefinition()
method. Any definition must implement DefinitionInterface
.
Typical definition class looks like this:
You can fetch some default parameters from the ParameterResolver:
Also, you can find out from which context it was called. It may be useful for autowire interfaces:
Exceptions
NotFoundExceptionInterface
- for an unknown entryContainerExceptionInterface
- for all common exceptions in the containerCircularReferencesException
- there is a special exception for circular references in the container