From c592b8f2323cdbb8b9e82833a16de9465ba69918 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Sun, 28 Aug 2022 20:14:19 +0200 Subject: [PATCH] DEBUG fix uncollected callbacks by analysing stack trace --- src/JsReload.php | 4 ++-- src/View.php | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/JsReload.php b/src/JsReload.php index 2125a32877..0d19ede659 100644 --- a/src/JsReload.php +++ b/src/JsReload.php @@ -56,7 +56,7 @@ public function dumpRenderTree(View $view, bool $rec = false): void public function jsRender(): string { - ini_set('output_buffering', (string) (1024 * 1024)); + /*ini_set('output_buffering', (string) (1024 * 1024)); ob_start(); $this->dumpRenderTree($this->view); // test URL: /demos/interactive/modal.php?__atk_m=atk_layout_maestro_modal_5&__atk_cbtarget=atk_layout_maestro_modal_5_view_callbacklater&__atk_cb_atk_layout_maestro_modal_5_view_callbacklater=ajax&__atk_json=1 @@ -66,7 +66,7 @@ public function jsRender(): string echo 'expected: string(166) "modal.php?__atk_m=atk_layout_maestro_modal_5&__atk_cb_atk_layout_maestro_modal_5_view_callbacklater=ajax&__atk_reload=atk_layout_maestro_modal_5_view_demos_viewtester"' . "\n"; ob_end_flush(); - exit; + exit;*/ $final = (new Jquery($this->view)) ->atkReloadView( diff --git a/src/View.php b/src/View.php index 4b795e4024..f5c6931381 100644 --- a/src/View.php +++ b/src/View.php @@ -544,6 +544,40 @@ protected function getRunningCallbackArgs(bool $isTerminated, array $page): arra $parentRenderView = $this->getOwner(); } // else + if (($this instanceof Modal || $this instanceof Panel\Content/* || $this instanceof Panel\Right no direct callback, must use something like mergeStickyArgsFromChildView */) && $this->cb !== null && $this->cb->isTriggered() && $this->cb->canTrigger()) { // hack for modals placed outside the render tree with possible callbacks + $isTerminated = true; // fake terminated detection to support https://github.com/atk4/ui/blob/8014b6c1cb5beb103f337af8ace5ac350f73ce19/src/JsReload.php#L58 URL built not thru callback + + $stacktrace = debug_backtrace(\DEBUG_BACKTRACE_PROVIDE_OBJECT | \DEBUG_BACKTRACE_IGNORE_ARGS); + foreach (array_slice($stacktrace, 1, null, true) as $k => $stackframe) { + if (($stackframe['object'] ?? null) instanceof self && ($stackframe['object'] ?? null) !== $this) { + $parentRenderView = $stackframe['object']; + foreach (array_slice($stacktrace, $k + 1) as $stackframe2) { + if (($stackframe2['object'] ?? null) === $parentRenderView && $stackframe2['function'] === 'getRunningCallbackArgs') { + $parentRenderView = null; // already called + } + } + + break; + } elseif (($stackframe['object'] ?? null) instanceof App && ($stackframe['function'] ?? null) === 'run') { + break; + } + } + + if ($parentRenderView !== null) { + $a = [ + array_map(function ($v) { + $v['class'] = isset($v['object']) ? get_class($v['object']) : 'x'; + unset($v['object']); + + return $v; + }, $stacktrace), + $parentRenderView !== null ? $parentRenderView->getRunningCallbackArgs($isTerminated, $page) : '-----', + $page, + ]; + // print_r($a); + } + } + if ($parentRenderView !== null) { $args = array_merge($parentRenderView->getRunningCallbackArgs($isTerminated, $page), $args); }