From dac290038e38195606550ce2c867d30179e7d670 Mon Sep 17 00:00:00 2001 From: Alain Belair Date: Thu, 13 Jun 2024 16:02:33 -0400 Subject: [PATCH] fix Get param --- app-test/_unit-test/table-filter.php | 2 +- src/Callback/Request.php | 8 ++++---- src/Service/Ui.php | 14 +++----------- src/Service/UiInterface.php | 2 +- src/View.php | 2 +- tests/Callback/CallbackTest.php | 5 +++-- 6 files changed, 13 insertions(+), 20 deletions(-) diff --git a/app-test/_unit-test/table-filter.php b/app-test/_unit-test/table-filter.php index 5053790..a31b817 100644 --- a/app-test/_unit-test/table-filter.php +++ b/app-test/_unit-test/table-filter.php @@ -11,7 +11,7 @@ require_once __DIR__ . '/../init-ui.php'; -if ($locale = Ui::getQueryParamValue('locale')) { +if ($locale = Ui::service()->getQueryParamValue('locale')) { \Fohn\Ui\Component\Utils::requireFLatPickrLocale(\Fohn\Ui\Service\Ui::page(), $locale); } diff --git a/src/Callback/Request.php b/src/Callback/Request.php index 0eb0ba1..8472103 100644 --- a/src/Callback/Request.php +++ b/src/Callback/Request.php @@ -113,7 +113,7 @@ protected function assertSafeRequest(): void */ public function isTriggered(): bool { - return (Ui::getQueryParamValue($this->urlTrigger) !== null) && $this->getTriggeredValue() === $this->type; + return (Ui::service()->getQueryParamValue($this->urlTrigger) !== null) && $this->getTriggeredValue() === $this->type; } /** @@ -121,7 +121,7 @@ public function isTriggered(): bool */ public function getTriggeredValue(): string { - return Ui::getQueryParamValue($this->urlTrigger) ?? ''; + return Ui::service()->getQueryParamValue($this->urlTrigger) ?? ''; } /** @@ -129,7 +129,7 @@ public function getTriggeredValue(): string */ public function canTerminate(): bool { - return (Ui::getQueryParamValue(static::URL_QUERY_TARGET) !== null) && Ui::getQueryParamValue(static::URL_QUERY_TARGET) === $this->urlTrigger; + return (Ui::service()->getQueryParamValue(static::URL_QUERY_TARGET) !== null) && Ui::service()->getQueryParamValue(static::URL_QUERY_TARGET) === $this->urlTrigger; } /** @@ -177,7 +177,7 @@ protected function getUrlArguments(): array public static function assertNoCallbackRunning(): void { - if ($v = Ui::getQueryParamValue(static::URL_QUERY_TARGET) !== null) { + if ($v = Ui::service()->getQueryParamValue(static::URL_QUERY_TARGET) !== null) { throw (new Exception('Callback requested, but never reached. You may be missing some arguments in request URL.')) ->addMoreInfo('callback requested', $v); } diff --git a/src/Service/Ui.php b/src/Service/Ui.php index e9b2d78..7908d12 100644 --- a/src/Service/Ui.php +++ b/src/Service/Ui.php @@ -171,17 +171,9 @@ public static function serverRequest(): ServerRequestInterface return static::service()->serverRequest; } - public static function getQueryParamValue(string $param): ?string + public function getQueryParamValue(string $param): ?string { - return static::service()->returnQueryParamValue($param); - } - - protected function returnQueryParamValue(string $param): ?string - { - $params = []; - parse_str(static::service()->serverRequest()->getUri()->getQuery(), $params); - - return $params[$param] ?? null; + return $_GET[$param] ?? null; } /** @@ -452,7 +444,7 @@ public static function copyView(View $view): View */ public static function viewDump(View $view, string $dumpWhen, bool $includeJs = true): void { - if (self::getQueryParamValue(self::DUMP_PARAM_NAME) === $dumpWhen) { + if (static::service()->getQueryParamValue(self::DUMP_PARAM_NAME) === $dumpWhen) { static::app()->terminateHtml(static::service()->getDumpPageHtml($view, $includeJs)); } } diff --git a/src/Service/UiInterface.php b/src/Service/UiInterface.php index 2bb6081..a1bfdd5 100644 --- a/src/Service/UiInterface.php +++ b/src/Service/UiInterface.php @@ -40,7 +40,7 @@ public static function page(): Page; public static function serverRequest(): ServerRequestInterface; - public static function getQueryParamValue(string $param): ?string; + public function getQueryParamValue(string $param): ?string; public static function timezone(string $timezone = null): string; diff --git a/src/View.php b/src/View.php index d381e12..077f50f 100644 --- a/src/View.php +++ b/src/View.php @@ -473,7 +473,7 @@ private function getStickyArgs(): array */ public function stickyGet(string $name, string $newValue = null): ?string { - $this->stickyArgs[$name] = Ui::getQueryParamValue($name) ?? $newValue; + $this->stickyArgs[$name] = Ui::service()->getQueryParamValue($name) ?? $newValue; return $this->stickyArgs[$name]; } diff --git a/tests/Callback/CallbackTest.php b/tests/Callback/CallbackTest.php index ef1bf23..b808736 100644 --- a/tests/Callback/CallbackTest.php +++ b/tests/Callback/CallbackTest.php @@ -7,6 +7,7 @@ namespace Fohn\Ui\Tests\Callback; +use Fohn\Ui\AppTest\UiAppTest; use Fohn\Ui\Callback\Ajax; use Fohn\Ui\Callback\Data; use Fohn\Ui\Callback\Generic; @@ -15,14 +16,14 @@ use Fohn\Ui\Callback\ServerEvent; use Fohn\Ui\HtmlTemplate; use Fohn\Ui\Js\Js; -use Fohn\Ui\Tests\UiTestService; +use Fohn\Ui\Service\Ui; use Fohn\Ui\View; class CallbackTest extends \PHPUnit\Framework\TestCase { protected function setUp(): void { - $ui = UiTestService::service(); + $ui = Ui::service(); $ui->setApp(new MockApp(['registerShutdown' => false])); }