From 20f5f44c629cd1604a3c3e2cf98ea1c03fd3e9cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Thu, 19 Aug 2021 14:57:45 +0200 Subject: [PATCH] DEBUG fix uncollected callbacks by analysing stack trace --- src/JsReload.php | 4 ++-- src/View.php | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/JsReload.php b/src/JsReload.php index ded0835968..cda0ffc640 100644 --- a/src/JsReload.php +++ b/src/JsReload.php @@ -62,7 +62,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 @@ -70,7 +70,7 @@ public function jsRender(): string echo 'actual: '; var_dump($url); 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 e66bcf4f1d..c422487cc9 100644 --- a/src/View.php +++ b/src/View.php @@ -637,6 +637,35 @@ 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); }