Project

General

Profile

Feature #22060 » 13428_v2.diff

Administrator Admin, 2010-02-05 13:24

View differences:

t3lib/extjs/class.t3lib_extjs_extdirectapi.php (working copy)
*/
class t3lib_extjs_ExtDirectApi {
/**
* Parses the ExtDirect configuration array "$GLOBALS['TYPO3_CONF_VARS']['BE']['ExtDirect']"
* Parses the ExtDirect configuration array "$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ExtDirect']"
* and feeds the given typo3ajax instance with the resulting informations. The get parameter
* "namespace" will be used to filter the configuration.
*
* This method makes usage of the reflection mechanism to fetch the methods inside the
* defined classes together with their amount of parameters. This informations are building
* the API and are required by ExtDirect.
* the API and are required by ExtDirect. The result is cached to improve the overall
* performance.
*
* @param array $ajaxParams ajax parameters
* @param TYPO3AJAX $ajaxObj typo3ajax instance
......
public function getAPI($ajaxParams, TYPO3AJAX $ajaxObj) {
$filterNamespace = t3lib_div::_GET('namespace');
// look up into the cache
$cacheIdentifier = 'ExtDirectApi';
$cacheHash = md5($cacheIdentifier . $filterNamespace);
$cacheContent = t3lib_pageSelect::getHash($cacheHash);
$javascriptNamespaces = unserialize($cacheContent);
// generate the javascript content if it wasn't found inside the cache and cache it!
if ($javascriptNamespaces === false) {
$javascriptNamespaces = $this->generateAPI($filterNamespace);
t3lib_pageSelect::storeHash(
$cacheHash,
serialize($javascriptNamespaces),
$cacheIdentifier
);
}
// return the generated javascript API configuration
if (count($javascriptNamespaces)) {
$setup = '
if (typeof Ext.app.ExtDirectAPI != "object") {
Ext.app.ExtDirectAPI = {};
}
if (typeof Object.extend != "function") {
Object.extend = function(destination, source) {
for (var property in source) {
destination[property] = source[property];
}
return destination;
}
}
';
$ajaxObj->setContent($javascriptNamespaces);
$ajaxObj->setContentFormat('javascript');
$ajaxObj->setJavascriptCallbackWrap(
$setup . 'Ext.app.ExtDirectAPI = Object.extend(Ext.app.ExtDirectAPI, |);'
);
}
}
/**
* Generates the API that is configured inside the ExtDirect configuration
* array "$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ExtDirect']".
*
* @param string $filerNamespace namespace that should be loaded like TYPO3.Backend
* @return array javascript API configuration
*/
protected function generateAPI($filterNamespace) {
$javascriptNamespaces = array();
if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ExtDirect'])) {
foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ExtDirect'] as $javascriptName => $className) {
......
}
}
}
if (count($javascriptNamespaces)) {
$setup = '
if (typeof Ext.app.ExtDirectAPI != "object") {
Ext.app.ExtDirectAPI = {};
}
if (typeof Object.extend != "function") {
Object.extend = function(destination, source) {
for (var property in source) {
destination[property] = source[property];
}
return destination;
}
}
';
$ajaxObj->setContent($javascriptNamespaces);
$ajaxObj->setContentFormat('javascript');
$ajaxObj->setJavascriptCallbackWrap($setup . 'Ext.app.ExtDirectAPI = Object.extend(Ext.app.ExtDirectAPI, |);');
}
return $javascriptNamespaces;
}
}
(3-3/5)