Open Journal Systems  2.4.4
 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)
 
 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)
 
 route (&$request)
 
 setApplication (&$application)
 
 setDispatcher (&$dispatcher)
 
 supports (&$request)
 
 url (&$request, $newContext=null, $handler=null, $op=null, $path=null, $params=null, $anchor=null, $escape=false)
 

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 373 of file PKPComponentRouter.inc.php.

References _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.

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 406 of file PKPComponentRouter.inc.php.

References PKPRouter\getApplication().

Referenced by _getValidatedServiceEndpointParts().

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 457 of file PKPComponentRouter.inc.php.

References String\regexp_match().

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.

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

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

References _getValidatedServiceEndpointParts(), and String\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.

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

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

References _getValidatedServiceEndpointParts(), and String\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.

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 167 of file PKPComponentRouter.inc.php.

References getRequestedComponent(), and getRequestedOp().

Referenced by route(), and supports().

PKPComponentRouter::handleAuthorizationFailure (   $request,
  $authorizationMessage 
)
PKPComponentRouter::route ( $request)
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 87 of file PKPComponentRouter.inc.php.

References getRpcServiceEndpoint().

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

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