Handles the operation and returns a response.
The $record and ICanBoogie\Operation::$form properties are unset in order for their
getters to be called on the next access, while keeping their scope.
The response object
The operation result is saved in a response object, which may contain meta data describing
or accompanying the result. For example, the ICanBoogie\Operation class returns success and
error messages in the $message and $errors properties.
Depending on the Accept header of the request, the response object can be formatted as
JSON or XML. If the Accept header is "application/json" the response is formatted as JSON.
If the Accept header is "application/xml" the response is formatted as XML. If the
Accept header is not of a supported type, only the result is printed, as a string.
For API requests, the output format can also be defined by appending the corresponding
extension to the request path:
/api/nodes/12/online.json
The response location
The Location header is used to ask the browser to load a different web page. This is often
used to redirect the user when an operation has been performed e.g. creating/deleting a
resource. The location property of the response is used to set that header. This is not
a desirable behavior for XHR because although we might want to redirect the user, we still
need to get the result of our request first. That is why when the location property is
set, and the request is an XHR, the location is set to the redirect_to field and the
location property is set to null to disable browser redirection.
Control, validation and processing
Before the operation is actually processed with the ICanBoogie\Operation::process() method, it is
controlled and validated using the ICanBoogie\Operation::control() and ICanBoogie\Operation::validate() methods. If the
control or validation fail the operation is not processed.
The controls passed to the ICanBoogie\Operation::control() method are obtained through the
$controls property or the ICanBoogie\Operation::get_controls() getter if the property is not
accessible.
Events
The failure event is fired when the control or validation of the operation failed. The
type property of the event is "control" or "validation" depending on which method failed.
Note that the event won't be fired if an exception is thrown.
The process:before event is fired with the operation as sender before the operation is
processed using the ICanBoogie\Operation::process() method.
The process event is fired with the operation as sender after the operation has been
processed if its result is not null.
Failed operation
If the result of the operation is null, the operation is considered as failed, in which
case the status code of the response is changed to 404 and the ICanBoogie\Operation\ProcessEvent is not
fired.
Note that exceptions are not caught by the method.
Parameters
$request
- The request triggering the operation.
Returns
Throws