2 /***************************************************************
5 * (c) 2010 Sebastian Kurfuerst <sebastian@typo3.org>
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
29 * Ext Direct API Generator
31 * @author Sebastian Kurfuerst <sebastian@typo3.org>
32 * @author Stefan Galinski <stefan.galinski@gmail.com>
35 class t3lib_ExtJs_ExtDirectAPI
{
37 * Parses the ExtDirect configuration array "$GLOBALS['TYPO3_CONF_VARS']['BE']['ExtDirect']"
38 * and feeds the given typo3ajax instance with the resulting informations. The get parameter
39 * "namespace" will be used to filter the configuration.
41 * This method makes usage of the reflection mechanism to fetch the methods inside the
42 * defined classes together with their amount of parameters. This informations are building
43 * the API and are required by ExtDirect.
45 * @param array $ajaxParams ajax parameters
46 * @param TYPO3AJAX $ajaxObj typo3ajax instance
49 public function getAPI($ajaxParams, TYPO3AJAX
$ajaxObj) {
50 $filterNamespace = t3lib_div
::_GET('namespace');
52 $javascriptNamespaces = array();
53 if (is_array($GLOBALS['TYPO3_CONF_VARS']['BE']['ExtDirect'])) {
54 foreach ($GLOBALS['TYPO3_CONF_VARS']['BE']['ExtDirect'] as $javascriptName => $className) {
55 $splittedJavascriptName = explode('.', $javascriptName);
56 $javascriptObjectName = array_pop($splittedJavascriptName);
57 $javascriptNamespace = implode('.', $splittedJavascriptName);
59 // only items inside the wanted namespace
60 if (strpos($javascriptNamespace, $filterNamespace) !== 0) {
64 if (!isset($javascriptNamespaces[$javascriptNamespace])) {
65 $javascriptNamespaces[$javascriptNamespace] = array(
66 'url' => 'ajax.php?ajaxID=ExtDirect::route&namespace=' . rawurlencode($javascriptNamespace),
69 'namespace' => $javascriptNamespace
73 $serverObject = t3lib_div
::getUserObj($className, FALSE);
74 $javascriptNamespaces[$javascriptNamespace]['actions'][$javascriptObjectName] = array();
75 foreach (get_class_methods($serverObject) as $methodName) {
76 $reflectionMethod = new ReflectionMethod($serverObject, $methodName);
77 $numberOfParameters = $reflectionMethod->getNumberOfParameters();
79 $javascriptNamespaces[$javascriptNamespace]['actions'][$javascriptObjectName][] = array(
80 'name' => $methodName,
81 'len' => $numberOfParameters
87 if (count($javascriptNamespaces)) {
89 if (typeof Ext.app.ExtDirectAPI != "object") {
90 Ext.app.ExtDirectAPI = {};
94 $ajaxObj->setContent($javascriptNamespaces);
95 $ajaxObj->setContentFormat('javascript');
96 $ajaxObj->setJavascriptCallbackWrap($setup . 'Ext.app.ExtDirectAPI = Object.extend(Ext.app.ExtDirectAPI, |);');
101 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['t3lib/class.t3lib_extjs_extdirectapi.php']) {
102 include_once($TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['t3lib/class.t3lib_extjs_extdirectapi.php']);