Controller/Plugin/ExtRequest.php
\Conjoon_Controller_Plugin_ExtRequest
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
Properties

Array
$_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
)'
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
)Details- Type
- Array

Array
$_helperList= 'array()'
array()Details- Type
- Array

Boolean
$_isExtMultiRequest= 'false'
falseDetails- Type
- Boolean

Boolean
$_isExtRequest= 'false'
falseDetails- Type
- Boolean

Array
$_paramsList= 'array()'
array()Details- Type
- Array

Array
$_pluginsList= 'array()'
array()Details- Type
- Array

\Conjoon_Controller_Plugin_ExtRequest_PreDispatcher
$_postDispatcher= 'null'
nullDetails

\Conjoon_Controller_Plugin_ExtRequest_PreDispatcher
$_preDispatcher= 'null'
nullDetails

Boolean
$_processed= 'false'
falseDetails- Type
- Boolean

array
$_requestInfo= 'array()'
array()Details- Type
- array
Methods

__construct(
Array $config
)
:
voidConstructor.
| 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". |

_applyParams(
\Zend_Controller_Request_Abstract $request, $data
)
:
voidRefreshes the parameter list for the specified request.
| Name | Type | Description |
|---|---|---|
| $request | \Zend_Controller_Request_Abstract | |
| $data |

_copyPlugins(
)
:
voidClones all plugins except those plugins registered by this instance one and stores them

_mergeInitException(
\Zend_Controller_Response_Abstract $response
)
:
voidCopies an exception found in the response of the initial request into the responses of teh requests found in the requestStack.
| Name | Type | Description |
|---|---|---|
| $response | \Zend_Controller_Response_Abstract |

_preProcessRequest(
\Zend_Controller_Request_Abstract $request
)
:
BooleanDecides 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.
| Name | Type | Description |
|---|---|---|
| $request | \Zend_Controller_Request_Abstract |
| Type | Description |
|---|---|
| Boolean | true if the request was already processed, otherwise false |

_processRequestStack(
\Zend_Controller_Front $front, \Zend_Controller_Response_Abstract $response
)
:
voidProcesses the requestStack and merges their responses into $response.
| Name | Type | Description |
|---|---|---|
| $front | \Zend_Controller_Front | |
| $response | \Zend_Controller_Response_Abstract |

_resetParams(
$additionalParameters
=
array()
)
:
voidResets 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.
| Name | Type | Description |
|---|---|---|
| $additionalParameters |

getConfigValue(
String $key
)
:
mixedReturns the value for the specified config key, or null if it does not exist.
| Name | Type | Description |
|---|---|---|
| $key | String |
| Type | Description |
|---|---|
| mixed |

getRequestStack(
)
:
ArrayReturns 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.
| Type | Description |
|---|---|
| Array |
| Exception | Description |
|---|---|
| \Zend_Controller_Exception | If trying to access the property when the plugins were not processed yet |

isExtMultiRequest(
)
:
BooleanReturns true if the request was made using the Ext.Direct-API and if more than one request were merged into this one.
| Type | Description |
|---|---|
| Boolean |
| Exception | Description |
|---|---|
| \Zend_Controller_Exception | If trying to access the property when the plugins were not processed yet |

isExtRequest(
)
:
BooleanReturn true if the request was made using the Ext.Direct-API.
| Type | Description |
|---|---|
| Boolean |
| Exception | Description |
|---|---|
| \Zend_Controller_Exception | If trying to access the property when the plugins were not processed yet |

notifyDispatchLoopShutdown(
)
:
voidMethod 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.
- Packageprotected

notifyDispatchLoopStartup(
\Zend_Controller_Request_Abstract $request
)
:
voidMethod gets called when the PreDispatcher's dispatchLoopStartup method gets called.
This method is API only.
| Name | Type | Description |
|---|---|---|
| $request | \Zend_Controller_Request_Abstract |
- Packageprotected