Skip to content

Commit

Permalink
fix Get param
Browse files Browse the repository at this point in the history
  • Loading branch information
ibelar committed Jun 13, 2024
1 parent f7db0e5 commit dac2900
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 20 deletions.
2 changes: 1 addition & 1 deletion app-test/_unit-test/table-filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
8 changes: 4 additions & 4 deletions src/Callback/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,23 +113,23 @@ 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;
}

/**
* Return callback triggered value.
*/
public function getTriggeredValue(): string
{
return Ui::getQueryParamValue($this->urlTrigger) ?? '';
return Ui::service()->getQueryParamValue($this->urlTrigger) ?? '';
}

/**
* Only current callback can terminate.
*/
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;
}

/**
Expand Down Expand Up @@ -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);
}
Expand Down
14 changes: 3 additions & 11 deletions src/Service/Ui.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Service/UiInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
5 changes: 3 additions & 2 deletions tests/Callback/CallbackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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]));
}

Expand Down

0 comments on commit dac2900

Please sign in to comment.