}
}
+ /**
+ * Adds the ExtDirect code
+ *
+ * @return void
+ */
+ public function addExtDirectCode() {
+ // Note: we need to iterate thru the object, because the addProvider method
+ // does this only with multiple arguments
+ $this->addExtOnReadyCode(
+ 'for (var api in Ext.app.ExtDirectAPI) {
+ Ext.Direct.addProvider(Ext.app.ExtDirectAPI[api]);
+ }
+
+ var extDirectDebug = function(message, header, group) {
+ var TYPO3ViewportInstance = null;
+
+ if (top && top.TYPO3 && typeof top.TYPO3.Backend === "object") {
+ TYPO3ViewportInstance = top.TYPO3.Backend;
+ } else if (typeof TYPO3 === "object" && typeof TYPO3.Backend === "object") {
+ TYPO3ViewportInstance = TYPO3.Backend;
+ }
+
+ if (TYPO3ViewportInstance !== null) {
+ TYPO3ViewportInstance.DebugConsole.addTab(message, header, group);
+ } else {
+ document.write(message);
+ }
+ };
+
+ Ext.Direct.on("exception", function(event) {
+ extDirectDebug(
+ "<p>" + event.message + "</p>" +
+ "<p style=\"margin-top: 20px;\">" +
+ "<strong>Backtrace:</strong><br />" +
+ event.where.replace(/#/g, "<br />#") +
+ "</p>",
+ event.method,
+ "ExtDirect - Exception"
+ );
+ });
+
+ Ext.Direct.on("event", function(event, provider) {
+ if (typeof event.debug !== "undefined" && event.debug !== "") {
+ extDirectDebug(event.debug, event.method, "ExtDirect - Debug");
+ }
+ });
+ ',
+ TRUE
+ );
+ }
+
/* CSS Files */
/**
--- /dev/null
+<?php\r
+/***************************************************************\r
+* Copyright notice\r
+*\r
+* (c) 2010 Stefan Galinski <stefan.galinski@gmail.com>\r
+* All rights reserved\r
+*\r
+* This script is part of the TYPO3 project. The TYPO3 project is\r
+* free software; you can redistribute it and/or modify\r
+* it under the terms of the GNU General Public License as published by\r
+* the Free Software Foundation; either version 2 of the License, or\r
+* (at your option) any later version.\r
+*\r
+* The GNU General Public License can be found at\r
+* http://www.gnu.org/copyleft/gpl.html.\r
+* A copy is found in the textfile GPL.txt and important notices to the license\r
+* from the author is found in LICENSE.txt distributed with these scripts.\r
+*\r
+*\r
+* This script is distributed in the hope that it will be useful,\r
+* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+* GNU General Public License for more details.\r
+*\r
+* This copyright notice MUST APPEAR in all copies of the script!\r
+***************************************************************/\r
+\r
+/**\r
+ * Ext Direct Debug\r
+ *\r
+ * @author Stefan Galinski <stefan.galinski@gmail.com>\r
+ * @package TYPO3\r
+ */\r
+final class t3lib_extjs_ExtDirectDebug {\r
+ /**\r
+ * Internal debug message array\r
+ *\r
+ * @var array\r
+ */\r
+ protected static $debugMessages = array();\r
+\r
+ /**\r
+ * Adds a new message of any data type to the internal debug message array.\r
+ *\r
+ * @param mixed $message\r
+ * @return void\r
+ */\r
+ public static function debug($message) {\r
+ self::$debugMessages[] = $message;\r
+ }\r
+\r
+ /**\r
+ * Returns the internal debug messages as a string.\r
+ *\r
+ * @return string\r
+ */\r
+ public static function toString() {\r
+ $messagesAsString = '';\r
+ if (count(self::$debugMessages)) {\r
+ $messagesAsString = t3lib_div::view_array(self::$debugMessages);\r
+ }\r
+\r
+ return $messagesAsString;\r
+ }\r
+}\r
+\r
+?>
\ No newline at end of file
* Copyright notice
*
* (c) 2010 Sebastian Kurfuerst <sebastian@typo3.org>
+* (c) 2010 Stefan Galinski <stefan.galinski@gmail.com>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* @return void
*/
public function route($ajaxParams, TYPO3AJAX $ajaxObj) {
- try {
- $isForm = FALSE;
- $isUpload = FALSE;
- $rawPostData = file_get_contents('php://input');
- $postParameters = t3lib_div::_POST();
- $namespace = t3lib_div::_GET('namespace');
-
- if (!empty($postParameters['extAction'])) {
- $isForm = TRUE;
- $isUpload = $postParameters['extUpload'] === 'true';
-
- $request->action = $postParameters['extAction'];
- $request->method = $postParameters['extMethod'];
- $request->tid = $postParameters['extTID'];
- $request->data = array($_POST + $_FILES);
- } elseif (!empty($rawPostData)) {
- $request = json_decode($rawPostData);
- } else {
- throw new t3lib_error_Exception('ExtDirect: Missing Parameters!');
- }
+ $isForm = FALSE;
+ $isUpload = FALSE;
+ $rawPostData = file_get_contents('php://input');
+ $postParameters = t3lib_div::_POST();
+ $namespace = t3lib_div::_GET('namespace');
+ $response = array();
+ $request = NULL;
+
+ if (!empty($postParameters['extAction'])) {
+ $isForm = TRUE;
+ $isUpload = $postParameters['extUpload'] === 'true';
+
+ $request = new stdClass;
+ $request->action = $postParameters['extAction'];
+ $request->method = $postParameters['extMethod'];
+ $request->tid = $postParameters['extTID'];
+ $request->data = array($_POST + $_FILES);
+ } elseif (!empty($rawPostData)) {
+ $request = json_decode($rawPostData);
+ } else {
+ $response[] = array(
+ 'type' => 'exception',
+ 'message' => 'Something went wrong with an ExtDirect call!'
+ );
+ }
- $response = NULL;
- if (is_array($request)) {
- $response = array();
- foreach ($request as $singleRequest) {
- $response[] = $this->processRpc($singleRequest, $namespace);
- }
- } else {
- $response = $this->processRpc($request, $namespace);
- }
+ if (!is_array($request)) {
+ $request = array($request);
+ }
- if ($isForm && $isUpload) {
- $ajaxObj->setContentFormat('plain');
- $response = json_encode($response);
- $response = preg_replace('/"/', '\\"', $response);
-
- $response = array(
- '<html><body><textarea>' .
- $response .
- '</textarea></body></html>'
- );
- } else {
- $ajaxObj->setContentFormat('jsonbody');
+ foreach ($request as $index => $singleRequest) {
+ $response[$index] = array(
+ 'tid' => $singleRequest->tid,
+ 'action' => $singleRequest->action,
+ 'method' => $singleRequest->method
+ );
+
+ try {
+ $response[$index]['type'] = 'rpc';
+ $response[$index]['result'] = $this->processRpc($singleRequest, $namespace);
+ $response[$index]['debug'] = t3lib_extjs_ExtDirectDebug::toString();
+
+ } catch (Exception $exception) {
+ $response[$index]['type'] = 'exception';
+ $response[$index]['message'] = $exception->getMessage();
+ $response[$index]['where'] = $exception->getTraceAsString();
}
- } catch (t3lib_error_Exception $exception) {
+ }
+
+ if ($isForm && $isUpload) {
+ $ajaxObj->setContentFormat('plain');
+ $response = json_encode($response);
+ $response = preg_replace('/"/', '\\"', $response);
+
$response = array(
- 'type' => 'exception',
- 'message' => $exception->getMessage(),
- 'where' => $exception->getTraceAsString()
+ '<html><body><textarea>' .
+ $response .
+ '</textarea></body></html>'
);
+ } else {
+ $ajaxObj->setContentFormat('jsonbody');
}
$ajaxObj->setContent($response);
*
* @param object $singleRequest request object from extJS
* @param string $namespace namespace like TYPO3.Backend
+ * @throws t3lib_error_exception if the remote method couldn't be found
* @return mixed return value of the called method
*/
protected function processRpc($singleRequest, $namespace) {
- try {
- $endpointName = $namespace . '.' . $singleRequest->action;
+ $endpointName = $namespace . '.' . $singleRequest->action;
// theoretically this can never happen, because of an javascript error on
// the client side due the missing namespace/endpoint
- if (!isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ExtDirect'][$endpointName])) {
- throw new t3lib_error_Exception('ExtDirect: Call to undefined endpoint: ' . $endpointName);
- }
-
- $response = array(
- 'type' => 'rpc',
- 'tid' => $singleRequest->tid,
- 'action' => $singleRequest->action,
- 'method' => $singleRequest->method
- );
-
- $endpointObject = t3lib_div::getUserObj(
- $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ExtDirect'][$endpointName],
- FALSE
- );
-
- $response['result'] = call_user_func_array(
- array($endpointObject, $singleRequest->method),
- is_array($singleRequest->data) ? $singleRequest->data : array()
- );
-
- } catch (t3lib_error_Exception $exception) {
- throw $exception;
+ if (!isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ExtDirect'][$endpointName])) {
+ throw new t3lib_error_Exception('ExtDirect: Call to undefined endpoint: ' . $endpointName);
}
- return $response;
+ $endpointObject = t3lib_div::getUserObj(
+ $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ExtDirect'][$endpointName],
+ FALSE
+ );
+
+ return call_user_func_array(
+ array($endpointObject, $singleRequest->method),
+ is_array($singleRequest->data) ? $singleRequest->data : array()
+ );
}
}