Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
PKPComponentRouter Class Reference
Inheritance diagram for PKPComponentRouter:
PKPRouter

Public Member Functions

 _getValidatedServiceEndpointParts ($request)
 
 _retrieveServiceEndpointParts ($request)
 
 _validateServiceEndpointParts ($rpcServiceEndpointParts)
 
 getRequestedComponent ($request)
 
 getRequestedOp ($request)
 
getRpcServiceEndpoint ($request)
 
 handleAuthorizationFailure ($request, $authorizationMessage)
 
 PKPComponentRouter ()
 
 route ($request)
 
 supports ($request)
 
 url ($request, $newContext=null, $component=null, $op=null, $path=null, $params=null, $anchor=null, $escape=false)
 
- Public Member Functions inherited from PKPRouter
 _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)
 
getContextByName ($request, $requestedContextName)
 
getDispatcher ()
 
 getIndexUrl ($request)
 
 getRequestedContextPath ($request, $requestedContextLevel=1)
 
 getRequestedContextPaths ($request)
 
 handleAuthorizationFailure ($request, $authorizationMessage)
 
 isCacheable ($request)
 
 PKPRouter ()
 
 route ($request)
 
 setApplication (&$application)
 
 setDispatcher ($dispatcher)
 
 supports ($request)
 
 url ($request, $newContext=null, $handler=null, $op=null, $path=null, $params=null, $anchor=null, $escape=false)
 

Public Attributes

 $_component
 
 $_op
 
 $_rpcServiceEndpoint = false
 
 $_rpcServiceEndpointParts = false
 
- Public Attributes inherited from PKPRouter
 $_contextDepth
 
 $_contextList
 
 $_contextPaths = array()
 
 $_contexts = array()
 
 $_flippedContextList
 

Detailed Description

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 components 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.

Member Function Documentation

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.

Parameters
$requestPKPRequest the request to be routed
Returns
array a string array with the RPC service endpoint parts as values.

Definition at line 398 of file PKPComponentRouter.inc.php.

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.

Parameters
$requestPKPRequest the request to be routed
Returns
array an array of (non-validated) service endpoint parts or null if the request is not an RPC request.

Definition at line 431 of file PKPComponentRouter.inc.php.

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.

Parameters
$rpcServiceEndpointPartsarray
Returns
array the validated service endpoint parts or null if validation does not succeed.

Definition at line 482 of file PKPComponentRouter.inc.php.

References String\regexp_match().

PKPComponentRouter::getRequestedComponent (   $request)

Retrieve the requested component from the request.

NB: This can be a component that not actually exists in the code base.

Parameters
$requestPKPRequest
Returns
string the requested component or an empty string if none can be found.

Definition at line 124 of file PKPComponentRouter.inc.php.

Referenced by 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.

Parameters
$requestPKPRequest
Returns
string the requested operation or an empty string if none can be found.

Definition at line 163 of file PKPComponentRouter.inc.php.

Referenced by 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.

Parameters
$requestPKPRequest the request to be routed
Returns
callable an array with the handler instance and the handler operation to be called by call_user_func().

Definition at line 188 of file PKPComponentRouter.inc.php.

PKPComponentRouter::handleAuthorizationFailure (   $request,
  $authorizationMessage 
)

Handle an authorization failure.

Parameters
$requestRequest
$authorizationMessagestring a translation key with the authorization failure message.

Definition at line 365 of file PKPComponentRouter.inc.php.

PKPComponentRouter::PKPComponentRouter ( )

Constructor

Definition at line 96 of file PKPComponentRouter.inc.php.

PKPComponentRouter::route (   $request)

Routes a given request to a handler operation

Parameters
$requestPKPRequest

Definition at line 259 of file PKPComponentRouter.inc.php.

PKPComponentRouter::supports (   $request)

Determines whether this router can route the given request.

Parameters
$requestPKPRequest
Returns
boolean true, if the router supports this request, otherwise false

Definition at line 105 of file PKPComponentRouter.inc.php.

PKPComponentRouter::url (   $request,
  $newContext = null,
  $component = null,
  $op = null,
  $path = null,
  $params = null,
  $anchor = null,
  $escape = false 
)

Build a handler request URL into PKPApplication.

Parameters
$requestPKPRequest the request to be routed
$newContextmixed Optional contextual paths
$handlerstring Optional name of the handler to invoke
$opstring Optional name of operation to invoke
$pathmixed Optional string or array of args to pass to handler
$paramsarray Optional set of name => value pairs to pass as user parameters
$anchorstring Optional name of anchor to add to URL
$escapeboolean Whether or not to escape ampersands, square brackets, etc. for this URL; default false.
Returns
string the URL

Definition at line 277 of file PKPComponentRouter.inc.php.

References getRequestedComponent(), and getRequestedOp().

Member Data Documentation

string PKPComponentRouter::$_component

the requested component handler

Definition at line 76 of file PKPComponentRouter.inc.php.

string PKPComponentRouter::$_op

the requested operation

Definition at line 81 of file PKPComponentRouter.inc.php.

callable PKPComponentRouter::$_rpcServiceEndpoint = false

the rpc service endpoint the request was routed to

Definition at line 91 of file PKPComponentRouter.inc.php.

array PKPComponentRouter::$_rpcServiceEndpointParts = false

the rpc service endpoint parts from the request

Definition at line 86 of file PKPComponentRouter.inc.php.


The documentation for this class was generated from the following file: