From e6bddb592bf1db8350b16aebc86169f67774fdad Mon Sep 17 00:00:00 2001 From: Alain Belair Date: Tue, 6 Jul 2021 11:51:11 -0400 Subject: [PATCH 01/25] init --- demos/interactive/tabs.php | 2 +- src/AbstractView.php | 20 -------------------- src/App.php | 22 +++++++++++++++++----- src/Callback.php | 14 ++++---------- src/Loader.php | 5 ----- src/Modal.php | 14 ++++++-------- src/Panel/Content.php | 5 ----- src/Panel/Right.php | 5 ----- src/Popup.php | 5 ----- src/UserAction/ExecutorFactory.php | 14 +------------- src/VirtualPage.php | 5 ----- src/Wizard.php | 5 ----- 12 files changed, 29 insertions(+), 87 deletions(-) diff --git a/demos/interactive/tabs.php b/demos/interactive/tabs.php index fd0271e3df..97969e158e 100644 --- a/demos/interactive/tabs.php +++ b/demos/interactive/tabs.php @@ -44,7 +44,7 @@ $modelRegister->addField('name', ['caption' => 'Please enter your name (John)']); $form = \Atk4\Ui\Form::addTo($tab, ['segment' => true]); - $form->setModel($modelRegister); + $form->setModel($modelRegister->createEntity()); $form->onSubmit(function (\Atk4\Ui\Form $form) { if ($form->model->get('name') !== 'John') { return $form->error('name', 'Your name is not John! It is "' . $form->model->get('name') . '". It should be John. Pleeease!'); diff --git a/src/AbstractView.php b/src/AbstractView.php index 769a4334c3..e86437daca 100644 --- a/src/AbstractView.php +++ b/src/AbstractView.php @@ -166,29 +166,9 @@ protected function _getStickyArgs(): array $stickyArgs = $this->stickyArgs; } - /** @var self $childView */ - $childView = $this->mergeStickyArgsFromChildView(); - if ($childView !== null && (!($childView instanceof Callback) || $childView->isTriggered())) { - $alreadyCalled = false; - foreach (debug_backtrace(\DEBUG_BACKTRACE_PROVIDE_OBJECT | \DEBUG_BACKTRACE_IGNORE_ARGS) as $frame) { - if ($childView === ($frame['object'] ?? null) && $frame['function'] === '_getStickyArgs') { - $alreadyCalled = true; - } - } - - if (!$alreadyCalled) { - $stickyArgs = array_merge($stickyArgs, $childView->_getStickyArgs()); - } - } - return $stickyArgs; } - protected function mergeStickyArgsFromChildView(): ?self - { - return null; - } - /** * Mark GET argument as sticky. Calling url() on this view or any * sub-views will embedd the value of this GET argument. diff --git a/src/App.php b/src/App.php index bda92900c6..2d72feff7b 100644 --- a/src/App.php +++ b/src/App.php @@ -124,6 +124,9 @@ class App 'cache-control' => 'no-store', // disable caching by default ]; + /** @var Modal[] Modal view that need to be rendered using json output. */ + private $modals = []; + /** * @var bool whether or not semantic-ui vue has been initialised */ @@ -222,6 +225,17 @@ static function (int $severity, string $msg, string $file, int $line): bool { $this->executorFactory = Factory::factory([ExecutorFactory::class]); } + /** + * Register a modal view. + * Fomantic-ui Modal are teleported in HTML template + * within specific location. This will keep track + * of modals when terminating app using json. + */ + public function registerModal(Modal $modal): void + { + $this->modals[$modal->short_name] = $modal; + } + public function setExecutorFactory(ExecutorFactory $factory) { $this->executorFactory = $factory; @@ -1132,11 +1146,9 @@ public function getRenderedModals(): array unset($_GET['__atk_reload']); $modals = []; - foreach ($this->html !== null ? $this->html->elements : [] as $view) { - if ($view instanceof Modal) { - $modals[$view->name]['html'] = $view->getHtml(); - $modals[$view->name]['js'] = $view->getJsRenderActions(); - } + foreach ($this->modals as $view) { + $modals[$view->name]['html'] = $view->getHtml(); + $modals[$view->name]['js'] = $view->getJsRenderActions(); } return $modals; diff --git a/src/Callback.php b/src/Callback.php index 9984b5efc8..4656ce72e5 100644 --- a/src/Callback.php +++ b/src/Callback.php @@ -43,6 +43,8 @@ protected function init(): void public function setUrlTrigger(string $trigger = null) { $this->urlTrigger = $trigger ?: $this->name; + + $this->getOwner()->stickyGet($this->urlTrigger); } public function getUrlTrigger(): string @@ -120,7 +122,7 @@ public function canTrigger(): bool */ public function getJsUrl(string $value = 'ajax'): string { - return $this->jsUrl($this->getUrlArguments($value)); + return $this->getOwner()->jsUrl($this->getUrlArguments($value)); } /** @@ -129,7 +131,7 @@ public function getJsUrl(string $value = 'ajax'): string */ public function getUrl(string $value = 'callback'): string { - return $this->url($this->getUrlArguments($value)); + return $this->getOwner()->url($this->getUrlArguments($value)); } /** @@ -139,12 +141,4 @@ private function getUrlArguments(string $value = null): array { return ['__atk_callback' => $this->urlTrigger, $this->urlTrigger => $value ?? $this->getTriggeredValue()]; } - - protected function _getStickyArgs(): array - { - // DEV NOTE: - // - getUrlArguments $value used only in https://github.com/atk4/ui/blob/08644a685a9ee07b4e94d1e35e3bd3c95b7a013d/src/VirtualPage.php#L134 - // - $_GET['__atk_callback'] from getUrlArguments seems to control terminating behaviour! - return array_merge(parent::_getStickyArgs(), $this->getUrlArguments() /* TODO we do not want/need all Callback args probably*/); - } } diff --git a/src/Loader.php b/src/Loader.php index 152ca92677..d8a2b00565 100644 --- a/src/Loader.php +++ b/src/Loader.php @@ -116,9 +116,4 @@ public function jsLoad($args = [], $apiConfig = [], $storeName = null) 'storeName' => $storeName ? $storeName : null, ]); } - - protected function mergeStickyArgsFromChildView(): AbstractView - { - return $this->cb; - } } diff --git a/src/Modal.php b/src/Modal.php index fc3437a32e..74d45790e6 100644 --- a/src/Modal.php +++ b/src/Modal.php @@ -59,6 +59,12 @@ class Modal extends View */ public $showActions = false; + protected function init(): void + { + parent::init(); + $this->getApp()->registerModal($this); + } + /** * Set callback function for this modal. * $fx is set as an array in order to comply with View::set(). @@ -330,12 +336,4 @@ protected function renderView(): void parent::renderView(); } - - /** @var AbstractView */ - public $viewForUrl; - - protected function mergeStickyArgsFromChildView(): ?AbstractView - { - return $this->viewForUrl ?? $this->cb; - } } diff --git a/src/Panel/Content.php b/src/Panel/Content.php index 6692fde844..ab28c63405 100644 --- a/src/Panel/Content.php +++ b/src/Panel/Content.php @@ -57,9 +57,4 @@ public function getClearSelector(): array { return ['.atk-panel-content']; } - - protected function mergeStickyArgsFromChildView(): ?\Atk4\Ui\AbstractView - { - return $this->cb; - } } diff --git a/src/Panel/Right.php b/src/Panel/Right.php index 4ca686f256..1d511f792f 100644 --- a/src/Panel/Right.php +++ b/src/Panel/Right.php @@ -202,9 +202,4 @@ protected function renderView(): void $this->js(true, $this->service()->addPanel($this->getPanelOptions())); } - - protected function mergeStickyArgsFromChildView(): ?\Atk4\Ui\AbstractView - { - return $this->dynamicContent; - } } diff --git a/src/Popup.php b/src/Popup.php index 8325e8f3bf..718cf584ef 100644 --- a/src/Popup.php +++ b/src/Popup.php @@ -295,9 +295,4 @@ protected function renderView(): void parent::renderView(); } - - protected function mergeStickyArgsFromChildView(): ?AbstractView - { - return $this->cb; - } } diff --git a/src/UserAction/ExecutorFactory.php b/src/UserAction/ExecutorFactory.php index 8e8a597514..0e05a02caa 100644 --- a/src/UserAction/ExecutorFactory.php +++ b/src/UserAction/ExecutorFactory.php @@ -172,19 +172,7 @@ protected function createExecutor(UserAction $action, View $owner, string $requi } } - $executor = Factory::factory($seed); - if ($executor instanceof Modal) { - // add modal to app->html for proper rendering on callback. - if (!isset($owner->getApp()->html->elements[$executor->short_name])) { - // very dirty hack, @TODO, attach modals in the standard render tree - // but only render the result to a different place/html DOM - $executor->viewForUrl = $owner; - $executor = $owner->getApp()->html->add($executor, 'Modals'); //->setAction($action); - } - } else { - $executor = $owner->add($executor); - } - + $executor = $owner->add(Factory::factory($seed)); $executor->setAction($action); return $executor; diff --git a/src/VirtualPage.php b/src/VirtualPage.php index c95c952d41..c111b964dd 100644 --- a/src/VirtualPage.php +++ b/src/VirtualPage.php @@ -150,9 +150,4 @@ public function getHtml() $this->getApp()->terminateHtml($this->getApp()->html->template); } } - - protected function mergeStickyArgsFromChildView(): AbstractView - { - return $this->cb; - } } diff --git a/src/Wizard.php b/src/Wizard.php index 825cfe0079..530ea67688 100644 --- a/src/Wizard.php +++ b/src/Wizard.php @@ -216,9 +216,4 @@ protected function renderView(): void parent::renderView(); } - - protected function mergeStickyArgsFromChildView(): AbstractView - { - return $this->stepCallback; - } } From b8f73728afe5b8ac0cabef71addf3094c15c8eaf Mon Sep 17 00:00:00 2001 From: Alain Belair Date: Tue, 6 Jul 2021 11:56:28 -0400 Subject: [PATCH 02/25] move url method to View class --- src/AbstractView.php | 67 -------------------------------------------- src/View.php | 65 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 67 deletions(-) diff --git a/src/AbstractView.php b/src/AbstractView.php index e86437daca..41dbd4b8aa 100644 --- a/src/AbstractView.php +++ b/src/AbstractView.php @@ -119,71 +119,4 @@ public function add($object, $args = null): self return $object; } - - // }}} - - // {{{ Sticky URLs - - /** @var string[] stickyGet arguments */ - public $stickyArgs = []; - - /** - * Build an URL which this view can use for js call-backs. It should - * be guaranteed that requesting returned URL would at some point call - * $this->invokeInit(). - * - * @param array $page - * - * @return string - */ - public function jsUrl($page = []) - { - return $this->getApp()->jsUrl($page, false, $this->_getStickyArgs()); - } - - /** - * Build an URL which this view can use for call-backs. It should - * be guaranteed that requesting returned URL would at some point call - * $this->invokeInit(). - * - * @param string|array $page URL as string or array with page name as first element and other GET arguments - * - * @return string - */ - public function url($page = []) - { - return $this->getApp()->url($page, false, $this->_getStickyArgs()); - } - - /** - * Get sticky arguments defined by the view and parents (including API). - */ - protected function _getStickyArgs(): array - { - if ($this->issetOwner() && $this->getOwner() instanceof self) { - $stickyArgs = array_merge($this->getOwner()->_getStickyArgs(), $this->stickyArgs); - } else { - $stickyArgs = $this->stickyArgs; - } - - return $stickyArgs; - } - - /** - * Mark GET argument as sticky. Calling url() on this view or any - * sub-views will embedd the value of this GET argument. - * - * If GET argument is empty or false, it won't make into URL. - * - * If GET argument is not presently set you can specify a 2nd argument - * to forge-set the GET argument for current view and it's sub-views. - */ - public function stickyGet(string $name, string $newValue = null): ?string - { - $this->stickyArgs[$name] = $newValue ?? $_GET[$name] ?? null; - - return $this->stickyArgs[$name]; - } - - // }}} } diff --git a/src/View.php b/src/View.php index bde56a4a3d..5819e4d7c9 100644 --- a/src/View.php +++ b/src/View.php @@ -584,6 +584,71 @@ public function removeAttr($property) // }}} + // {{{ Sticky URLs + + /** @var string[] stickyGet arguments */ + public $stickyArgs = []; + + /** + * Build an URL which this view can use for js call-backs. It should + * be guaranteed that requesting returned URL would at some point call + * $this->invokeInit(). + * + * @param array $page + * + * @return string + */ + public function jsUrl($page = []) + { + return $this->getApp()->jsUrl($page, false, $this->_getStickyArgs()); + } + + /** + * Build an URL which this view can use for call-backs. It should + * be guaranteed that requesting returned URL would at some point call + * $this->invokeInit(). + * + * @param string|array $page URL as string or array with page name as first element and other GET arguments + * + * @return string + */ + public function url($page = []) + { + return $this->getApp()->url($page, false, $this->_getStickyArgs()); + } + + /** + * Get sticky arguments defined by the view and parents (including API). + */ + protected function _getStickyArgs(): array + { + if ($this->issetOwner() && $this->getOwner() instanceof self) { + $stickyArgs = array_merge($this->getOwner()->_getStickyArgs(), $this->stickyArgs); + } else { + $stickyArgs = $this->stickyArgs; + } + + return $stickyArgs; + } + + /** + * Mark GET argument as sticky. Calling url() on this view or any + * sub-views will embedd the value of this GET argument. + * + * If GET argument is empty or false, it won't make into URL. + * + * If GET argument is not presently set you can specify a 2nd argument + * to forge-set the GET argument for current view and it's sub-views. + */ + public function stickyGet(string $name, string $newValue = null): ?string + { + $this->stickyArgs[$name] = $newValue ?? $_GET[$name] ?? null; + + return $this->stickyArgs[$name]; + } + + // }}} + // {{{ Rendering /** From 932a5662272f866a218e1005f5f94082d103d2b9 Mon Sep 17 00:00:00 2001 From: Alain Belair Date: Tue, 6 Jul 2021 16:02:29 -0400 Subject: [PATCH 03/25] cs fix --- src/App.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/App.php b/src/App.php index 2d72feff7b..dd7c103139 100644 --- a/src/App.php +++ b/src/App.php @@ -124,7 +124,7 @@ class App 'cache-control' => 'no-store', // disable caching by default ]; - /** @var Modal[] Modal view that need to be rendered using json output. */ + /** @var Modal[] Modal view that need to be rendered using json output. */ private $modals = []; /** From 5cb1f639640fee4543e4ae6ad9828592a00aecbd Mon Sep 17 00:00:00 2001 From: Alain Belair Date: Tue, 6 Jul 2021 16:20:04 -0400 Subject: [PATCH 04/25] cs fix --- src/UserAction/ExecutorFactory.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/UserAction/ExecutorFactory.php b/src/UserAction/ExecutorFactory.php index 0e05a02caa..e65f85e6c8 100644 --- a/src/UserAction/ExecutorFactory.php +++ b/src/UserAction/ExecutorFactory.php @@ -10,7 +10,6 @@ use Atk4\Ui\Button; use Atk4\Ui\Exception; use Atk4\Ui\Item; -use Atk4\Ui\Modal; use Atk4\Ui\View; /** From b3036023dc1c2bad753db01b25c6260145c67430 Mon Sep 17 00:00:00 2001 From: Alain Belair Date: Tue, 6 Jul 2021 16:30:06 -0400 Subject: [PATCH 05/25] remove report error --- phpstan.neon.dist | 6 ------ 1 file changed, 6 deletions(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 0e1182dafd..a46b56a415 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1203,12 +1203,6 @@ parameters: - path: 'src/AbstractView.php' message: '~^Method Atk4\\Ui\\AbstractView::add\(\) has parameter \$args with no typehint specified\.$~' - - - path: 'src/AbstractView.php' - message: '~^Instanceof between Atk4\\Ui\\View and Atk4\\Ui\\AbstractView will always evaluate to true\.$~' - - - path: 'src/AbstractView.php' - message: '~^Strict comparison using \!\=\= between Atk4\\Ui\\AbstractView and null will always evaluate to true\.$~' - path: 'src/Accordion.php' message: '~^Method Atk4\\Ui\\Accordion::activate\(\) has no return typehint specified\.$~' From df2e5388a551718461af06b7b3bbdba77d9b1356 Mon Sep 17 00:00:00 2001 From: Alain Belair Date: Wed, 7 Jul 2021 10:52:22 -0400 Subject: [PATCH 06/25] make sure callback never reach is caught --- src/App.php | 3 ++- src/Callback.php | 7 +------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/App.php b/src/App.php index dd7c103139..67854a7a16 100644 --- a/src/App.php +++ b/src/App.php @@ -568,7 +568,8 @@ public function run() $this->hook(self::HOOK_BEFORE_OUTPUT); if (isset($_GET['__atk_callback']) && $this->catch_runaway_callbacks) { - throw new Exception('Callback requested, but never reached. You may be missing some arguments in request URL.'); + throw (new Exception('Callback requested, but never reached. You may be missing some arguments in request URL.')) + ->addMoreInfo('callback', $_GET['__atk_callback']); } $output = $this->html->template->renderToHtml(); diff --git a/src/Callback.php b/src/Callback.php index 4656ce72e5..74cb968a20 100644 --- a/src/Callback.php +++ b/src/Callback.php @@ -63,13 +63,8 @@ public function getUrlTrigger(): string public function set($fx = null, $args = null) { if ($this->isTriggered() && $this->canTrigger()) { - $this->getApp()->catch_runaway_callbacks = false; - $t = $this->getApp()->run_called; - $this->getApp()->run_called = true; - $ret = $fx(...($args ?? [])); - $this->getApp()->run_called = $t; - return $ret; + return $fx(...($args ?? [])); } } From 5a45235ef40708fc4feb8053e61dca49f74f9bad Mon Sep 17 00:00:00 2001 From: Alain Belair Date: Wed, 7 Jul 2021 12:04:11 -0400 Subject: [PATCH 07/25] cs fix --- src/App.php | 2 +- src/Callback.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/App.php b/src/App.php index 67854a7a16..8e4a89d214 100644 --- a/src/App.php +++ b/src/App.php @@ -569,7 +569,7 @@ public function run() if (isset($_GET['__atk_callback']) && $this->catch_runaway_callbacks) { throw (new Exception('Callback requested, but never reached. You may be missing some arguments in request URL.')) - ->addMoreInfo('callback', $_GET['__atk_callback']); + ->addMoreInfo('callback', $_GET['__atk_callback']); } $output = $this->html->template->renderToHtml(); diff --git a/src/Callback.php b/src/Callback.php index 74cb968a20..aa1b3e710e 100644 --- a/src/Callback.php +++ b/src/Callback.php @@ -63,7 +63,6 @@ public function getUrlTrigger(): string public function set($fx = null, $args = null) { if ($this->isTriggered() && $this->canTrigger()) { - return $fx(...($args ?? [])); } } From 0e6c9bbc27c601f13ea5d8b66d60e1abf4bc5c6f Mon Sep 17 00:00:00 2001 From: Alain Belair Date: Wed, 7 Jul 2021 12:14:08 -0400 Subject: [PATCH 08/25] Remove callback from Wizard --- demos/interactive/wizard.php | 2 +- src/Wizard.php | 74 ++++++++++++------------------------ 2 files changed, 25 insertions(+), 51 deletions(-) diff --git a/demos/interactive/wizard.php b/demos/interactive/wizard.php index 26192eadef..a1f367073b 100644 --- a/demos/interactive/wizard.php +++ b/demos/interactive/wizard.php @@ -13,7 +13,7 @@ /** * Demonstrates how to use a wizard. */ -$wizard = Wizard::addTo($app, ['stepCallback' => Callback::addTo($app, ['urlTrigger' => 'demo_wizard'])]); +$wizard = Wizard::addTo($app, ['urlTrigger' => 'demo_wizard']); // First step will automatcally be active when you open page first. It // will contain the 'Next' button with a link. $wizard->addStep('Welcome', function (Wizard $wizard) { diff --git a/src/Wizard.php b/src/Wizard.php index 530ea67688..6865355c34 100644 --- a/src/Wizard.php +++ b/src/Wizard.php @@ -16,39 +16,19 @@ class Wizard extends View public $defaultTemplate = 'wizard.html'; public $ui = 'steps'; - /** - * Callback, that triggers selection of a step. - * - * @var Callback - */ - public $stepCallback; + /** @var string Get argument for this wizard. */ + public $urlTrigger; - /** - * List of steps. - * - * @var array - */ + /** @var array List of steps.*/ public $steps = []; - /** - * Current step. - * - * @var int - */ + /** @var int Current step.*/ public $currentStep; - /** - * Button for going to previous step. - * - * @var Button - */ + /** @var Button Button for going to previous step.*/ public $buttonPrev; - /** - * Buttor for going to next step. - * - * @var Button - */ + /** @var Button Buttor for going to next step.*/ public $buttonNext; /** @@ -65,11 +45,11 @@ protected function init(): void { parent::init(); - if (!$this->stepCallback) { - $this->stepCallback = Callback::addTo($this, ['urlTrigger' => $this->name]); + if (!$this->urlTrigger) { + $this->urlTrigger = $this->name; } - $this->currentStep = (int) ($this->stepCallback->getTriggeredValue() ?: 0); + $this->currentStep = (int) ($this->stickyGet($this->urlTrigger) ?? 0); $this->stepTemplate = $this->template->cloneRegion('Step'); $this->template->del('Step'); @@ -77,24 +57,28 @@ protected function init(): void // add buttons if ($this->currentStep) { $this->buttonPrev = Button::addTo($this, ['Back', 'basic'], ['Left']); - $this->buttonPrev->link($this->stepCallback->getUrl((string) ($this->currentStep - 1))); + $this->buttonPrev->link($this->getUrl($this->currentStep - 1)); } $this->buttonNext = Button::addTo($this, ['Next', 'primary'], ['Right']); $this->buttonFinish = Button::addTo($this, ['Finish', 'primary'], ['Right']); - $this->buttonNext->link($this->stepCallback->getUrl((string) ($this->currentStep + 1))); + $this->buttonNext->link($this->getUrl($this->currentStep + 1)); + } + + protected function getUrl(int $step): string + { + return $this->url([$this->urlTrigger => $step]); } /** * Adds step to the wizard. * * @param mixed $name Name of tab or Tab object - * @param mixed $callback Optional callback action or URL (or array with url + parameters) * * @return View */ - public function addStep($name, $callback) + public function addStep($name, \Closure $fx) { $step = Factory::factory([ Step::class, @@ -106,14 +90,9 @@ public function addStep($name, $callback) // add tabs menu item $this->steps[] = $this->add($step, 'Step'); - if (!$this->stepCallback->isTriggered()) { - $_GET[$this->stepCallback->getUrlTrigger()] = '0'; - } - if ($step->sequence === $this->currentStep) { $step->addClass('active'); - - $this->stepCallback->set($callback, [$this]); + $fx($this); } elseif ($step->sequence < $this->currentStep) { $step->addClass('completed'); } @@ -128,20 +107,17 @@ public function addStep($name, $callback) /** * Adds an extra screen to show user when he goes beyond last step. * There won't be "back" button on this step anymore. - * - * @param \Closure $callback Virtual page */ - public function addFinish(\Closure $callback) + public function addFinish(\Closure $fx) { if (count($this->steps) === $this->currentStep + 1) { - $this->buttonFinish->link($this->stepCallback->getUrl((string) (count($this->steps)))); + $this->buttonFinish->link($this->getUrl(count($this->steps))); } elseif ($this->currentStep === count($this->steps)) { $this->buttonPrev->destroy(); $this->buttonNext->addClass('disabled')->set('Completed'); $this->buttonFinish->destroy(); - $this->getApp()->catch_runaway_callbacks = false; - $callback($this); + $fx($this); } else { $this->buttonFinish->destroy(); } @@ -166,12 +142,10 @@ public function add($seed, $region = null): AbstractView /** * Get URL to next step. Will respect stickyGET. - * - * @return string URL to next step */ - public function urlNext() + public function urlNext(): string { - return $this->stepCallback->getUrl((string) ($this->currentStep + 1)); + return $this->getUrl($this->currentStep + 1); } /** @@ -181,7 +155,7 @@ public function urlNext() */ public function jsNext() { - return new JsExpression('document.location = []', [$this->urlNext()]); + return new JsExpression('document.location = []', [$this->getUrl($this->currentStep + 1)]); } protected function recursiveRender(): void From a9f6e7005b2c02fd5f8e9404957a916c6a489b57 Mon Sep 17 00:00:00 2001 From: Alain Belair Date: Wed, 7 Jul 2021 13:06:54 -0400 Subject: [PATCH 09/25] fix --- src/Callback.php | 2 +- src/Wizard.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Callback.php b/src/Callback.php index aa1b3e710e..384d26fab2 100644 --- a/src/Callback.php +++ b/src/Callback.php @@ -111,7 +111,7 @@ public function canTrigger(): bool /** * Return URL that will trigger action on this call-back. If you intend to request - * the URL direcly in your browser (as iframe, new tab, or document location), you + * the URL directly in your browser (as iframe, new tab, or document location), you * should use getUrl instead. */ public function getJsUrl(string $value = 'ajax'): string diff --git a/src/Wizard.php b/src/Wizard.php index 6865355c34..d241d3daab 100644 --- a/src/Wizard.php +++ b/src/Wizard.php @@ -155,7 +155,7 @@ public function urlNext(): string */ public function jsNext() { - return new JsExpression('document.location = []', [$this->getUrl($this->currentStep + 1)]); + return new JsExpression('document.location = []', [$this->urlNext()]); } protected function recursiveRender(): void From d996585a548778501eabbe6625a51b6f30a6e8f9 Mon Sep 17 00:00:00 2001 From: Alain Belair Date: Wed, 7 Jul 2021 13:08:21 -0400 Subject: [PATCH 10/25] cs fix --- src/Wizard.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Wizard.php b/src/Wizard.php index d241d3daab..8115ee7f7f 100644 --- a/src/Wizard.php +++ b/src/Wizard.php @@ -19,16 +19,16 @@ class Wizard extends View /** @var string Get argument for this wizard. */ public $urlTrigger; - /** @var array List of steps.*/ + /** @var array List of steps. */ public $steps = []; - /** @var int Current step.*/ + /** @var int Current step. */ public $currentStep; - /** @var Button Button for going to previous step.*/ + /** @var Button Button for going to previous step. */ public $buttonPrev; - /** @var Button Buttor for going to next step.*/ + /** @var Button Buttor for going to next step. */ public $buttonNext; /** @@ -74,7 +74,7 @@ protected function getUrl(int $step): string /** * Adds step to the wizard. * - * @param mixed $name Name of tab or Tab object + * @param mixed $name Name of tab or Tab object * * @return View */ From e70f9b776bbb84eb038f5e5f4399b8d2c4a12d90 Mon Sep 17 00:00:00 2001 From: Alain Belair Date: Wed, 7 Jul 2021 13:10:41 -0400 Subject: [PATCH 11/25] phpstan fix --- phpstan.neon.dist | 3 --- 1 file changed, 3 deletions(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index a46b56a415..edbb86c7d9 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -906,9 +906,6 @@ parameters: - path: 'src/View.php' message: '~^If condition is always true\.$~' - - - path: 'src/Wizard.php' - message: '~^Negated boolean expression is always false\.$~' - path: 'tests/DemosTest.php' message: '~^Else branch is unreachable because ternary operator condition is always true\.$~' From 289d7b0fa5baab6d3ef78668479f63135e6fa848 Mon Sep 17 00:00:00 2001 From: Alain Belair Date: Fri, 16 Jul 2021 10:50:52 -0400 Subject: [PATCH 12/25] add callback trigger test --- tests/CallbackTest.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/CallbackTest.php b/tests/CallbackTest.php index 3fc37d555a..411d4804af 100644 --- a/tests/CallbackTest.php +++ b/tests/CallbackTest.php @@ -5,6 +5,7 @@ namespace Atk4\Ui\Tests; use Atk4\Core\Phpunit\TestCase; +use Atk4\Ui\Callback; class AppMock extends \Atk4\Ui\App { @@ -58,6 +59,15 @@ public function testCallback(): void $this->assertSame(34, $var); } + public function testCallbackTrigger(): void + { + $cb = \Atk4\Ui\Callback::addTo($this->app); + $this->assertSame($this->app->layout->name . '_' . $cb->short_name, $cb->getUrlTrigger()); + + $cb = Callback::addTo($this->app, ['urlTrigger' => 'test']); + $this->assertSame('test', $cb->getUrlTrigger()); + } + public function testCallbackNotFiring(): void { $var = null; From a4c5d22fe883bce4e694a4ecc0438d9dc8b26b55 Mon Sep 17 00:00:00 2001 From: Alain Belair Date: Fri, 16 Jul 2021 11:13:47 -0400 Subject: [PATCH 13/25] add getTriggeredValue test --- tests/CallbackTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/CallbackTest.php b/tests/CallbackTest.php index 411d4804af..5e5c8b1afc 100644 --- a/tests/CallbackTest.php +++ b/tests/CallbackTest.php @@ -57,6 +57,7 @@ public function testCallback(): void }, [34]); $this->assertSame(34, $var); + $this->assertSame('1', $cb->getTriggeredValue()); } public function testCallbackTrigger(): void From 419e929f570e8cf7176ed143f47c1c0e65717996 Mon Sep 17 00:00:00 2001 From: Alain Belair Date: Wed, 21 Jul 2021 13:49:35 -0400 Subject: [PATCH 14/25] add runaway --- src/AbstractView.php | 2 ++ src/Callback.php | 13 ++++++------- src/JsCallback.php | 1 - src/JsReload.php | 2 +- src/View.php | 21 ++++++++++++++++----- 5 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/AbstractView.php b/src/AbstractView.php index 41dbd4b8aa..edf3b2f919 100644 --- a/src/AbstractView.php +++ b/src/AbstractView.php @@ -53,6 +53,8 @@ abstract class AbstractView */ protected $_rendered = false; + protected const TRIGGER_PREFIX = '__atkcb_'; + // }}} // {{{ Default init() method and add() logic diff --git a/src/Callback.php b/src/Callback.php index 384d26fab2..21482aefc9 100644 --- a/src/Callback.php +++ b/src/Callback.php @@ -43,8 +43,6 @@ protected function init(): void public function setUrlTrigger(string $trigger = null) { $this->urlTrigger = $trigger ?: $this->name; - - $this->getOwner()->stickyGet($this->urlTrigger); } public function getUrlTrigger(): string @@ -82,7 +80,7 @@ public function terminateJson(AbstractView $view): void */ public function isTriggered() { - return isset($_GET[$this->urlTrigger]); + return isset($_GET[self::TRIGGER_PREFIX . $this->urlTrigger] ); } /** @@ -90,7 +88,7 @@ public function isTriggered() */ public function getTriggeredValue(): string { - return $_GET[$this->urlTrigger] ?? ''; + return $_GET[self::TRIGGER_PREFIX . $this->urlTrigger] ?? ''; } /** @@ -116,7 +114,7 @@ public function canTrigger(): bool */ public function getJsUrl(string $value = 'ajax'): string { - return $this->getOwner()->jsUrl($this->getUrlArguments($value)); + return $this->getOwner()->jsUrl($this->getUrlArguments($value), true); } /** @@ -125,7 +123,7 @@ public function getJsUrl(string $value = 'ajax'): string */ public function getUrl(string $value = 'callback'): string { - return $this->getOwner()->url($this->getUrlArguments($value)); + return $this->getOwner()->url($this->getUrlArguments($value), true); } /** @@ -133,6 +131,7 @@ public function getUrl(string $value = 'callback'): string */ private function getUrlArguments(string $value = null): array { - return ['__atk_callback' => $this->urlTrigger, $this->urlTrigger => $value ?? $this->getTriggeredValue()]; + return ['__atk_callback' => $this->urlTrigger, self::TRIGGER_PREFIX . $this->urlTrigger => $value ?? $this->getTriggeredValue()]; } + } diff --git a/src/JsCallback.php b/src/JsCallback.php index 97f82b81e0..c37342f1d8 100644 --- a/src/JsCallback.php +++ b/src/JsCallback.php @@ -43,7 +43,6 @@ class JsCallback extends Callback implements JsExpressionable * @var bool */ public $triggerOnReload = false; - /** * When multiple JsExpressionable's are collected inside an array and may * have some degree of nesting, convert it into a one-dimensional array, diff --git a/src/JsReload.php b/src/JsReload.php index 0b82b969e9..7b226a2175 100644 --- a/src/JsReload.php +++ b/src/JsReload.php @@ -55,7 +55,7 @@ public function jsRender(): string $final = (new Jquery($this->view)) ->atkReloadView( [ - 'uri' => $this->view->jsUrl(['__atk_reload' => $this->view->name]), + 'uri' => $this->view->jsUrl(['__atk_reload' => $this->view->name], true), 'uri_options' => !empty($this->args) ? $this->args : null, 'afterSuccess' => $this->afterSuccess ? $this->afterSuccess->jsRender() : null, 'apiConfig' => !empty($this->apiConfig) ? $this->apiConfig : null, diff --git a/src/View.php b/src/View.php index 5819e4d7c9..0c46cafc4b 100644 --- a/src/View.php +++ b/src/View.php @@ -122,7 +122,6 @@ class View extends AbstractView implements JsExpressionable /** @var ExecutorFactory Seed class name */ public $executorFactory; - // }}} // {{{ Setting Things up @@ -598,9 +597,9 @@ public function removeAttr($property) * * @return string */ - public function jsUrl($page = []) + public function jsUrl($page = [], bool $includeRunningCallback = false) { - return $this->getApp()->jsUrl($page, false, $this->_getStickyArgs()); + return $this->getApp()->jsUrl($page, false, array_merge($this->_getStickyArgs(), $includeRunningCallback ? $this->getCallbackArguments() : [])); } /** @@ -612,9 +611,9 @@ public function jsUrl($page = []) * * @return string */ - public function url($page = []) + public function url($page = [], bool $includeRunningCallback = false) { - return $this->getApp()->url($page, false, $this->_getStickyArgs()); + return $this->getApp()->url($page, false, array_merge($this->_getStickyArgs(), $includeRunningCallback ? $this->getCallbackArguments() : [])); } /** @@ -631,6 +630,18 @@ protected function _getStickyArgs(): array return $stickyArgs; } + protected function getCallbackArguments(): array + { + $triggers = []; + foreach ($_GET as $k => $get) { + if (str_starts_with($k, self::TRIGGER_PREFIX)) { + $triggers[$k] = $get; + } + } + + return $triggers; + } + /** * Mark GET argument as sticky. Calling url() on this view or any * sub-views will embedd the value of this GET argument. From dae98a1312b2d928ba86077a610b4e619f2b8e4a Mon Sep 17 00:00:00 2001 From: Alain Belair Date: Wed, 21 Jul 2021 14:38:20 -0400 Subject: [PATCH 15/25] add test --- src/AbstractView.php | 2 +- src/Callback.php | 7 +++---- src/JsCallback.php | 1 + src/View.php | 2 +- tests/CallbackTest.php | 38 +++++++++++++++++++++++++++++++------- 5 files changed, 37 insertions(+), 13 deletions(-) diff --git a/src/AbstractView.php b/src/AbstractView.php index edf3b2f919..4d285062f1 100644 --- a/src/AbstractView.php +++ b/src/AbstractView.php @@ -53,7 +53,7 @@ abstract class AbstractView */ protected $_rendered = false; - protected const TRIGGER_PREFIX = '__atkcb_'; + public const CALLBACK_TRIGGER_PREFIX = '__atkcb_'; // }}} diff --git a/src/Callback.php b/src/Callback.php index 21482aefc9..11a67b5fc0 100644 --- a/src/Callback.php +++ b/src/Callback.php @@ -80,7 +80,7 @@ public function terminateJson(AbstractView $view): void */ public function isTriggered() { - return isset($_GET[self::TRIGGER_PREFIX . $this->urlTrigger] ); + return isset($_GET[self::CALLBACK_TRIGGER_PREFIX . $this->urlTrigger]); } /** @@ -88,7 +88,7 @@ public function isTriggered() */ public function getTriggeredValue(): string { - return $_GET[self::TRIGGER_PREFIX . $this->urlTrigger] ?? ''; + return $_GET[self::CALLBACK_TRIGGER_PREFIX . $this->urlTrigger] ?? ''; } /** @@ -131,7 +131,6 @@ public function getUrl(string $value = 'callback'): string */ private function getUrlArguments(string $value = null): array { - return ['__atk_callback' => $this->urlTrigger, self::TRIGGER_PREFIX . $this->urlTrigger => $value ?? $this->getTriggeredValue()]; + return ['__atk_callback' => $this->urlTrigger, self::CALLBACK_TRIGGER_PREFIX . $this->urlTrigger => $value ?? $this->getTriggeredValue()]; } - } diff --git a/src/JsCallback.php b/src/JsCallback.php index c37342f1d8..97f82b81e0 100644 --- a/src/JsCallback.php +++ b/src/JsCallback.php @@ -43,6 +43,7 @@ class JsCallback extends Callback implements JsExpressionable * @var bool */ public $triggerOnReload = false; + /** * When multiple JsExpressionable's are collected inside an array and may * have some degree of nesting, convert it into a one-dimensional array, diff --git a/src/View.php b/src/View.php index 0c46cafc4b..11f8322b53 100644 --- a/src/View.php +++ b/src/View.php @@ -634,7 +634,7 @@ protected function getCallbackArguments(): array { $triggers = []; foreach ($_GET as $k => $get) { - if (str_starts_with($k, self::TRIGGER_PREFIX)) { + if (str_starts_with($k, self::CALLBACK_TRIGGER_PREFIX)) { $triggers[$k] = $get; } } diff --git a/tests/CallbackTest.php b/tests/CallbackTest.php index 5e5c8b1afc..be6576e01b 100644 --- a/tests/CallbackTest.php +++ b/tests/CallbackTest.php @@ -32,6 +32,7 @@ class CallbackTest extends TestCase /** @var \Atk4\Ui\App */ public $app; + public $cbPrefix; protected function setUp(): void { @@ -50,7 +51,7 @@ public function testCallback(): void $cb = \Atk4\Ui\Callback::addTo($this->app); // simulate triggering - $_GET[$cb->name] = '1'; + $_GET[Callback::CALLBACK_TRIGGER_PREFIX . $cb->name] = '1'; $cb->set(function ($x) use (&$var) { $var = $x; @@ -69,6 +70,29 @@ public function testCallbackTrigger(): void $this->assertSame('test', $cb->getUrlTrigger()); } + public function testViewUrlCallback() + { + $var = null; + + $v1 = \Atk4\Ui\View::addTo($this->app); + $cb = \Atk4\Ui\Callback::addTo($v1); + + // simulate triggering + $_GET[Callback::CALLBACK_TRIGGER_PREFIX . $cb->name] = '1'; + + $cb->set(function ($x) use (&$var, $v1) { + $v3 = \Atk4\Ui\View::addTo($v1); + $this->assertSame('test.php', $v3->url(['test'])); + $var = $x; + }, [34]); + + $v2 = \Atk4\Ui\View::addTo($v1); + $v2->stickyGet('g1', '1'); + + $this->assertSame(34, $var); + $this->assertSame('test.php?g1=1', $v2->url(['test'])); + } + public function testCallbackNotFiring(): void { $var = null; @@ -90,7 +114,7 @@ public function testCallbackLater(): void $cb = \Atk4\Ui\CallbackLater::addTo($this->app); // simulate triggering - $_GET[$cb->name] = '1'; + $_GET[Callback::CALLBACK_TRIGGER_PREFIX . $cb->name] = '1'; $cb->set(function ($x) use (&$var) { $var = $x; @@ -111,8 +135,8 @@ public function testCallbackLaterNested(): void $cb = \Atk4\Ui\CallbackLater::addTo($this->app); // simulate triggering - $_GET[$cb->name] = '1'; - $_GET[$cb->name . '_2'] = '1'; + $_GET[Callback::CALLBACK_TRIGGER_PREFIX . $cb->name] = '1'; + $_GET[Callback::CALLBACK_TRIGGER_PREFIX . $cb->name . '_2'] = '1'; $app = $this->app; $cb->set(function ($x) use (&$var, $app, &$cbname) { @@ -157,7 +181,7 @@ public function testVirtualPage(): void $vp = \Atk4\Ui\VirtualPage::addTo($this->app); // simulate triggering - $_GET[$vp->name] = '1'; + $_GET[Callback::CALLBACK_TRIGGER_PREFIX . $vp->name] = '1'; $vp->set(function ($p) use (&$var) { $var = 25; @@ -175,7 +199,7 @@ public function testVirtualPageCustomTrigger(): void $vp = \Atk4\Ui\VirtualPage::addTo($this->app, ['urlTrigger' => 'bah']); // simulate triggering - $_GET['bah'] = '1'; + $_GET[Callback::CALLBACK_TRIGGER_PREFIX . 'bah'] = '1'; $vp->set(function ($p) use (&$var) { $var = 25; @@ -200,7 +224,7 @@ public function testPull230(): void $vp = \Atk4\Ui\VirtualPage::addTo($this->app); // simulate triggering - $_GET[$vp->name] = '1'; + $_GET[Callback::CALLBACK_TRIGGER_PREFIX . $vp->name] = '1'; $vp->set(\Closure::fromCallable([$this, 'callPull230'])); From 7ac7a68be37b8b4493cfd4d3dbc538bf8131c285 Mon Sep 17 00:00:00 2001 From: Alain Belair Date: Wed, 21 Jul 2021 14:59:54 -0400 Subject: [PATCH 16/25] fix test --- tests/DemosTest.php | 21 +++++++++++---------- tests/FormTest.php | 3 ++- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/tests/DemosTest.php b/tests/DemosTest.php index 4d7af1891c..ccdf0010d8 100644 --- a/tests/DemosTest.php +++ b/tests/DemosTest.php @@ -7,6 +7,7 @@ use Atk4\Core\Phpunit\TestCase; use Atk4\Data\Persistence; use Atk4\Ui\App; +use Atk4\Ui\Callback; use GuzzleHttp\Client; use GuzzleHttp\Psr7\Request; use Psr\Http\Message\RequestInterface; @@ -327,7 +328,7 @@ public function testWizard(): void } $response = $this->getResponseFromRequest( - 'interactive/wizard.php?demo_wizard=1&w_form_submit=ajax&__atk_callback=w_form_submit', + 'interactive/wizard.php?demo_wizard=1&' . Callback::CALLBACK_TRIGGER_PREFIX .'w_form_submit=ajax&__atk_callback=w_form_submit', ['form_params' => [ 'dsn' => 'mysql://root:root@db-host.example.com/atk4', ]] @@ -350,10 +351,10 @@ public function jsonResponseProvider(): array // simple reload $files[] = ['_unit-test/reload.php?__atk_reload=reload']; // loader callback reload - $files[] = ['_unit-test/reload.php?c_reload=ajax&__atk_callback=c_reload']; + $files[] = ['_unit-test/reload.php?' . Callback::CALLBACK_TRIGGER_PREFIX . 'c_reload=ajax&__atk_callback=c_reload']; // test catch exceptions - $files[] = ['_unit-test/exception.php?m_cb=ajax&__atk_callback=m_cb&__atk_json=1']; - $files[] = ['_unit-test/exception.php?m2_cb=ajax&__atk_callback=m2_cb&__atk_json=1']; + $files[] = ['_unit-test/exception.php?' . Callback::CALLBACK_TRIGGER_PREFIX . 'm_cb=ajax&__atk_callback=m_cb&__atk_json=1']; + $files[] = ['_unit-test/exception.php?' . Callback::CALLBACK_TRIGGER_PREFIX . 'm2_cb=ajax&__atk_callback=m2_cb&__atk_json=1']; return $files; } @@ -383,11 +384,11 @@ public function testDemoAssertJsonResponse(string $uri): void public function sseResponseProvider(): array { $files = []; - $files[] = ['_unit-test/sse.php?see_test=ajax&__atk_callback=1&__atk_sse=1']; - $files[] = ['_unit-test/console.php?console_test=ajax&__atk_callback=1&__atk_sse=1']; + $files[] = ['_unit-test/sse.php?' . Callback::CALLBACK_TRIGGER_PREFIX . 'see_test=ajax&__atk_callback=1&__atk_sse=1']; + $files[] = ['_unit-test/console.php?' . Callback::CALLBACK_TRIGGER_PREFIX . 'console_test=ajax&__atk_callback=1&__atk_sse=1']; if (!($this instanceof DemosHttpNoExitTest)) { // ignore content type mismatch when App->call_exit equals to true - $files[] = ['_unit-test/console_run.php?console_test=ajax&__atk_callback=1&__atk_sse=1']; - $files[] = ['_unit-test/console_exec.php?console_test=ajax&__atk_callback=1&__atk_sse=1']; + $files[] = ['_unit-test/console_run.php?' . Callback::CALLBACK_TRIGGER_PREFIX . 'console_test=ajax&__atk_callback=1&__atk_sse=1']; + $files[] = ['_unit-test/console_exec.php?' . Callback::CALLBACK_TRIGGER_PREFIX . 'console_test=ajax&__atk_callback=1&__atk_sse=1']; } return $files; @@ -433,7 +434,7 @@ public function jsonResponsePostProvider(): array { $files = []; $files[] = [ - '_unit-test/post.php?test_submit=ajax&__atk_callback=test_submit', + '_unit-test/post.php?' . Callback::CALLBACK_TRIGGER_PREFIX . 'test_submit=ajax&__atk_callback=test_submit', [ 'f1' => 'v1', ], @@ -441,7 +442,7 @@ public function jsonResponsePostProvider(): array // for JsNotify coverage $files[] = [ - 'obsolete/notify2.php?test_notify=ajax&__atk_callback=test_notify', + 'obsolete/notify2.php?' . Callback::CALLBACK_TRIGGER_PREFIX . 'test_notify=ajax&__atk_callback=test_notify', [ 'text' => 'This text will appear in notification', 'icon' => 'warning sign', diff --git a/tests/FormTest.php b/tests/FormTest.php index 2205385982..5c9191fd8b 100644 --- a/tests/FormTest.php +++ b/tests/FormTest.php @@ -7,6 +7,7 @@ use Atk4\Core\Phpunit\TestCase; use Atk4\Data\Model; use Atk4\Ui\App; +use Atk4\Ui\Callback; use Atk4\Ui\Form; class FormTest extends TestCase @@ -47,7 +48,7 @@ public function assertSubmit(array $post_data, \Closure $submit = null, \Closure $submit_called = false; $_POST = $post_data; // trigger callback - $_GET['atk_submit'] = 'ajax'; + $_GET[Callback::CALLBACK_TRIGGER_PREFIX . 'atk_submit'] = 'ajax'; $_GET['__atk_callback'] = 'atk_submit'; $this->f->onSubmit(function (Form $form) use (&$submit_called, $submit) { From cfc976e72741dae9c2e8bd9ee0863c851a12dcf0 Mon Sep 17 00:00:00 2001 From: Alain Belair Date: Wed, 21 Jul 2021 15:02:20 -0400 Subject: [PATCH 17/25] fix cs --- tests/DemosTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/DemosTest.php b/tests/DemosTest.php index ccdf0010d8..ff25b39a4f 100644 --- a/tests/DemosTest.php +++ b/tests/DemosTest.php @@ -328,7 +328,7 @@ public function testWizard(): void } $response = $this->getResponseFromRequest( - 'interactive/wizard.php?demo_wizard=1&' . Callback::CALLBACK_TRIGGER_PREFIX .'w_form_submit=ajax&__atk_callback=w_form_submit', + 'interactive/wizard.php?demo_wizard=1&' . Callback::CALLBACK_TRIGGER_PREFIX . 'w_form_submit=ajax&__atk_callback=w_form_submit', ['form_params' => [ 'dsn' => 'mysql://root:root@db-host.example.com/atk4', ]] From 8656f7a140ea7755a22afb650d6d7fa05a887c3e Mon Sep 17 00:00:00 2001 From: Alain Belair Date: Wed, 21 Jul 2021 15:03:54 -0400 Subject: [PATCH 18/25] remove unused --- tests/CallbackTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/CallbackTest.php b/tests/CallbackTest.php index be6576e01b..de1a06b25a 100644 --- a/tests/CallbackTest.php +++ b/tests/CallbackTest.php @@ -32,7 +32,6 @@ class CallbackTest extends TestCase /** @var \Atk4\Ui\App */ public $app; - public $cbPrefix; protected function setUp(): void { From 06c5faef3b0b73ae8752c114fdc4ee83b44df6ce Mon Sep 17 00:00:00 2001 From: Alain Belair Date: Wed, 21 Jul 2021 15:06:26 -0400 Subject: [PATCH 19/25] add return type --- tests/CallbackTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/CallbackTest.php b/tests/CallbackTest.php index de1a06b25a..9c9722c789 100644 --- a/tests/CallbackTest.php +++ b/tests/CallbackTest.php @@ -69,7 +69,7 @@ public function testCallbackTrigger(): void $this->assertSame('test', $cb->getUrlTrigger()); } - public function testViewUrlCallback() + public function testViewUrlCallback(): void { $var = null; From 09c0fb5504a46d654a9ba417c1d800bb83e757a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Wed, 21 Jul 2021 22:31:19 +0200 Subject: [PATCH 20/25] revert faked global sticky via _GET filter --- src/AbstractView.php | 2 -- src/Callback.php | 12 +++++++----- src/JsReload.php | 2 +- src/View.php | 20 ++++---------------- tests/CallbackTest.php | 14 +++++++------- tests/DemosTest.php | 21 ++++++++++----------- tests/FormTest.php | 3 +-- 7 files changed, 30 insertions(+), 44 deletions(-) diff --git a/src/AbstractView.php b/src/AbstractView.php index 4d285062f1..41dbd4b8aa 100644 --- a/src/AbstractView.php +++ b/src/AbstractView.php @@ -53,8 +53,6 @@ abstract class AbstractView */ protected $_rendered = false; - public const CALLBACK_TRIGGER_PREFIX = '__atkcb_'; - // }}} // {{{ Default init() method and add() logic diff --git a/src/Callback.php b/src/Callback.php index 11a67b5fc0..384d26fab2 100644 --- a/src/Callback.php +++ b/src/Callback.php @@ -43,6 +43,8 @@ protected function init(): void public function setUrlTrigger(string $trigger = null) { $this->urlTrigger = $trigger ?: $this->name; + + $this->getOwner()->stickyGet($this->urlTrigger); } public function getUrlTrigger(): string @@ -80,7 +82,7 @@ public function terminateJson(AbstractView $view): void */ public function isTriggered() { - return isset($_GET[self::CALLBACK_TRIGGER_PREFIX . $this->urlTrigger]); + return isset($_GET[$this->urlTrigger]); } /** @@ -88,7 +90,7 @@ public function isTriggered() */ public function getTriggeredValue(): string { - return $_GET[self::CALLBACK_TRIGGER_PREFIX . $this->urlTrigger] ?? ''; + return $_GET[$this->urlTrigger] ?? ''; } /** @@ -114,7 +116,7 @@ public function canTrigger(): bool */ public function getJsUrl(string $value = 'ajax'): string { - return $this->getOwner()->jsUrl($this->getUrlArguments($value), true); + return $this->getOwner()->jsUrl($this->getUrlArguments($value)); } /** @@ -123,7 +125,7 @@ public function getJsUrl(string $value = 'ajax'): string */ public function getUrl(string $value = 'callback'): string { - return $this->getOwner()->url($this->getUrlArguments($value), true); + return $this->getOwner()->url($this->getUrlArguments($value)); } /** @@ -131,6 +133,6 @@ public function getUrl(string $value = 'callback'): string */ private function getUrlArguments(string $value = null): array { - return ['__atk_callback' => $this->urlTrigger, self::CALLBACK_TRIGGER_PREFIX . $this->urlTrigger => $value ?? $this->getTriggeredValue()]; + return ['__atk_callback' => $this->urlTrigger, $this->urlTrigger => $value ?? $this->getTriggeredValue()]; } } diff --git a/src/JsReload.php b/src/JsReload.php index 7b226a2175..0b82b969e9 100644 --- a/src/JsReload.php +++ b/src/JsReload.php @@ -55,7 +55,7 @@ public function jsRender(): string $final = (new Jquery($this->view)) ->atkReloadView( [ - 'uri' => $this->view->jsUrl(['__atk_reload' => $this->view->name], true), + 'uri' => $this->view->jsUrl(['__atk_reload' => $this->view->name]), 'uri_options' => !empty($this->args) ? $this->args : null, 'afterSuccess' => $this->afterSuccess ? $this->afterSuccess->jsRender() : null, 'apiConfig' => !empty($this->apiConfig) ? $this->apiConfig : null, diff --git a/src/View.php b/src/View.php index 11f8322b53..4b6c17b9e6 100644 --- a/src/View.php +++ b/src/View.php @@ -597,9 +597,9 @@ public function removeAttr($property) * * @return string */ - public function jsUrl($page = [], bool $includeRunningCallback = false) + public function jsUrl($page = []) { - return $this->getApp()->jsUrl($page, false, array_merge($this->_getStickyArgs(), $includeRunningCallback ? $this->getCallbackArguments() : [])); + return $this->getApp()->jsUrl($page, false, $this->_getStickyArgs()); } /** @@ -611,9 +611,9 @@ public function jsUrl($page = [], bool $includeRunningCallback = false) * * @return string */ - public function url($page = [], bool $includeRunningCallback = false) + public function url($page = []) { - return $this->getApp()->url($page, false, array_merge($this->_getStickyArgs(), $includeRunningCallback ? $this->getCallbackArguments() : [])); + return $this->getApp()->url($page, false, $this->_getStickyArgs()); } /** @@ -630,18 +630,6 @@ protected function _getStickyArgs(): array return $stickyArgs; } - protected function getCallbackArguments(): array - { - $triggers = []; - foreach ($_GET as $k => $get) { - if (str_starts_with($k, self::CALLBACK_TRIGGER_PREFIX)) { - $triggers[$k] = $get; - } - } - - return $triggers; - } - /** * Mark GET argument as sticky. Calling url() on this view or any * sub-views will embedd the value of this GET argument. diff --git a/tests/CallbackTest.php b/tests/CallbackTest.php index 9c9722c789..76292de16c 100644 --- a/tests/CallbackTest.php +++ b/tests/CallbackTest.php @@ -50,7 +50,7 @@ public function testCallback(): void $cb = \Atk4\Ui\Callback::addTo($this->app); // simulate triggering - $_GET[Callback::CALLBACK_TRIGGER_PREFIX . $cb->name] = '1'; + $_GET[$cb->name] = '1'; $cb->set(function ($x) use (&$var) { $var = $x; @@ -113,7 +113,7 @@ public function testCallbackLater(): void $cb = \Atk4\Ui\CallbackLater::addTo($this->app); // simulate triggering - $_GET[Callback::CALLBACK_TRIGGER_PREFIX . $cb->name] = '1'; + $_GET[$cb->name] = '1'; $cb->set(function ($x) use (&$var) { $var = $x; @@ -134,8 +134,8 @@ public function testCallbackLaterNested(): void $cb = \Atk4\Ui\CallbackLater::addTo($this->app); // simulate triggering - $_GET[Callback::CALLBACK_TRIGGER_PREFIX . $cb->name] = '1'; - $_GET[Callback::CALLBACK_TRIGGER_PREFIX . $cb->name . '_2'] = '1'; + $_GET[$cb->name] = '1'; + $_GET[$cb->name . '_2'] = '1'; $app = $this->app; $cb->set(function ($x) use (&$var, $app, &$cbname) { @@ -180,7 +180,7 @@ public function testVirtualPage(): void $vp = \Atk4\Ui\VirtualPage::addTo($this->app); // simulate triggering - $_GET[Callback::CALLBACK_TRIGGER_PREFIX . $vp->name] = '1'; + $_GET[$vp->name] = '1'; $vp->set(function ($p) use (&$var) { $var = 25; @@ -198,7 +198,7 @@ public function testVirtualPageCustomTrigger(): void $vp = \Atk4\Ui\VirtualPage::addTo($this->app, ['urlTrigger' => 'bah']); // simulate triggering - $_GET[Callback::CALLBACK_TRIGGER_PREFIX . 'bah'] = '1'; + $_GET['bah'] = '1'; $vp->set(function ($p) use (&$var) { $var = 25; @@ -223,7 +223,7 @@ public function testPull230(): void $vp = \Atk4\Ui\VirtualPage::addTo($this->app); // simulate triggering - $_GET[Callback::CALLBACK_TRIGGER_PREFIX . $vp->name] = '1'; + $_GET[$vp->name] = '1'; $vp->set(\Closure::fromCallable([$this, 'callPull230'])); diff --git a/tests/DemosTest.php b/tests/DemosTest.php index ff25b39a4f..4d7af1891c 100644 --- a/tests/DemosTest.php +++ b/tests/DemosTest.php @@ -7,7 +7,6 @@ use Atk4\Core\Phpunit\TestCase; use Atk4\Data\Persistence; use Atk4\Ui\App; -use Atk4\Ui\Callback; use GuzzleHttp\Client; use GuzzleHttp\Psr7\Request; use Psr\Http\Message\RequestInterface; @@ -328,7 +327,7 @@ public function testWizard(): void } $response = $this->getResponseFromRequest( - 'interactive/wizard.php?demo_wizard=1&' . Callback::CALLBACK_TRIGGER_PREFIX . 'w_form_submit=ajax&__atk_callback=w_form_submit', + 'interactive/wizard.php?demo_wizard=1&w_form_submit=ajax&__atk_callback=w_form_submit', ['form_params' => [ 'dsn' => 'mysql://root:root@db-host.example.com/atk4', ]] @@ -351,10 +350,10 @@ public function jsonResponseProvider(): array // simple reload $files[] = ['_unit-test/reload.php?__atk_reload=reload']; // loader callback reload - $files[] = ['_unit-test/reload.php?' . Callback::CALLBACK_TRIGGER_PREFIX . 'c_reload=ajax&__atk_callback=c_reload']; + $files[] = ['_unit-test/reload.php?c_reload=ajax&__atk_callback=c_reload']; // test catch exceptions - $files[] = ['_unit-test/exception.php?' . Callback::CALLBACK_TRIGGER_PREFIX . 'm_cb=ajax&__atk_callback=m_cb&__atk_json=1']; - $files[] = ['_unit-test/exception.php?' . Callback::CALLBACK_TRIGGER_PREFIX . 'm2_cb=ajax&__atk_callback=m2_cb&__atk_json=1']; + $files[] = ['_unit-test/exception.php?m_cb=ajax&__atk_callback=m_cb&__atk_json=1']; + $files[] = ['_unit-test/exception.php?m2_cb=ajax&__atk_callback=m2_cb&__atk_json=1']; return $files; } @@ -384,11 +383,11 @@ public function testDemoAssertJsonResponse(string $uri): void public function sseResponseProvider(): array { $files = []; - $files[] = ['_unit-test/sse.php?' . Callback::CALLBACK_TRIGGER_PREFIX . 'see_test=ajax&__atk_callback=1&__atk_sse=1']; - $files[] = ['_unit-test/console.php?' . Callback::CALLBACK_TRIGGER_PREFIX . 'console_test=ajax&__atk_callback=1&__atk_sse=1']; + $files[] = ['_unit-test/sse.php?see_test=ajax&__atk_callback=1&__atk_sse=1']; + $files[] = ['_unit-test/console.php?console_test=ajax&__atk_callback=1&__atk_sse=1']; if (!($this instanceof DemosHttpNoExitTest)) { // ignore content type mismatch when App->call_exit equals to true - $files[] = ['_unit-test/console_run.php?' . Callback::CALLBACK_TRIGGER_PREFIX . 'console_test=ajax&__atk_callback=1&__atk_sse=1']; - $files[] = ['_unit-test/console_exec.php?' . Callback::CALLBACK_TRIGGER_PREFIX . 'console_test=ajax&__atk_callback=1&__atk_sse=1']; + $files[] = ['_unit-test/console_run.php?console_test=ajax&__atk_callback=1&__atk_sse=1']; + $files[] = ['_unit-test/console_exec.php?console_test=ajax&__atk_callback=1&__atk_sse=1']; } return $files; @@ -434,7 +433,7 @@ public function jsonResponsePostProvider(): array { $files = []; $files[] = [ - '_unit-test/post.php?' . Callback::CALLBACK_TRIGGER_PREFIX . 'test_submit=ajax&__atk_callback=test_submit', + '_unit-test/post.php?test_submit=ajax&__atk_callback=test_submit', [ 'f1' => 'v1', ], @@ -442,7 +441,7 @@ public function jsonResponsePostProvider(): array // for JsNotify coverage $files[] = [ - 'obsolete/notify2.php?' . Callback::CALLBACK_TRIGGER_PREFIX . 'test_notify=ajax&__atk_callback=test_notify', + 'obsolete/notify2.php?test_notify=ajax&__atk_callback=test_notify', [ 'text' => 'This text will appear in notification', 'icon' => 'warning sign', diff --git a/tests/FormTest.php b/tests/FormTest.php index 5c9191fd8b..2205385982 100644 --- a/tests/FormTest.php +++ b/tests/FormTest.php @@ -7,7 +7,6 @@ use Atk4\Core\Phpunit\TestCase; use Atk4\Data\Model; use Atk4\Ui\App; -use Atk4\Ui\Callback; use Atk4\Ui\Form; class FormTest extends TestCase @@ -48,7 +47,7 @@ public function assertSubmit(array $post_data, \Closure $submit = null, \Closure $submit_called = false; $_POST = $post_data; // trigger callback - $_GET[Callback::CALLBACK_TRIGGER_PREFIX . 'atk_submit'] = 'ajax'; + $_GET['atk_submit'] = 'ajax'; $_GET['__atk_callback'] = 'atk_submit'; $this->f->onSubmit(function (Form $form) use (&$submit_called, $submit) { From be4d2df1475ee1b6cca2e4e407f4aefa6f2b231f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Wed, 21 Jul 2021 22:34:59 +0200 Subject: [PATCH 21/25] fix callback test --- tests/CallbackTest.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/CallbackTest.php b/tests/CallbackTest.php index 76292de16c..0315c4bc40 100644 --- a/tests/CallbackTest.php +++ b/tests/CallbackTest.php @@ -37,8 +37,10 @@ protected function setUp(): void { $this->app = new AppMock(['always_run' => false, 'catch_exceptions' => false]); $this->app->initLayout([\Atk4\Ui\Layout\Centered::class]); + } - // reset var, between tests + protected function tearDown(): void + { $_GET = []; $_POST = []; } @@ -77,7 +79,7 @@ public function testViewUrlCallback(): void $cb = \Atk4\Ui\Callback::addTo($v1); // simulate triggering - $_GET[Callback::CALLBACK_TRIGGER_PREFIX . $cb->name] = '1'; + $_GET[$cb->name] = '1'; $cb->set(function ($x) use (&$var, $v1) { $v3 = \Atk4\Ui\View::addTo($v1); From d017be7ffd826db478da66108712cd148a98d215 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Wed, 21 Jul 2021 23:00:42 +0200 Subject: [PATCH 22/25] use trigger prefix --- src/AbstractView.php | 1 - src/Callback.php | 8 +++++--- src/View.php | 2 +- tests/CallbackTest.php | 16 ++++++++-------- tests/DemosTest.php | 21 +++++++++++---------- tests/FormTest.php | 3 ++- 6 files changed, 27 insertions(+), 24 deletions(-) diff --git a/src/AbstractView.php b/src/AbstractView.php index 41dbd4b8aa..a2e3e7fc4b 100644 --- a/src/AbstractView.php +++ b/src/AbstractView.php @@ -52,7 +52,6 @@ abstract class AbstractView * @var bool */ protected $_rendered = false; - // }}} // {{{ Default init() method and add() logic diff --git a/src/Callback.php b/src/Callback.php index 384d26fab2..6076df61bb 100644 --- a/src/Callback.php +++ b/src/Callback.php @@ -22,6 +22,8 @@ */ class Callback extends AbstractView { + public const CALLBACK_TRIGGER_PREFIX = '__atkcb_'; + /** @var string Specify a custom GET trigger. */ protected $urlTrigger; @@ -82,7 +84,7 @@ public function terminateJson(AbstractView $view): void */ public function isTriggered() { - return isset($_GET[$this->urlTrigger]); + return isset($_GET[self::CALLBACK_TRIGGER_PREFIX . $this->urlTrigger]); } /** @@ -90,7 +92,7 @@ public function isTriggered() */ public function getTriggeredValue(): string { - return $_GET[$this->urlTrigger] ?? ''; + return $_GET[self::CALLBACK_TRIGGER_PREFIX . $this->urlTrigger] ?? ''; } /** @@ -133,6 +135,6 @@ public function getUrl(string $value = 'callback'): string */ private function getUrlArguments(string $value = null): array { - return ['__atk_callback' => $this->urlTrigger, $this->urlTrigger => $value ?? $this->getTriggeredValue()]; + return ['__atk_callback' => $this->urlTrigger, self::CALLBACK_TRIGGER_PREFIX . $this->urlTrigger => $value ?? $this->getTriggeredValue()]; } } diff --git a/src/View.php b/src/View.php index 4b6c17b9e6..174036890f 100644 --- a/src/View.php +++ b/src/View.php @@ -40,7 +40,7 @@ class View extends AbstractView implements JsExpressionable * * @var string */ - public $region; //'Content'; + public $region; /** * Enables UI keyword for Semantic UI indicating that this is a diff --git a/tests/CallbackTest.php b/tests/CallbackTest.php index 0315c4bc40..e81d8f6d1d 100644 --- a/tests/CallbackTest.php +++ b/tests/CallbackTest.php @@ -52,7 +52,7 @@ public function testCallback(): void $cb = \Atk4\Ui\Callback::addTo($this->app); // simulate triggering - $_GET[$cb->name] = '1'; + $_GET[Callback::CALLBACK_TRIGGER_PREFIX . $cb->name] = '1'; $cb->set(function ($x) use (&$var) { $var = $x; @@ -79,7 +79,7 @@ public function testViewUrlCallback(): void $cb = \Atk4\Ui\Callback::addTo($v1); // simulate triggering - $_GET[$cb->name] = '1'; + $_GET[Callback::CALLBACK_TRIGGER_PREFIX . $cb->name] = '1'; $cb->set(function ($x) use (&$var, $v1) { $v3 = \Atk4\Ui\View::addTo($v1); @@ -115,7 +115,7 @@ public function testCallbackLater(): void $cb = \Atk4\Ui\CallbackLater::addTo($this->app); // simulate triggering - $_GET[$cb->name] = '1'; + $_GET[Callback::CALLBACK_TRIGGER_PREFIX . $cb->name] = '1'; $cb->set(function ($x) use (&$var) { $var = $x; @@ -136,8 +136,8 @@ public function testCallbackLaterNested(): void $cb = \Atk4\Ui\CallbackLater::addTo($this->app); // simulate triggering - $_GET[$cb->name] = '1'; - $_GET[$cb->name . '_2'] = '1'; + $_GET[Callback::CALLBACK_TRIGGER_PREFIX . $cb->name] = '1'; + $_GET[Callback::CALLBACK_TRIGGER_PREFIX . $cb->name . '_2'] = '1'; $app = $this->app; $cb->set(function ($x) use (&$var, $app, &$cbname) { @@ -182,7 +182,7 @@ public function testVirtualPage(): void $vp = \Atk4\Ui\VirtualPage::addTo($this->app); // simulate triggering - $_GET[$vp->name] = '1'; + $_GET[Callback::CALLBACK_TRIGGER_PREFIX . $vp->name] = '1'; $vp->set(function ($p) use (&$var) { $var = 25; @@ -200,7 +200,7 @@ public function testVirtualPageCustomTrigger(): void $vp = \Atk4\Ui\VirtualPage::addTo($this->app, ['urlTrigger' => 'bah']); // simulate triggering - $_GET['bah'] = '1'; + $_GET[Callback::CALLBACK_TRIGGER_PREFIX . 'bah'] = '1'; $vp->set(function ($p) use (&$var) { $var = 25; @@ -225,7 +225,7 @@ public function testPull230(): void $vp = \Atk4\Ui\VirtualPage::addTo($this->app); // simulate triggering - $_GET[$vp->name] = '1'; + $_GET[Callback::CALLBACK_TRIGGER_PREFIX . $vp->name] = '1'; $vp->set(\Closure::fromCallable([$this, 'callPull230'])); diff --git a/tests/DemosTest.php b/tests/DemosTest.php index 4d7af1891c..ff25b39a4f 100644 --- a/tests/DemosTest.php +++ b/tests/DemosTest.php @@ -7,6 +7,7 @@ use Atk4\Core\Phpunit\TestCase; use Atk4\Data\Persistence; use Atk4\Ui\App; +use Atk4\Ui\Callback; use GuzzleHttp\Client; use GuzzleHttp\Psr7\Request; use Psr\Http\Message\RequestInterface; @@ -327,7 +328,7 @@ public function testWizard(): void } $response = $this->getResponseFromRequest( - 'interactive/wizard.php?demo_wizard=1&w_form_submit=ajax&__atk_callback=w_form_submit', + 'interactive/wizard.php?demo_wizard=1&' . Callback::CALLBACK_TRIGGER_PREFIX . 'w_form_submit=ajax&__atk_callback=w_form_submit', ['form_params' => [ 'dsn' => 'mysql://root:root@db-host.example.com/atk4', ]] @@ -350,10 +351,10 @@ public function jsonResponseProvider(): array // simple reload $files[] = ['_unit-test/reload.php?__atk_reload=reload']; // loader callback reload - $files[] = ['_unit-test/reload.php?c_reload=ajax&__atk_callback=c_reload']; + $files[] = ['_unit-test/reload.php?' . Callback::CALLBACK_TRIGGER_PREFIX . 'c_reload=ajax&__atk_callback=c_reload']; // test catch exceptions - $files[] = ['_unit-test/exception.php?m_cb=ajax&__atk_callback=m_cb&__atk_json=1']; - $files[] = ['_unit-test/exception.php?m2_cb=ajax&__atk_callback=m2_cb&__atk_json=1']; + $files[] = ['_unit-test/exception.php?' . Callback::CALLBACK_TRIGGER_PREFIX . 'm_cb=ajax&__atk_callback=m_cb&__atk_json=1']; + $files[] = ['_unit-test/exception.php?' . Callback::CALLBACK_TRIGGER_PREFIX . 'm2_cb=ajax&__atk_callback=m2_cb&__atk_json=1']; return $files; } @@ -383,11 +384,11 @@ public function testDemoAssertJsonResponse(string $uri): void public function sseResponseProvider(): array { $files = []; - $files[] = ['_unit-test/sse.php?see_test=ajax&__atk_callback=1&__atk_sse=1']; - $files[] = ['_unit-test/console.php?console_test=ajax&__atk_callback=1&__atk_sse=1']; + $files[] = ['_unit-test/sse.php?' . Callback::CALLBACK_TRIGGER_PREFIX . 'see_test=ajax&__atk_callback=1&__atk_sse=1']; + $files[] = ['_unit-test/console.php?' . Callback::CALLBACK_TRIGGER_PREFIX . 'console_test=ajax&__atk_callback=1&__atk_sse=1']; if (!($this instanceof DemosHttpNoExitTest)) { // ignore content type mismatch when App->call_exit equals to true - $files[] = ['_unit-test/console_run.php?console_test=ajax&__atk_callback=1&__atk_sse=1']; - $files[] = ['_unit-test/console_exec.php?console_test=ajax&__atk_callback=1&__atk_sse=1']; + $files[] = ['_unit-test/console_run.php?' . Callback::CALLBACK_TRIGGER_PREFIX . 'console_test=ajax&__atk_callback=1&__atk_sse=1']; + $files[] = ['_unit-test/console_exec.php?' . Callback::CALLBACK_TRIGGER_PREFIX . 'console_test=ajax&__atk_callback=1&__atk_sse=1']; } return $files; @@ -433,7 +434,7 @@ public function jsonResponsePostProvider(): array { $files = []; $files[] = [ - '_unit-test/post.php?test_submit=ajax&__atk_callback=test_submit', + '_unit-test/post.php?' . Callback::CALLBACK_TRIGGER_PREFIX . 'test_submit=ajax&__atk_callback=test_submit', [ 'f1' => 'v1', ], @@ -441,7 +442,7 @@ public function jsonResponsePostProvider(): array // for JsNotify coverage $files[] = [ - 'obsolete/notify2.php?test_notify=ajax&__atk_callback=test_notify', + 'obsolete/notify2.php?' . Callback::CALLBACK_TRIGGER_PREFIX . 'test_notify=ajax&__atk_callback=test_notify', [ 'text' => 'This text will appear in notification', 'icon' => 'warning sign', diff --git a/tests/FormTest.php b/tests/FormTest.php index 2205385982..5c9191fd8b 100644 --- a/tests/FormTest.php +++ b/tests/FormTest.php @@ -7,6 +7,7 @@ use Atk4\Core\Phpunit\TestCase; use Atk4\Data\Model; use Atk4\Ui\App; +use Atk4\Ui\Callback; use Atk4\Ui\Form; class FormTest extends TestCase @@ -47,7 +48,7 @@ public function assertSubmit(array $post_data, \Closure $submit = null, \Closure $submit_called = false; $_POST = $post_data; // trigger callback - $_GET['atk_submit'] = 'ajax'; + $_GET[Callback::CALLBACK_TRIGGER_PREFIX . 'atk_submit'] = 'ajax'; $_GET['__atk_callback'] = 'atk_submit'; $this->f->onSubmit(function (Form $form) use (&$submit_called, $submit) { From 56bb9c0c6c9cb51c839d8413b3a7a3a9cbb3e589 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Wed, 21 Jul 2021 23:00:53 +0200 Subject: [PATCH 23/25] rename trigger const --- src/Callback.php | 8 ++++---- tests/CallbackTest.php | 16 ++++++++-------- tests/DemosTest.php | 20 ++++++++++---------- tests/FormTest.php | 2 +- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/Callback.php b/src/Callback.php index 6076df61bb..7a855b967e 100644 --- a/src/Callback.php +++ b/src/Callback.php @@ -22,7 +22,7 @@ */ class Callback extends AbstractView { - public const CALLBACK_TRIGGER_PREFIX = '__atkcb_'; + public const URL_TRIGGER_PREFIX = '__atkcb_'; /** @var string Specify a custom GET trigger. */ protected $urlTrigger; @@ -84,7 +84,7 @@ public function terminateJson(AbstractView $view): void */ public function isTriggered() { - return isset($_GET[self::CALLBACK_TRIGGER_PREFIX . $this->urlTrigger]); + return isset($_GET[self::URL_TRIGGER_PREFIX . $this->urlTrigger]); } /** @@ -92,7 +92,7 @@ public function isTriggered() */ public function getTriggeredValue(): string { - return $_GET[self::CALLBACK_TRIGGER_PREFIX . $this->urlTrigger] ?? ''; + return $_GET[self::URL_TRIGGER_PREFIX . $this->urlTrigger] ?? ''; } /** @@ -135,6 +135,6 @@ public function getUrl(string $value = 'callback'): string */ private function getUrlArguments(string $value = null): array { - return ['__atk_callback' => $this->urlTrigger, self::CALLBACK_TRIGGER_PREFIX . $this->urlTrigger => $value ?? $this->getTriggeredValue()]; + return ['__atk_callback' => $this->urlTrigger, self::URL_TRIGGER_PREFIX . $this->urlTrigger => $value ?? $this->getTriggeredValue()]; } } diff --git a/tests/CallbackTest.php b/tests/CallbackTest.php index e81d8f6d1d..93b33c5c95 100644 --- a/tests/CallbackTest.php +++ b/tests/CallbackTest.php @@ -52,7 +52,7 @@ public function testCallback(): void $cb = \Atk4\Ui\Callback::addTo($this->app); // simulate triggering - $_GET[Callback::CALLBACK_TRIGGER_PREFIX . $cb->name] = '1'; + $_GET[Callback::URL_TRIGGER_PREFIX . $cb->name] = '1'; $cb->set(function ($x) use (&$var) { $var = $x; @@ -79,7 +79,7 @@ public function testViewUrlCallback(): void $cb = \Atk4\Ui\Callback::addTo($v1); // simulate triggering - $_GET[Callback::CALLBACK_TRIGGER_PREFIX . $cb->name] = '1'; + $_GET[Callback::URL_TRIGGER_PREFIX . $cb->name] = '1'; $cb->set(function ($x) use (&$var, $v1) { $v3 = \Atk4\Ui\View::addTo($v1); @@ -115,7 +115,7 @@ public function testCallbackLater(): void $cb = \Atk4\Ui\CallbackLater::addTo($this->app); // simulate triggering - $_GET[Callback::CALLBACK_TRIGGER_PREFIX . $cb->name] = '1'; + $_GET[Callback::URL_TRIGGER_PREFIX . $cb->name] = '1'; $cb->set(function ($x) use (&$var) { $var = $x; @@ -136,8 +136,8 @@ public function testCallbackLaterNested(): void $cb = \Atk4\Ui\CallbackLater::addTo($this->app); // simulate triggering - $_GET[Callback::CALLBACK_TRIGGER_PREFIX . $cb->name] = '1'; - $_GET[Callback::CALLBACK_TRIGGER_PREFIX . $cb->name . '_2'] = '1'; + $_GET[Callback::URL_TRIGGER_PREFIX . $cb->name] = '1'; + $_GET[Callback::URL_TRIGGER_PREFIX . $cb->name . '_2'] = '1'; $app = $this->app; $cb->set(function ($x) use (&$var, $app, &$cbname) { @@ -182,7 +182,7 @@ public function testVirtualPage(): void $vp = \Atk4\Ui\VirtualPage::addTo($this->app); // simulate triggering - $_GET[Callback::CALLBACK_TRIGGER_PREFIX . $vp->name] = '1'; + $_GET[Callback::URL_TRIGGER_PREFIX . $vp->name] = '1'; $vp->set(function ($p) use (&$var) { $var = 25; @@ -200,7 +200,7 @@ public function testVirtualPageCustomTrigger(): void $vp = \Atk4\Ui\VirtualPage::addTo($this->app, ['urlTrigger' => 'bah']); // simulate triggering - $_GET[Callback::CALLBACK_TRIGGER_PREFIX . 'bah'] = '1'; + $_GET[Callback::URL_TRIGGER_PREFIX . 'bah'] = '1'; $vp->set(function ($p) use (&$var) { $var = 25; @@ -225,7 +225,7 @@ public function testPull230(): void $vp = \Atk4\Ui\VirtualPage::addTo($this->app); // simulate triggering - $_GET[Callback::CALLBACK_TRIGGER_PREFIX . $vp->name] = '1'; + $_GET[Callback::URL_TRIGGER_PREFIX . $vp->name] = '1'; $vp->set(\Closure::fromCallable([$this, 'callPull230'])); diff --git a/tests/DemosTest.php b/tests/DemosTest.php index ff25b39a4f..6497cfd977 100644 --- a/tests/DemosTest.php +++ b/tests/DemosTest.php @@ -328,7 +328,7 @@ public function testWizard(): void } $response = $this->getResponseFromRequest( - 'interactive/wizard.php?demo_wizard=1&' . Callback::CALLBACK_TRIGGER_PREFIX . 'w_form_submit=ajax&__atk_callback=w_form_submit', + 'interactive/wizard.php?demo_wizard=1&' . Callback::URL_TRIGGER_PREFIX . 'w_form_submit=ajax&__atk_callback=w_form_submit', ['form_params' => [ 'dsn' => 'mysql://root:root@db-host.example.com/atk4', ]] @@ -351,10 +351,10 @@ public function jsonResponseProvider(): array // simple reload $files[] = ['_unit-test/reload.php?__atk_reload=reload']; // loader callback reload - $files[] = ['_unit-test/reload.php?' . Callback::CALLBACK_TRIGGER_PREFIX . 'c_reload=ajax&__atk_callback=c_reload']; + $files[] = ['_unit-test/reload.php?' . Callback::URL_TRIGGER_PREFIX . 'c_reload=ajax&__atk_callback=c_reload']; // test catch exceptions - $files[] = ['_unit-test/exception.php?' . Callback::CALLBACK_TRIGGER_PREFIX . 'm_cb=ajax&__atk_callback=m_cb&__atk_json=1']; - $files[] = ['_unit-test/exception.php?' . Callback::CALLBACK_TRIGGER_PREFIX . 'm2_cb=ajax&__atk_callback=m2_cb&__atk_json=1']; + $files[] = ['_unit-test/exception.php?' . Callback::URL_TRIGGER_PREFIX . 'm_cb=ajax&__atk_callback=m_cb&__atk_json=1']; + $files[] = ['_unit-test/exception.php?' . Callback::URL_TRIGGER_PREFIX . 'm2_cb=ajax&__atk_callback=m2_cb&__atk_json=1']; return $files; } @@ -384,11 +384,11 @@ public function testDemoAssertJsonResponse(string $uri): void public function sseResponseProvider(): array { $files = []; - $files[] = ['_unit-test/sse.php?' . Callback::CALLBACK_TRIGGER_PREFIX . 'see_test=ajax&__atk_callback=1&__atk_sse=1']; - $files[] = ['_unit-test/console.php?' . Callback::CALLBACK_TRIGGER_PREFIX . 'console_test=ajax&__atk_callback=1&__atk_sse=1']; + $files[] = ['_unit-test/sse.php?' . Callback::URL_TRIGGER_PREFIX . 'see_test=ajax&__atk_callback=1&__atk_sse=1']; + $files[] = ['_unit-test/console.php?' . Callback::URL_TRIGGER_PREFIX . 'console_test=ajax&__atk_callback=1&__atk_sse=1']; if (!($this instanceof DemosHttpNoExitTest)) { // ignore content type mismatch when App->call_exit equals to true - $files[] = ['_unit-test/console_run.php?' . Callback::CALLBACK_TRIGGER_PREFIX . 'console_test=ajax&__atk_callback=1&__atk_sse=1']; - $files[] = ['_unit-test/console_exec.php?' . Callback::CALLBACK_TRIGGER_PREFIX . 'console_test=ajax&__atk_callback=1&__atk_sse=1']; + $files[] = ['_unit-test/console_run.php?' . Callback::URL_TRIGGER_PREFIX . 'console_test=ajax&__atk_callback=1&__atk_sse=1']; + $files[] = ['_unit-test/console_exec.php?' . Callback::URL_TRIGGER_PREFIX . 'console_test=ajax&__atk_callback=1&__atk_sse=1']; } return $files; @@ -434,7 +434,7 @@ public function jsonResponsePostProvider(): array { $files = []; $files[] = [ - '_unit-test/post.php?' . Callback::CALLBACK_TRIGGER_PREFIX . 'test_submit=ajax&__atk_callback=test_submit', + '_unit-test/post.php?' . Callback::URL_TRIGGER_PREFIX . 'test_submit=ajax&__atk_callback=test_submit', [ 'f1' => 'v1', ], @@ -442,7 +442,7 @@ public function jsonResponsePostProvider(): array // for JsNotify coverage $files[] = [ - 'obsolete/notify2.php?' . Callback::CALLBACK_TRIGGER_PREFIX . 'test_notify=ajax&__atk_callback=test_notify', + 'obsolete/notify2.php?' . Callback::URL_TRIGGER_PREFIX . 'test_notify=ajax&__atk_callback=test_notify', [ 'text' => 'This text will appear in notification', 'icon' => 'warning sign', diff --git a/tests/FormTest.php b/tests/FormTest.php index 5c9191fd8b..7532624d9a 100644 --- a/tests/FormTest.php +++ b/tests/FormTest.php @@ -48,7 +48,7 @@ public function assertSubmit(array $post_data, \Closure $submit = null, \Closure $submit_called = false; $_POST = $post_data; // trigger callback - $_GET[Callback::CALLBACK_TRIGGER_PREFIX . 'atk_submit'] = 'ajax'; + $_GET[Callback::URL_TRIGGER_PREFIX . 'atk_submit'] = 'ajax'; $_GET['__atk_callback'] = 'atk_submit'; $this->f->onSubmit(function (Form $form) use (&$submit_called, $submit) { From a8d8e4fd2f8b1cf62634b54768423077deabf87f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Wed, 21 Jul 2021 23:15:09 +0200 Subject: [PATCH 24/25] use constants for callback query names --- src/App.php | 5 +++-- src/Callback.php | 18 +++++++++++------- tests/CallbackTest.php | 16 ++++++++-------- tests/DemosTest.php | 20 ++++++++++---------- tests/FormTest.php | 4 ++-- 5 files changed, 34 insertions(+), 29 deletions(-) diff --git a/src/App.php b/src/App.php index 901f673e79..c4b182578e 100644 --- a/src/App.php +++ b/src/App.php @@ -12,6 +12,7 @@ use Atk4\Core\InitializerTrait; use Atk4\Data\Persistence; use Atk4\Ui\Exception\ExitApplicationException; +use Atk4\Ui\Callback; use Atk4\Ui\Persistence\Ui as UiPersistence; use Atk4\Ui\UserAction\ExecutorFactory; use Psr\Log\LoggerInterface; @@ -567,9 +568,9 @@ public function run() $this->is_rendering = false; $this->hook(self::HOOK_BEFORE_OUTPUT); - if (isset($_GET['__atk_callback']) && $this->catch_runaway_callbacks) { + if (isset($_GET[Callback::URL_QUERY_TARGET]) && $this->catch_runaway_callbacks) { throw (new Exception('Callback requested, but never reached. You may be missing some arguments in request URL.')) - ->addMoreInfo('callback', $_GET['__atk_callback']); + ->addMoreInfo('callback', $_GET[Callback::URL_QUERY_TARGET]); } $output = $this->html->template->renderToHtml(); diff --git a/src/Callback.php b/src/Callback.php index 7a855b967e..bfb7a327a8 100644 --- a/src/Callback.php +++ b/src/Callback.php @@ -9,7 +9,7 @@ * executed directly will perform a PHP callback that you set(). * * Callback function run when triggered, i.e. when it's urlTrigger param value is present in the $_GET request. - * The current callback will be set within the $_GET['__atk_callback'] and will be set to urlTrigger as well. + * The current callback will be set within the $_GET[Callback::URL_QUERY_TARGET] and will be set to urlTrigger as well. * * $button = Button::addTo($layout); * $button->set('Click to do something')->link( @@ -22,7 +22,11 @@ */ class Callback extends AbstractView { - public const URL_TRIGGER_PREFIX = '__atkcb_'; + /** @const string */ + public const URL_QUERY_TRIGGER_PREFIX = '__atk_cb_'; + + /** @const string */ + public const URL_QUERY_TARGET = '__atk_cbtarget'; /** @var string Specify a custom GET trigger. */ protected $urlTrigger; @@ -46,7 +50,7 @@ public function setUrlTrigger(string $trigger = null) { $this->urlTrigger = $trigger ?: $this->name; - $this->getOwner()->stickyGet($this->urlTrigger); + $this->getOwner()->stickyGet(self::URL_QUERY_TRIGGER_PREFIX . $this->urlTrigger); } public function getUrlTrigger(): string @@ -84,7 +88,7 @@ public function terminateJson(AbstractView $view): void */ public function isTriggered() { - return isset($_GET[self::URL_TRIGGER_PREFIX . $this->urlTrigger]); + return isset($_GET[self::URL_QUERY_TRIGGER_PREFIX . $this->urlTrigger]); } /** @@ -92,7 +96,7 @@ public function isTriggered() */ public function getTriggeredValue(): string { - return $_GET[self::URL_TRIGGER_PREFIX . $this->urlTrigger] ?? ''; + return $_GET[self::URL_QUERY_TRIGGER_PREFIX . $this->urlTrigger] ?? ''; } /** @@ -100,7 +104,7 @@ public function getTriggeredValue(): string */ public function canTerminate(): bool { - return isset($_GET['__atk_callback']) && $_GET['__atk_callback'] === $this->urlTrigger; + return isset($_GET[self::URL_QUERY_TARGET]) && $_GET[self::URL_QUERY_TARGET] === $this->urlTrigger; } /** @@ -135,6 +139,6 @@ public function getUrl(string $value = 'callback'): string */ private function getUrlArguments(string $value = null): array { - return ['__atk_callback' => $this->urlTrigger, self::URL_TRIGGER_PREFIX . $this->urlTrigger => $value ?? $this->getTriggeredValue()]; + return [self::URL_QUERY_TARGET => $this->urlTrigger, self::URL_QUERY_TRIGGER_PREFIX . $this->urlTrigger => $value ?? $this->getTriggeredValue()]; } } diff --git a/tests/CallbackTest.php b/tests/CallbackTest.php index 93b33c5c95..05774315df 100644 --- a/tests/CallbackTest.php +++ b/tests/CallbackTest.php @@ -52,7 +52,7 @@ public function testCallback(): void $cb = \Atk4\Ui\Callback::addTo($this->app); // simulate triggering - $_GET[Callback::URL_TRIGGER_PREFIX . $cb->name] = '1'; + $_GET[Callback::URL_QUERY_TRIGGER_PREFIX . $cb->name] = '1'; $cb->set(function ($x) use (&$var) { $var = $x; @@ -79,7 +79,7 @@ public function testViewUrlCallback(): void $cb = \Atk4\Ui\Callback::addTo($v1); // simulate triggering - $_GET[Callback::URL_TRIGGER_PREFIX . $cb->name] = '1'; + $_GET[Callback::URL_QUERY_TRIGGER_PREFIX . $cb->name] = '1'; $cb->set(function ($x) use (&$var, $v1) { $v3 = \Atk4\Ui\View::addTo($v1); @@ -115,7 +115,7 @@ public function testCallbackLater(): void $cb = \Atk4\Ui\CallbackLater::addTo($this->app); // simulate triggering - $_GET[Callback::URL_TRIGGER_PREFIX . $cb->name] = '1'; + $_GET[Callback::URL_QUERY_TRIGGER_PREFIX . $cb->name] = '1'; $cb->set(function ($x) use (&$var) { $var = $x; @@ -136,8 +136,8 @@ public function testCallbackLaterNested(): void $cb = \Atk4\Ui\CallbackLater::addTo($this->app); // simulate triggering - $_GET[Callback::URL_TRIGGER_PREFIX . $cb->name] = '1'; - $_GET[Callback::URL_TRIGGER_PREFIX . $cb->name . '_2'] = '1'; + $_GET[Callback::URL_QUERY_TRIGGER_PREFIX . $cb->name] = '1'; + $_GET[Callback::URL_QUERY_TRIGGER_PREFIX . $cb->name . '_2'] = '1'; $app = $this->app; $cb->set(function ($x) use (&$var, $app, &$cbname) { @@ -182,7 +182,7 @@ public function testVirtualPage(): void $vp = \Atk4\Ui\VirtualPage::addTo($this->app); // simulate triggering - $_GET[Callback::URL_TRIGGER_PREFIX . $vp->name] = '1'; + $_GET[Callback::URL_QUERY_TRIGGER_PREFIX . $vp->name] = '1'; $vp->set(function ($p) use (&$var) { $var = 25; @@ -200,7 +200,7 @@ public function testVirtualPageCustomTrigger(): void $vp = \Atk4\Ui\VirtualPage::addTo($this->app, ['urlTrigger' => 'bah']); // simulate triggering - $_GET[Callback::URL_TRIGGER_PREFIX . 'bah'] = '1'; + $_GET[Callback::URL_QUERY_TRIGGER_PREFIX . 'bah'] = '1'; $vp->set(function ($p) use (&$var) { $var = 25; @@ -225,7 +225,7 @@ public function testPull230(): void $vp = \Atk4\Ui\VirtualPage::addTo($this->app); // simulate triggering - $_GET[Callback::URL_TRIGGER_PREFIX . $vp->name] = '1'; + $_GET[Callback::URL_QUERY_TRIGGER_PREFIX . $vp->name] = '1'; $vp->set(\Closure::fromCallable([$this, 'callPull230'])); diff --git a/tests/DemosTest.php b/tests/DemosTest.php index 6497cfd977..c7a5328173 100644 --- a/tests/DemosTest.php +++ b/tests/DemosTest.php @@ -328,7 +328,7 @@ public function testWizard(): void } $response = $this->getResponseFromRequest( - 'interactive/wizard.php?demo_wizard=1&' . Callback::URL_TRIGGER_PREFIX . 'w_form_submit=ajax&__atk_callback=w_form_submit', + 'interactive/wizard.php?demo_wizard=1&' . Callback::URL_QUERY_TRIGGER_PREFIX . 'w_form_submit=ajax&' . Callback::URL_QUERY_TARGET . '=w_form_submit', ['form_params' => [ 'dsn' => 'mysql://root:root@db-host.example.com/atk4', ]] @@ -351,10 +351,10 @@ public function jsonResponseProvider(): array // simple reload $files[] = ['_unit-test/reload.php?__atk_reload=reload']; // loader callback reload - $files[] = ['_unit-test/reload.php?' . Callback::URL_TRIGGER_PREFIX . 'c_reload=ajax&__atk_callback=c_reload']; + $files[] = ['_unit-test/reload.php?' . Callback::URL_QUERY_TRIGGER_PREFIX . 'c_reload=ajax&' . Callback::URL_QUERY_TARGET . '=c_reload']; // test catch exceptions - $files[] = ['_unit-test/exception.php?' . Callback::URL_TRIGGER_PREFIX . 'm_cb=ajax&__atk_callback=m_cb&__atk_json=1']; - $files[] = ['_unit-test/exception.php?' . Callback::URL_TRIGGER_PREFIX . 'm2_cb=ajax&__atk_callback=m2_cb&__atk_json=1']; + $files[] = ['_unit-test/exception.php?' . Callback::URL_QUERY_TRIGGER_PREFIX . 'm_cb=ajax&' . Callback::URL_QUERY_TARGET . '=m_cb&__atk_json=1']; + $files[] = ['_unit-test/exception.php?' . Callback::URL_QUERY_TRIGGER_PREFIX . 'm2_cb=ajax&' . Callback::URL_QUERY_TARGET . '=m2_cb&__atk_json=1']; return $files; } @@ -384,11 +384,11 @@ public function testDemoAssertJsonResponse(string $uri): void public function sseResponseProvider(): array { $files = []; - $files[] = ['_unit-test/sse.php?' . Callback::URL_TRIGGER_PREFIX . 'see_test=ajax&__atk_callback=1&__atk_sse=1']; - $files[] = ['_unit-test/console.php?' . Callback::URL_TRIGGER_PREFIX . 'console_test=ajax&__atk_callback=1&__atk_sse=1']; + $files[] = ['_unit-test/sse.php?' . Callback::URL_QUERY_TRIGGER_PREFIX . 'see_test=ajax&' . Callback::URL_QUERY_TARGET . '=1&__atk_sse=1']; + $files[] = ['_unit-test/console.php?' . Callback::URL_QUERY_TRIGGER_PREFIX . 'console_test=ajax&' . Callback::URL_QUERY_TARGET . '=1&__atk_sse=1']; if (!($this instanceof DemosHttpNoExitTest)) { // ignore content type mismatch when App->call_exit equals to true - $files[] = ['_unit-test/console_run.php?' . Callback::URL_TRIGGER_PREFIX . 'console_test=ajax&__atk_callback=1&__atk_sse=1']; - $files[] = ['_unit-test/console_exec.php?' . Callback::URL_TRIGGER_PREFIX . 'console_test=ajax&__atk_callback=1&__atk_sse=1']; + $files[] = ['_unit-test/console_run.php?' . Callback::URL_QUERY_TRIGGER_PREFIX . 'console_test=ajax&' . Callback::URL_QUERY_TARGET . '=1&__atk_sse=1']; + $files[] = ['_unit-test/console_exec.php?' . Callback::URL_QUERY_TRIGGER_PREFIX . 'console_test=ajax&' . Callback::URL_QUERY_TARGET . '=1&__atk_sse=1']; } return $files; @@ -434,7 +434,7 @@ public function jsonResponsePostProvider(): array { $files = []; $files[] = [ - '_unit-test/post.php?' . Callback::URL_TRIGGER_PREFIX . 'test_submit=ajax&__atk_callback=test_submit', + '_unit-test/post.php?' . Callback::URL_QUERY_TRIGGER_PREFIX . 'test_submit=ajax&' . Callback::URL_QUERY_TARGET . '=test_submit', [ 'f1' => 'v1', ], @@ -442,7 +442,7 @@ public function jsonResponsePostProvider(): array // for JsNotify coverage $files[] = [ - 'obsolete/notify2.php?' . Callback::URL_TRIGGER_PREFIX . 'test_notify=ajax&__atk_callback=test_notify', + 'obsolete/notify2.php?' . Callback::URL_QUERY_TRIGGER_PREFIX . 'test_notify=ajax&' . Callback::URL_QUERY_TARGET . '=test_notify', [ 'text' => 'This text will appear in notification', 'icon' => 'warning sign', diff --git a/tests/FormTest.php b/tests/FormTest.php index 7532624d9a..ab968a129d 100644 --- a/tests/FormTest.php +++ b/tests/FormTest.php @@ -48,8 +48,8 @@ public function assertSubmit(array $post_data, \Closure $submit = null, \Closure $submit_called = false; $_POST = $post_data; // trigger callback - $_GET[Callback::URL_TRIGGER_PREFIX . 'atk_submit'] = 'ajax'; - $_GET['__atk_callback'] = 'atk_submit'; + $_GET[Callback::URL_QUERY_TRIGGER_PREFIX . 'atk_submit'] = 'ajax'; + $_GET[Callback::URL_QUERY_TARGET] = 'atk_submit'; $this->f->onSubmit(function (Form $form) use (&$submit_called, $submit) { $submit_called = true; From c925c5ff4f59aa05fa93629e37d1ac4b7d3e3376 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Wed, 21 Jul 2021 23:18:43 +0200 Subject: [PATCH 25/25] fix cs - import not needed, same NS --- src/App.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/App.php b/src/App.php index c4b182578e..86404154ee 100644 --- a/src/App.php +++ b/src/App.php @@ -12,7 +12,6 @@ use Atk4\Core\InitializerTrait; use Atk4\Data\Persistence; use Atk4\Ui\Exception\ExitApplicationException; -use Atk4\Ui\Callback; use Atk4\Ui\Persistence\Ui as UiPersistence; use Atk4\Ui\UserAction\ExecutorFactory; use Psr\Log\LoggerInterface;