Resolver
The Streams Platform provides a powerful value handler pattern that let's you defer the value or something to a handler
. The resolver
service makes it easy to resolve the value from such handlers.
The resolver
is usually used in other parts of the system so it's helpful to understand how it works even though you may not use it directly.
Introduction
This section will show you what a resolver is and how to use it.
Handlers
Handlers is a generic term for a class that handles the value for something.
Where a typical attribute in an array might look like:
$array = [
'example' => 'Test',
];
A value handler
might look like this:
$array = [
'example' => 'Example\TestHandler@value',
];
A value can also define a self handling handler:
$array = [
'example' => Example\TestHandler::class, // Assumes 'Example\TestHandler@handle'
];
Basic Usage
To start resolving values in your class you need to include the \Anomaly\Streams\Platform\Support\Resolver
class.
Resolver::resolve()
The resolve
method recursively resolves values within the target
value. The target
is called through the Service Container and supports class and method injection.
Returns: mixed
Arguments
Key | Required | Type | Default | Description |
---|---|---|---|---|
$target |
true |
string |
none |
The value handler. |
$arguments |
false |
array |
null |
The arguments to pass to the handler. |
$options |
false |
array |
null |
Options for the resolver. |
Example
$resolver->resolve('Example\Test@value', compact('entry'));
Available Options
-
method
- The handler method when no method is defined. Defaults tohandle
.