diff --git a/dev/ajax.bar.php b/dev/ajax.bar.php new file mode 100644 index 000000000..b3884f850 --- /dev/null +++ b/dev/ajax.bar.php @@ -0,0 +1,52 @@ + $this->id); + $json = htmlSpecialChars(json_encode($parameters), ENT_QUOTES); + $id = htmlSpecialChars($this->id); + + ob_start(); + include __DIR__ . '/ajax.bar.phtml'; + return ob_get_clean(); + } + + + public function handleAsyncCall($parameters) + { + return '' . microtime(TRUE) . '' + . '
' . var_export($parameters, TRUE) . ''; + } + + + public function setHandlerId($id) + { + $this->id = $id; + } + +} + +Tracy\Debugger::enable(); + +Tracy\Debugger::getBar()->addPanel($panel = new Panel); +Tracy\Debugger::addAsyncHandler($panel); + +Tracy\Debugger::getBar()->addPanel($panel = new Panel); +Tracy\Debugger::addAsyncHandler($panel); + +Tracy\Debugger::getBar()->addPanel($panel = new Panel); +Tracy\Debugger::addAsyncHandler($panel); diff --git a/dev/ajax.bar.phtml b/dev/ajax.bar.phtml new file mode 100644 index 000000000..cdfc7d5ca --- /dev/null +++ b/dev/ajax.bar.phtml @@ -0,0 +1,40 @@ + + +

AJAX Panel

+
+ Refresh
+
(payload)
+
diff --git a/src/Tracy/Debugger.php b/src/Tracy/Debugger.php index 15498889b..101d2e423 100644 --- a/src/Tracy/Debugger.php +++ b/src/Tracy/Debugger.php @@ -98,6 +98,11 @@ class Debugger /** @var ILogger */ private static $fireLogger; + /********************* asynchronous calls ************/ + + /** @var IAsyncHandler[] */ + private static $asyncHandlers = array(); + /** * Static class - cannot be instantiated. @@ -403,6 +408,44 @@ public static function getFireLogger() } + /** + * @param IAsyncHandler + * @param string + */ + public static function addAsyncHandler(IAsyncHandler $handler, $id = NULL) + { + if ($id === NULL) { + $c = 0; + do { + $id = get_class($handler) . ($c++ ? "-$c" : ''); + } while (isset(self::$asyncHandlers[$id])); + } + + if (self::$enabled && !self::$productionMode && isset($_SERVER['HTTP_X_TRACY_ASYNC']) && $_SERVER['HTTP_X_TRACY_ASYNC'] === "$id") { + try { + set_error_handler(function($severity, $message, $file, $line){ + restore_error_handler(); + throw new \ErrorException($message, 0, $severity, $file, $line); + }); + $result = json_encode($handler->handleAsyncCall(json_decode($_SERVER['HTTP_X_TRACY_ASYNC_PARAMETERS'], TRUE))); + restore_error_handler(); + + header('Content-Type: application/json; charset=utf-8'); + echo $result; + + } catch (\Exception $e) { + header('HTTP/1.1 500 Internal Server Error'); + header('Content-Type: text/plain; charset=utf-8'); + echo $e->getMessage() . ' in ' . $e->getFile() . ':' . $e->getLine(); + } + die(); + } + + self::$asyncHandlers["$id"] = $handler; + $handler->setHandlerId($id); + } + + /********************* useful tools ****************d*g**/ diff --git a/src/Tracy/IAsyncHandler.php b/src/Tracy/IAsyncHandler.php new file mode 100644 index 000000000..4cbbd97ba --- /dev/null +++ b/src/Tracy/IAsyncHandler.php @@ -0,0 +1,34 @@ +