Download the PHP package kassko/class-resolver without Composer
On this page you can find all versions of the php package kassko/class-resolver. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package class-resolver
class-resolver
Allows to create an object with dependencies from it's class name.
Installation
You can install this component with composer
composer require kassko/class-resolver:some_version
Usage
Use the class-resolver
Imagine, you need to create a cache instance and you have only the cache class name.
In the simpliest case, you can go for such code:
If the cache class has some dependencies, you can use the class-resolver and go through this kind of code:
If you need to handle yourself the case when the class cannot be resolved with the class-resolver, you can go through such code:
Feed the class-resolver
There are severals ways to feed the class-resolver. Each way of feeding has it's own class-resolver implementation.
From a map Kassko\ClassResolver\MapClassResolver
You can use a closure for lazy loading:
From a container by providing the get
method, and the has
method.
The get
method is the method that resolves the service and the has
method is the method that checks if the service exists.
From a container adapter that implements Kassko\ClassResolver\ContainerInterface
You can find an adapter in the bundle class-resolver-bundle. This is an adapter for Symfony container
.
From a closure
From a factory
From a static factory
From others class-resolver
If no resolver can handle the className, a basic new $className
is performed.
You can change this behaviour so that an exception Kassko\ClassResolver\NotResolvedClassException
is thrown instead.
Or you can provide your own default resolver implementation to setDefaultResolver()
method.