Basic usage
<?php
use Abellion\Resolver\Resolver;
$resolver = new Resolver;
Resolving any types
Resolve $subject and all of its dependencies.
public mixed resolve(mixed $subject, array $parameters = [])
$subject
Can be a string (for classe name, function name or static method name), a closure or an array (for dynamic methods).
//String (function name)
$resolver->resolve('strlen', ['Antoine']); //Return 7
//String (class name)
$resolver->resolve(Resolver::class); //Return a new Resolver instance
//String (static method name)
$resolver->resolve('Resolver::isClass', [Resolver::class]); //Return true
//Closure
$resolver->resolve(function() {
return 'Antoine';
}); //Return 'Antoine'
//Array (object and method name)
$resolver->resolve([$resolver, 'resolve'], ['subject' => 'strlen', 'parameters' => ['Antoine']]); //Return 7
$parameters
An array that the resolver uses to resolve the given type, in case where some dependencies couldn't be resolved automagically, or if you want to force the injection for a parameter. The keys of the array are used to identify which parameter has to be injected. Keys can be a integer (correspond to the order, from 0, where the parameters went in the given type) or a string (correspond to the name of the parameter).
//With numbered key
$resolver->resolve('strlen', ['Antoine']);
//With named key
$resolver->resolve('strlen', ['str' => 'Antoine']);
Resolving a class
Resolve $subject and all of his dependencies. Useful if you know by advance that what you want to resolve is a class.
public mixed resolveClass(string $subject, array $parameters = [])
Resolving a method
Resolve $subject and all of his dependencies. Useful if you know by advance that what you want to resolve is a method.
public mixed resolveMethod(mixed $subject, array $parameters = [])
Resolving a function
Resolve $subject and all of his dependencies. Useful if you know by advance that what you want to resolve is a function (string or closure).
public mixed resolveFunction(mixed $subject, array $parameters = [])