Open Monograph Press
3.3.0
|
Public Member Functions | |
_getValidatedServiceEndpointParts ($request) | |
_retrieveServiceEndpointParts ($request) | |
_validateServiceEndpointParts ($rpcServiceEndpointParts) | |
getRequestedComponent ($request) | |
getRequestedOp ($request) | |
& | getRpcServiceEndpoint ($request) |
handleAuthorizationFailure ($request, $authorizationMessage) | |
route ($request) | |
supports ($request) | |
url ($request, $newContext=null, $component=null, $op=null, $path=null, $params=null, $anchor=null, $escape=false) | |
![]() | |
__construct () | |
_authorizeInitializeAndCallRequest (&$serviceEndpoint, $request, &$args, $validate=true) | |
_contextLevelToContextName ($contextLevel) | |
_contextNameToContextLevel ($contextName) | |
_urlCanonicalizeNewContext ($newContext) | |
_urlFromParts ($baseUrl, $pathInfoArray=array(), $queryParametersArray=array(), $anchor='', $escape=false) | |
_urlGetAdditionalParameters ($request, $params=null, $escape=true) | |
_urlGetBaseAndContext ($request, $newContext=array()) | |
& | getApplication () |
getCacheFilename ($request) | |
& | getContext ($request, $requestedContextLevel=1, $forceReload=false) |
& | getContextByName ($request, $requestedContextName) |
& | getDispatcher () |
getHandler () | |
getIndexUrl ($request) | |
getRequestedContextPath ($request, $requestedContextLevel=1) | |
getRequestedContextPaths ($request) | |
isCacheable ($request) | |
setApplication ($application) | |
setDispatcher ($dispatcher) | |
setHandler ($handler) | |
Data Fields | |
$_component | |
$_op | |
$_rpcServiceEndpoint = false | |
$_rpcServiceEndpointParts = false | |
![]() | |
$_application | |
$_contextDepth | |
$_contextList | |
$_contextPaths = array() | |
$_contexts = array() | |
$_dispatcher | |
$_flippedContextList | |
$_handler | |
Class mapping an HTTP request to a component handler operation.
We are using an RPC style URL-to-endpoint mapping. Our approach follows a simple "convention-over-configuration" paradigm. If necessary the router can be subclassed to implement more complex URL-to-endpoint mappings.
For servers with path info enabled the component URL has the following elements:
.../index.php/context1/context2/$$$call$$$/path/to/handler-class/operation-name?arg1=...&arg2=...
where "$$$call$$$" is a non-mutable literal string and "path/to" is by convention the directory path below the "controllers" folder leading to the component. The next element ("handler-class" in this example) will be mapped to a component class file by "camelizing" the string to "HandlerClassHandler" and adding ".inc.php" to the end. The "operation-name" is transformed to "operationName" and represents the name of the handler method to be called. Finally "arg1", "arg2", etc. are parameters to be passed along to the handler method.
For servers with path info disabled the component URL looks like this:
.../index.php?component=path.to.handler-class&op=operation-name&arg1=...&arg2=...
The router will sanitize the request URL to a certain amount to make sure that random code inclusions are prevented. User authorization and parameter validation are however not the router's concern. These must be implemented on handler level.
NB: Component and operation names may only contain a-z, 0-9 and hyphens. Numbers are not allowed at the beginning of a name or after a hyphen.
NB: Component handlers must implement an initialize() method that will be called before the request is routed. The initialization method must enforce authorization and request validation.
Definition at line 66 of file PKPComponentRouter.inc.php.
PKPComponentRouter::_getValidatedServiceEndpointParts | ( | $request | ) |
Get the (validated) RPC service endpoint parts from the request. If no such RPC service endpoint parts can be retrieved then the method returns null.
$request | PKPRequest the request to be routed |
Definition at line 397 of file PKPComponentRouter.inc.php.
References $_rpcServiceEndpointParts, _retrieveServiceEndpointParts(), and _validateServiceEndpointParts().
Referenced by getRequestedComponent(), and getRequestedOp().
PKPComponentRouter::_retrieveServiceEndpointParts | ( | $request | ) |
Try to retrieve a (non-validated) array with the service endpoint parts from the request. See the classdoc for the URL patterns supported here.
$request | PKPRequest the request to be routed |
Definition at line 430 of file PKPComponentRouter.inc.php.
References $application, and PKPRouter\getApplication().
Referenced by _getValidatedServiceEndpointParts(), and supports().
PKPComponentRouter::_validateServiceEndpointParts | ( | $rpcServiceEndpointParts | ) |
This method pre-validates the service endpoint parts before we try to convert them to a file/method name. This also converts all parts to lower case.
$rpcServiceEndpointParts | array |
Definition at line 481 of file PKPComponentRouter.inc.php.
References PKPString\regexp_match(), and strtolower_codesafe().
Referenced by _getValidatedServiceEndpointParts().
PKPComponentRouter::getRequestedComponent | ( | $request | ) |
Retrieve the requested component from the request.
NB: This can be a component that not actually exists in the code base.
$request | PKPRequest |
Definition at line 118 of file PKPComponentRouter.inc.php.
References $_component, _getValidatedServiceEndpointParts(), and PKPString\camelize().
Referenced by getRpcServiceEndpoint(), and url().
PKPComponentRouter::getRequestedOp | ( | $request | ) |
Retrieve the requested operation from the request
NB: This can be an operation that not actually exists in the requested component.
$request | PKPRequest |
Definition at line 157 of file PKPComponentRouter.inc.php.
References $_op, _getValidatedServiceEndpointParts(), and PKPString\camelize().
Referenced by getRpcServiceEndpoint(), and url().
& PKPComponentRouter::getRpcServiceEndpoint | ( | $request | ) |
Get the (validated) RPC service endpoint from the request. If no such RPC service endpoint can be constructed then the method returns null.
$request | PKPRequest the request to be routed |
Definition at line 182 of file PKPComponentRouter.inc.php.
References $_rpcServiceEndpoint, $op, HookRegistry\call(), getRequestedComponent(), getRequestedOp(), instantiate(), and PKPRouter\setHandler().
Referenced by route().
PKPComponentRouter::handleAuthorizationFailure | ( | $request, | |
$authorizationMessage | |||
) |
Handle an authorization failure.
$request | Request |
$authorizationMessage | string a translation key with the authorization failure message. |
Reimplemented from PKPRouter.
Definition at line 365 of file PKPComponentRouter.inc.php.
References Config\getVar(), and AppLocale\requireComponents().
PKPComponentRouter::route | ( | $request | ) |
Routes a given request to a handler operation
$request | PKPRequest |
Reimplemented from PKPRouter.
Definition at line 257 of file PKPComponentRouter.inc.php.
References PKPRouter\_authorizeInitializeAndCallRequest(), and getRpcServiceEndpoint().
PKPComponentRouter::supports | ( | $request | ) |
Determines whether this router can route the given request.
$request | PKPRequest |
Reimplemented from PKPRouter.
Definition at line 99 of file PKPComponentRouter.inc.php.
References _retrieveServiceEndpointParts().
PKPComponentRouter::url | ( | $request, | |
$newContext = null , |
|||
$component = null , |
|||
$op = null , |
|||
$path = null , |
|||
$params = null , |
|||
$anchor = null , |
|||
$escape = false |
|||
) |
Build a handler request URL into PKPApplication.
$request | PKPRequest the request to be routed |
$newContext | mixed Optional contextual paths |
$handler | string Optional name of the handler to invoke |
$op | string Optional name of operation to invoke |
$path | mixed Optional string or array of args to pass to handler |
$params | array Optional set of name => value pairs to pass as user parameters |
$anchor | string Optional name of anchor to add to URL |
$escape | boolean Whether or not to escape ampersands, square brackets, etc. for this URL; default false. |
Reimplemented from PKPRouter.
Definition at line 275 of file PKPComponentRouter.inc.php.
References $op, PKPRouter\_urlCanonicalizeNewContext(), PKPRouter\_urlFromParts(), PKPRouter\_urlGetAdditionalParameters(), PKPRouter\_urlGetBaseAndContext(), getRequestedComponent(), getRequestedOp(), and PKPString\uncamelize().
string PKPComponentRouter::$_component |
the requested component handler
Definition at line 76 of file PKPComponentRouter.inc.php.
Referenced by getRequestedComponent().
string PKPComponentRouter::$_op |
the requested operation
Definition at line 81 of file PKPComponentRouter.inc.php.
Referenced by getRequestedOp().
callable PKPComponentRouter::$_rpcServiceEndpoint = false |
the rpc service endpoint the request was routed to
Definition at line 91 of file PKPComponentRouter.inc.php.
Referenced by getRpcServiceEndpoint().
array PKPComponentRouter::$_rpcServiceEndpointParts = false |
the rpc service endpoint parts from the request
Definition at line 86 of file PKPComponentRouter.inc.php.
Referenced by _getValidatedServiceEndpointParts().