Index: t3lib/extjs/class.t3lib_extjs_extdirectapi.php =================================================================== --- t3lib/extjs/class.t3lib_extjs_extdirectapi.php (Revision 6917) +++ t3lib/extjs/class.t3lib_extjs_extdirectapi.php (Arbeitskopie) @@ -34,13 +34,14 @@ */ class t3lib_extjs_ExtDirectApi { /** - * Parses the ExtDirect configuration array "$GLOBALS['TYPO3_CONF_VARS']['BE']['ExtDirect']" - * and feeds the given typo3ajax instance with the resulting informations. The get parameter + * Parses the ExtDirect configuration array "$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ExtDirect']" + * and feeds the given typo3ajax instance with the resulting information. 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. + * defined classes together with their amount of parameters. This information are building + * 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 @@ -49,6 +50,56 @@ 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); + + // generate the javascript content if it wasn't found inside the cache and cache it! + if (!$cacheContent) { + $javascriptNamespaces = $this->generateAPI($filterNamespace); + t3lib_pageSelect::storeHash( + $cacheHash, + serialize($javascriptNamespaces), + $cacheIdentifier + ); + } else { + $javascriptNamespaces = unserialize($cacheContent); + } + + // 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) { @@ -84,27 +135,7 @@ } } - 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; } }