Creates an operation instance from a request.
An operation can be defined as a route, in which case the path of the request starts with
"/api/". An operation can also be defined using the request parameters, in which case
the ICanBoogie\Operation::DESTINATION
, ICanBoogie\Operation::NAME
and optionally ICanBoogie\Operation::KEY
parameters are defined
within the request parameters.
When the operation is defined as a route, the method searches for a matching route.
If a matching route is found, the captured parameters of the matching route are merged
with the request parameters and the method tries to create an Operation instance using the
route.
If no matching route could be found, the method tries to extract the ICanBoogie\Operation::DESTINATION
,
ICanBoogie\Operation::NAME
and optional ICanBoogie\Operation::KEY
parameters from the route using the
/api/:destination(/:key)/:name
pattern. If the route matches this pattern, captured
parameters are merged with the request parameters and the operation decoding continues as
if the operation was defined using parameters instead of the REST API.
Finally, the method searches for the ICanBoogie\Operation::DESTINATION
, ICanBoogie\Operation::NAME
and optional
ICanBoogie\Operation::KEY
parameters within the request parameters to create the Operation instance.
If no operation was found in the request, the method returns null.
Instancing using the matching route
The matching route must define either the class of the operation instance (by defining the
class
key) or a callback that would create the operation instance (by defining the
callback
key).
If the route defines the instance class, it is used to create the instance. Otherwise, the
callback is used to create the instance.
Instancing using the request parameters
The operation destination (specified by the ICanBoogie\Operation::DESTINATION
parameter) is the id of the
destination module. The class and the operation name (specified by the ICanBoogie\Operation::NAME
parameter) are used to search for the corresponding operation class to create the instance:
ICanBoogie\<normalized_module_id>\<normalized_operation_name>Operation
The inheritance of the module class is used the find a suitable class. For example,
these are the classes tried for the "articles" module and the "save" operation:
ICanBoogie\Modules\Articles\SaveOperation
ICanBoogie\Modules\Contents\SaveOperation
ICanBoogie\Modules\Nodes\SaveOperation
An instance of the found class is created with the request arguments and returned. If the
class could not be found to create the operation instance, an exception is raised.
Parameters
$request
- The request parameters.
Returns
Throws
BadMethodCallException
when the destination module or the operation name is
not defined for a module operation.
ICanBoogie\HTTP\NotFound
if the operation is not found.