Final Class Yiisoft\Validator\RuleHandlerResolver\RuleHandlerContainer
| Inheritance | Yiisoft\ |
|---|---|
| Implements | Yiisoft\ |
An implementation for {@see RuleHandlerResolverInterface} acting as a wrapper over dependency injection container ({@see ContainerInterface}) throwing more specific exceptions and executing additional checks during resolving a rule handler name to make sure that if a handler was found, then it's indeed a valid handler to work with.
To use it, make sure to change config.php like so:
use Yiisoft\Validator\RuleHandlerResolverInterface;
use Yiisoft\Validator\RuleHandlerResolver\RuleHandlerContainer;
[
RuleHandlerResolverInterface::class => RuleHandlerContainer::class,
];
If you don't need DI container, {@see \
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\ |
|
| resolve() | Resolves a rule handler name to a corresponding rule handler instance. The actual resolving is delegated to {@see $container}. Throws more specific exceptions and executes additional checks to make sure that if a handler was found, then it's indeed a valid handler to work with. | Yiisoft\ |
Method Details
| public mixed __construct ( \ | ||
| $container | \ |
|
public function __construct(
/**
* @var ContainerInterface An instance of dependency injection container.
*/
private readonly ContainerInterface $container,
) {}
Resolves a rule handler name to a corresponding rule handler instance. The actual resolving is delegated to {@see $container}. Throws more specific exceptions and executes additional checks to make sure that if a handler was found, then it's indeed a valid handler to work with.
| public Yiisoft\ | ||
| $name | string |
A rule handler name ({@see \ |
| return | Yiisoft\ |
A corresponding rule handler instance. |
|---|---|---|
| throws | Yiisoft\ |
If a rule handler instance was not found. |
| throws | Yiisoft\ |
If a found instance is not a valid rule handler. |
public function resolve(string $name): RuleHandlerInterface
{
try {
$ruleHandler = $this->container->get($name);
} catch (NotFoundExceptionInterface $e) {
throw new RuleHandlerNotFoundException($name, previous: $e);
}
if (!$ruleHandler instanceof RuleHandlerInterface) {
throw new RuleHandlerInterfaceNotImplementedException($ruleHandler);
}
return $ruleHandler;
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.