Controller/Plugin/ExtRequest.php

Show: inherited
Table of Contents

\Conjoon_Controller_Plugin_ExtRequest

Package: Conjoon\Controller\Plugin

This is not directly a plugin, but more of a mediator between two plugins: The Conjoon_Controller_Plugin_ExtRequest_PreDispatcher and Conjoon_Controller_Plugin_ExtRequest_PostDispatcher.

Those two plugins combined are capable of recognizing whether a request to the server was made using the Ext.Direct-API. In some cases, the Ext.Direct-API might merge a number of requests into a single one: The plugins splits one request into multiple requests if it detects that Ext did collect data to send in one request, whereas each dataIndex denotes an individual action to process, just as if this data was sent in a single request.

Before the dispatch loop gets invoked, the Conjoon_Controller_Plugin_ExtRequest_PreDispatcher checks if there is a specific parameter available, then JSON-decodes it (as it assumes it's json encoded data) and tests if the array is a numeric array - if that is the case, each array index will be searched for the action and method values and based on this several requests (Zend_Controller_Request_Http) which will be moved onto a stack. This stack will be processed later on by the Conjoon_Controller_Plugin_ExtRequest_PostDispatcher which resets the Front-Controller to it's state when the original request has been made in a loop that processes those requests. The individual responses will then be merged again and send back to the client.

Example:

The application wants to read out feed accounts, check if a feed address is valid, and read out feed items afterwards. All of those actions are merged by Ext. The Ext.Direct Provider API looks like this:

{ url : '/groupware', // the module actions : { feeds : [{ // controller name : 'getFeedAccounts' // action }, { name : 'isFeedAddressValid' }, { name : 'getFeedItems' }] } namespace : 'com.conjoon.groupware.remote' }

Client side calls then:

com.conjoon.groupware.remote.feeds.getFeedAccounts(); com.conjoon.groupware.remote.feeds.isFeedAddressValid(); com.conjoon.groupware.remote.feeds.getFeedItems();

Ext does now merge those requests into one. The url called is

'/groupware'. The value of the specific Ext.Direct parameter looks like this: [ {"action":"feeds","method":"getFeedAccounts","data":[],"type":"rpc","tid":2}, {"action":"feeds","method":"isFeedAddressValid","data":[],"type":"rpc","tid":3}, {"action":"feeds","method":"getFeedItems","data":[],"type":"rpc","tid":4} ]

Conjoon_Controller_Plugin_ExtRequest_PreDispatcher inspects the post data. It finds a numeric array and assumes that multiple requests were merged into one. Requests-Objects will be created, moved onto the stack and processed by the postDispatcher later on. Additionally, if the data-value is numeric, the param "data" for each request will be added as a parameter. If the data value is associative, the properties with their values will be added as parameters. The original data will be stored decoded under the name of the specified Ext.Direct Post parameter. On the other hand, if the specified Ext.Direct post parameter was found, but does not hold a numeric array, the PreDispatcher assumes it deals with a single request made by the Ext.Direct-API. Data will be decoded and stored as described above. The PostDispatcher will not take action then.

Please note, that using multiple requests merged into one is expensive, since copies of all plugins and helpers found initially are stored and exchanged between plugins and helpers. The front controller's "dispatch()" method will be called as many times as requests are available on the stack.

When using those plugins, you have to make sure that the PreDispatcher is the VERY FIRST plugin that gets processed, and the PostDispatcher is the VERY LAST plugin that gets processed. This mediator will help by defining default stack indexes. If you provide your own stack indexes, make sure that no other plugin gets a lower stack index than the PreDispatcher, and no higher index than the PostDispatcher.

Note: 1) Before the request stack gets processed, the request that holds the merged ones gets processed as usual, with the only difference that its response body gets later on completely overwritten with the merged responses from the processed requests. 2) For the initial request, you have to specify a module, a controller and an action that should be called.

Author
Thorsten Suckow-Homberg  
Category
Plugins  

Constants

Constant  LOW_INDEX = -99999999

Const
Integer LOW_INDEX The default index for the PreDispatcher  
Constant  HIGH_INDEX = 99999999

Const
Integer LOW_INDEX The default index for the PostDispatcher  
Constant  INDEX_KEY = '__ExtDirectRequestRouter_processIndex__'

Const
String INDEX_KEY The default param name for the index of a splitted request in the request stack  

Properties

PropertyprotectedArray  $_config= 'array( 'extParameter' => 'extDirectData', 'additionalParams' => array(), 'lowIndex' => self::LOW_INDEX, 'highIndex' => self::HIGH_INDEX, 'action' => null, 'controller' => null, 'module' => null, 'indexKey' => self::INDEX_KEY, 'additionalHeaders' => array(), 'singleException' => false )'

_config
Default valuearray( 'extParameter' => 'extDirectData', 'additionalParams' => array(), 'lowIndex' => self::LOW_INDEX, 'highIndex' => self::HIGH_INDEX, 'action' => null, 'controller' => null, 'module' => null, 'indexKey' => self::INDEX_KEY, 'additionalHeaders' => array(), 'singleException' => false )Details
Type
Array
PropertyprotectedArray  $_helperList= 'array()'

Stores a copy of the original helper that where found in the HelperBroker with which the PreDispatcher was called.
Default valuearray()Details
Type
Array
PropertyprotectedBoolean  $_isExtMultiRequest= 'false'

Gets set to true if the plugins detect a merged request that was sent by the Ext.Direct API. Note, that this property gets in fact only set to true if the request was merged. For checking whether the request was made using the Ext.Direct-API, see $_isExtRequest
Default valuefalseDetails
Type
Boolean
PropertyprotectedBoolean  $_isExtRequest= 'false'

Gets set to true if the plugins detect a request that was sent by the Ext.Direct API.
Default valuefalseDetails
Type
Boolean
PropertyprotectedArray  $_paramsList= 'array()'

Stores a copy of the original params of the front controller with which the PreDispatcher was called.
Default valuearray()Details
Type
Array
PropertyprotectedArray  $_pluginsList= 'array()'

Stores a copy of the original plugins that where found in the front's plugins broker with which the PreDispatcher was called, except the PreDispatcher and the PostDispatcher
Default valuearray()Details
Type
Array
Propertyprotected\Conjoon_Controller_Plugin_ExtRequest_PreDispatcher  $_postDispatcher= 'null'

Propertyprotected\Conjoon_Controller_Plugin_ExtRequest_PreDispatcher  $_preDispatcher= 'null'

PropertyprotectedBoolean  $_processed= 'false'

Whether the dispatchLoopStartup has been called at least once for the PreDispatcher.
Default valuefalseDetails
Type
Boolean
Propertyprotectedarray  $_requestInfo= 'array()'

A stack of additional informations for processing a request when in the dispatchLoopStartup method.
Default valuearray()Details
Type
array
Propertyprotectedarray  $_requestStack= 'array()'

A stack of requests that were created from merged requests.
Default valuearray()Details
Type
array

Methods

methodpublic__construct( Array $config ) : void

Constructor.

Parameters
Name Type Description
$config Array

The configuration for an instance of this class. Possible key/value/pairs are: String extParameter The post parameter name which holds data submitted by an Ext.Direct-request. Defaults to extDirectData Array additionalParams A set of additional params that get added to each requests params list. Defaults to an empty array. Params in thes list get added before automatic parameter handling for the Ext.Direct-data is invoked Integer lowIndex The stack index for the PreDispatcher to make sure it gets called as the very first plugin. Defaults to LOW_INDEX Integer highIndex The stack index for the PostDispatcher to make sure it gets called as the very last plugin. Defaults to HIGH_INDEX String action The action to call for the original request. Defaults to null, which means the url of the original request will be routed as usual String controller The controller where action can be found. Defaults to null, which means the url of the original request will be routed as usual String module The module where controller can be found. Defaults to null, which means the url of the original request will be routed as usual Integer indexKey If the passed request to either of the plugins is a splitted request, this holds the index of the request in the request stack. Defaults to INDEX_KEY Array additionalHeaders a list of additional headers to set for the response Boolean singleException whether an exception that happens during the initial request should becopied and returned for all tids. If set to "false", copies the exception, otherwise returns the exception without specifying further tids. Defaults to "false".

methodprotected_applyParams( \Zend_Controller_Request_Abstract $request,  $data ) : void

Refreshes the parameter list for the specified request.

Parameters
Name Type Description
$request \Zend_Controller_Request_Abstract
$data
methodprotected_copyHelper( ) : void

Clones all helpers as found in the HelperBroker and stores them.

methodprotected_copyParams( ) : void

Clones all initial params set for the front controller and stores them.

methodprotected_copyPlugins( ) : void

Clones all plugins except those plugins registered by this instance one and stores them

methodprotected_mergeInitException( \Zend_Controller_Response_Abstract $response ) : void

Copies an exception found in the response of the initial request into the responses of teh requests found in the requestStack.

Parameters
Name Type Description
$response \Zend_Controller_Response_Abstract
methodprotected_preProcessRequest( \Zend_Controller_Request_Abstract $request ) : Boolean

Decides whether to process the request or not. Requests get processed if either their indexKey param is not set or if the requestInfo for this request was not already processed.

If the requestInfo is still available, the method will invoke the appropriate actions and then mark this request as processed.

Parameters
Name Type Description
$request \Zend_Controller_Request_Abstract
Returns
Type Description
Boolean true if the request was already processed, otherwise false
methodprotected_processRequestStack( \Zend_Controller_Front $front, \Zend_Controller_Response_Abstract $response ) : void

Processes the requestStack and merges their responses into $response.

Parameters
Name Type Description
$front \Zend_Controller_Front
$response \Zend_Controller_Response_Abstract
methodprotected_resetHelper( ) : void

Resets all helpers to the helpers found in $_helperList.

methodprotected_resetParams(  $additionalParameters = array() ) : void

Resets the parameters for the front controller to the params found in $_paramsList.

If the optional array is specified, copies those values into the param list, too.

Parameters
Name Type Description
$additionalParameters
methodprotected_resetPlugins( ) : void

Resets all plugins to the plugins found in $_pluginsList.

methodpublicgetConfigValue( String $key ) : mixed

Returns the value for the specified config key, or null if it does not exist.

Parameters
Name Type Description
$key String
Returns
Type Description
mixed
methodpublicgetRequestStack( ) : Array

Returns the current configured request stack for this instance.

Note, that depending on when you call this method, not all configured request may be available in the request stack anymore.

Returns
Type Description
Array
Throws
Exception Description
\Zend_Controller_Exception If trying to access the property when the plugins were not processed yet
methodpublicisExtMultiRequest( ) : Boolean

Returns true if the request was made using the Ext.Direct-API and if more than one request were merged into this one.

Returns
Type Description
Boolean
Throws
Exception Description
\Zend_Controller_Exception If trying to access the property when the plugins were not processed yet
methodpublicisExtRequest( ) : Boolean

Return true if the request was made using the Ext.Direct-API.

Returns
Type Description
Boolean
Throws
Exception Description
\Zend_Controller_Exception If trying to access the property when the plugins were not processed yet
methodpublicnotifyDispatchLoopShutdown( ) : void

Method gets called when the PostDispatcher's dispatchLoopShutdown method gets called.

This method is API only. Note, that this method only gets processed for the initial request that has been made, not for requests found on the requestStack.

Details
Packageprotected
 
methodpublicnotifyDispatchLoopStartup( \Zend_Controller_Request_Abstract $request ) : void

Method gets called when the PreDispatcher's dispatchLoopStartup method gets called.

This method is API only.

Parameters
Name Type Description
$request \Zend_Controller_Request_Abstract
Details
Packageprotected
 
methodpublicregisterPlugins( ) : void

Registers the PreDispatcher and PostDispatcher to the front's plugins list.

Throws
Exception Description
\Zend_Controller_Exception if the plugins are already registered.
Documentation was generated by DocBlox 0.18.1.