Class Dispatcher
Dispatches operation requests.
-
ICanBoogie\Operation\Dispatcher
implements
ICanBoogie\HTTP\DispatcherInterface
Methods summary
public
__invoke( ICanBoogie\HTTP\Request $request
)
Tries to create an ICanBoogie\Operation
instance from the specified request. The operation
is then executed and its response returned.
Tries to create an ICanBoogie\Operation
instance from the specified request. The operation
is then executed and its response returned.
If an operation could be created from the request, the operation
property of the request's
context is set to that operation.
For forwarded operation, successful responses are not returned unless the request is an XHR
or the response has a location.
Inheritdoc
public
rescue( ICanBoogie\Operation\Exception
$exception
, ICanBoogie\HTTP\Request $request
)
: ICanBoogie\Operation\Response
|null
Try to rescue the exception.
Try to rescue the exception.
The rescue process consists in the following steps:
- The operation associated with the exception cannot be retrieved the exception is
re-thrown.
- Otherwise, the
ICanBoogie\Operation::rescue
event of class ICanBoogie\Operation\RescueEvent
is fired. Event hooks attached to this event may replace the exception or provide a
response. If a response is provided it is returned.
- Otherwise, if the exception is not an instance of
ICanBoogie\Operation\Failure
the exception is
re-thrown.
- Otherwise, if the request is an XHR the response of the operation is returned.
- Otherwise, if the operation was forwarded the exception message is logged as an error
and the method returns.
- Otherwise, the exception is re-thrown.
In summary, a failed operation is rescued if a response is provided during the
ICanBoogie\Operation::rescue
event, or later if the request is an XHR. Although the
rescue of an operation might be successful, the returned response can be an error response.
Parameters
$exception
- The exception to rescue.
$request
- The request.
Returns
Throws
protected
retrieve_operation( ICanBoogie\Operation\Exception
& $exception
, ICanBoogie\HTTP\Request $request
, ICanBoogie\Operation\Failure
& $failure
= null )
: ICanBoogie\Operation
Retrieve the operation from the exception or request.
Retrieve the operation from the exception or request.
Parameters
$exception
$request
$failure
Returns
Throws
Exception
when the operation cannot be retrieved, that is the original exception.