Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace $_GET/$_POST/$_FILES with App::getRequestXxx() #2101

Merged
merged 103 commits into from
Sep 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
7fdbbe7
Fix PrettyUrl legitimate path
abbadon1334 Aug 23, 2023
ba90e32
Add Unit tests for App::url
abbadon1334 Aug 25, 2023
f2dd8f3
add default excepted page and extension
abbadon1334 Aug 25, 2023
6713d61
fix 7.4 array merge with keys / spread operator
abbadon1334 Aug 25, 2023
04720c5
Add more test cases for App:url
abbadon1334 Aug 25, 2023
80b8fca
Reorganize code
abbadon1334 Aug 25, 2023
27d9cb4
Improve converage
abbadon1334 Aug 26, 2023
67f0594
Improve App::url tests
abbadon1334 Aug 28, 2023
b2810b8
Skip $useRequestUrl=true due to REQUEST_URI
abbadon1334 Aug 28, 2023
3997714
Change REQUEST_URI to Psr7 methods
abbadon1334 Aug 28, 2023
4348ff1
Allow $useRequestUrl=true
abbadon1334 Aug 28, 2023
e4c3428
clean up
abbadon1334 Aug 28, 2023
7895ec9
Improve error message
abbadon1334 Aug 28, 2023
f1fefac
CS Fix
abbadon1334 Aug 28, 2023
308cc87
Merge branch 'develop' into add_tests_app_url
abbadon1334 Sep 3, 2023
23a5a6b
Add App::$urlBuildingPage to customize url building page
abbadon1334 Sep 4, 2023
f3f099f
Comment out App::url failing tests
abbadon1334 Sep 4, 2023
3c36038
Merge branch 'develop' into fix_pretty_url_legitimate_path
abbadon1334 Sep 4, 2023
534cff4
Avoid change of global var $_SERVER
abbadon1334 Sep 4, 2023
a01c3bb
Fix missing request in App for Unit tests
abbadon1334 Sep 4, 2023
62f370b
Comment out not working tests
abbadon1334 Sep 4, 2023
8b3561e
removed getRequestUrl
abbadon1334 Sep 4, 2023
b6ae878
Add failing tests
abbadon1334 Sep 4, 2023
c7840f1
Add methods App::issetRequestXxx App::getRequestXxx
abbadon1334 Sep 5, 2023
f7e819a
Replaced all $_FILES
abbadon1334 Sep 5, 2023
279f796
Replace $_GET App::getRequestGetParam
abbadon1334 Sep 5, 2023
c2e175c
Replace $_GET App::getRequestGetParam
abbadon1334 Sep 5, 2023
e4fb8ab
Replace $_GET App::getRequestGetParam
abbadon1334 Sep 5, 2023
029580c
Add App::tryGetRequestGetParam not raise exceptiona nd return null if…
abbadon1334 Sep 5, 2023
f7bf3fb
Replace $_GET App::has/get/tryGet/RequestGetParam
abbadon1334 Sep 5, 2023
b7241cc
Replace $_GET/$_POST App::has/get/tryGet/RequestGet/PostParam
abbadon1334 Sep 7, 2023
c7b21f9
Replace $_GET/$_POST App::has/get/tryGet/RequestGet/PostParam
abbadon1334 Sep 7, 2023
e2d5123
Cs Fix
abbadon1334 Sep 7, 2023
af6d8b9
Fix Url building if path starts with ..
abbadon1334 Sep 7, 2023
c778a65
Fix JSON POST test
abbadon1334 Sep 7, 2023
ee4ea0a
Fix stan
abbadon1334 Sep 8, 2023
1fe9312
Raise composer require to nyholm/psr7 ( failing lowest tests)
abbadon1334 Sep 8, 2023
766af8a
Align composer require-release to require
abbadon1334 Sep 8, 2023
4a9c711
Cs Fix
abbadon1334 Sep 8, 2023
f1de9eb
Revert "Cs Fix"
abbadon1334 Sep 8, 2023
cccceb1
Cs Fix with latest version
abbadon1334 Sep 8, 2023
645e0aa
Strong type for $urlBuildingXxx vars
abbadon1334 Sep 8, 2023
7022361
Use CreateApp
abbadon1334 Sep 8, 2023
0a1bd7f
Remove message from Assert
abbadon1334 Sep 8, 2023
95b7d1e
Cs Fix
abbadon1334 Sep 8, 2023
7bd47a2
Raise Nyholm/psr7 from 1.4 to 1.6
abbadon1334 Sep 8, 2023
945008d
Merge branch 'develop' into use_request_not_globals
abbadon1334 Sep 8, 2023
d5b4224
Merge branch 'develop' into add_tests_app_url
mvorisek Sep 9, 2023
47d6032
DEBUG REVERT ALL
mvorisek Sep 9, 2023
d4a0810
introduce App::$urlBuildingIndexPage prop
mvorisek Sep 9, 2023
89e3efa
drop protected App::getRequestUrl() method
mvorisek Sep 9, 2023
b490c1f
replace $_SERVER['REQUEST_URI'] with PSR7 request
mvorisek Sep 9, 2023
4d0e4c7
fix cs
mvorisek Sep 9, 2023
8b3bd58
original AppTest changes
mvorisek Sep 9, 2023
fccada4
no manual assert context dump
mvorisek Sep 9, 2023
b14f5fe
allow to create test App with defaults
mvorisek Sep 9, 2023
c3de25c
always use test App in tests
mvorisek Sep 9, 2023
a4c193f
Merge branch 'develop'
mvorisek Sep 9, 2023
84cfbd0
Merge PR 2096
mvorisek Sep 9, 2023
547f2f4
remaining reverted changes from PR 2096
mvorisek Sep 9, 2023
9353bba
Merge develop
mvorisek Sep 9, 2023
b80942d
Merge branch 'develop'
mvorisek Sep 10, 2023
6651bc9
Merge branch 'develop'
mvorisek Sep 10, 2023
dfd4ead
Merge branch 'fix_pretty_url_legitimate_path'
mvorisek Sep 10, 2023
f472b49
Add correct DocBlock
abbadon1334 Sep 10, 2023
80c7417
Add method App::tryGetRequestUploadedFile for consistency
abbadon1334 Sep 10, 2023
f5aaeba
Add to _SERVER key CONTENT_TYPE
abbadon1334 Sep 10, 2023
fdac5e2
Removed Hack
abbadon1334 Sep 10, 2023
b691c26
Cs Fix
abbadon1334 Sep 10, 2023
2c08709
Fix Typo
abbadon1334 Sep 10, 2023
8f8b7df
Fix getRequestPostParam and tryGetRequestPostParam cases
abbadon1334 Sep 10, 2023
c16e299
Fix getRequestPostParam and tryGetRequestPostParam cases
abbadon1334 Sep 10, 2023
d64706e
Recheck usage of Try with useless coalesce
abbadon1334 Sep 10, 2023
c9d06c6
Merge branch 'develop'
mvorisek Sep 14, 2023
4aa74c8
Merge branch 'fix_pretty_url_legitimate_path'
mvorisek Sep 14, 2023
bae7f69
Merge branch 'develop'
mvorisek Sep 14, 2023
9cff373
enable commented tests
mvorisek Sep 14, 2023
75efe8c
silence failing tests
mvorisek Sep 14, 2023
2c2b8ca
add wrongly removed check_unset_page test
mvorisek Sep 14, 2023
ded9e9a
Merge branch 'fix_pretty_url_legitimate_path'
mvorisek Sep 14, 2023
965926e
REVERT ALL (reset to develop)
mvorisek Sep 14, 2023
1fe9677
Merge branch 'develop'
mvorisek Sep 15, 2023
87b02b2
unmerge PR 2095 ('fix_pretty_url_legitimate_path' branch)
mvorisek Sep 15, 2023
dedf6a8
Merge branch 'develop' into use_request_not_globals
mvorisek Sep 17, 2023
de485ae
REVERT ALL (reset to develop)
mvorisek Sep 15, 2023
25e7950
Merge branch 'develop'
mvorisek Sep 22, 2023
7174fa3
Merge branch 'develop'
mvorisek Sep 24, 2023
5e9f268
rm CreateAppTrait::setGlobalsFromRequest() test method
mvorisek Sep 22, 2023
2ed9348
add App request shortcut methods
mvorisek Sep 26, 2023
836ade9
replace all 'isset\(\$_GET\[(.+?)\]' matches
mvorisek Sep 22, 2023
6b92214
replace all '\$_GET\[(.+?)\](?= \?\?)' matches
mvorisek Sep 26, 2023
46f02ec
replace all '\$_GET\[(.+?)\]' matches
mvorisek Sep 22, 2023
eb936bc
replace all '\$_POST\[(.+?)\](?= \?\?)' matches
mvorisek Sep 22, 2023
bfcead2
replace all '\$_POST\[(.+?)\]' matches
mvorisek Sep 22, 2023
6ccd09e
replace remaining $_GET/$_POST
mvorisek Sep 26, 2023
487903a
rename "GetParam" to "QueryParam"
mvorisek Sep 28, 2023
994cc1f
replace/emulate $_FILES
mvorisek Sep 26, 2023
4dd1121
fix $_SERVER emulation for POST test
mvorisek Sep 26, 2023
fb349fd
add edge cases empty GET param test
mvorisek Sep 26, 2023
e63de0a
test all exceptions
mvorisek Sep 26, 2023
acd263e
unset $_GET, $_POST, ... after App is created in demos/testing
mvorisek Sep 26, 2023
f6faa97
fix phpstan
mvorisek Sep 30, 2023
78ad102
fix $_COOKIE unset in demos
mvorisek Sep 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demos/_includes/ReloadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ protected function init(): void
$label = Label::addTo($this, ['Testing...', 'detail' => '', 'class.red' => true]);
$reload = new JsReload($this, [$this->name => 'ok']);

if (isset($_GET[$this->name])) {
if ($this->getApp()->hasRequestQueryParam($this->name)) {
$label->class[] = 'green';
$label->content = 'Reload success';
} else {
Expand Down
2 changes: 1 addition & 1 deletion demos/_includes/ViewTester.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected function init(): void
$label = Label::addTo($this, ['CallBack', 'detail' => 'fail', 'class.red' => true]);
$reload = new JsReload($this, [$this->name => 'ok']);

if (isset($_GET[$this->name])) {
if ($this->getApp()->hasRequestQueryParam($this->name)) {
$label->class[] = 'green';
$label->detail = 'success';
} else {
Expand Down
6 changes: 3 additions & 3 deletions demos/_unit-test/callback-nested.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
$loader->set(static function (Loader $p) use ($m) {
Header::addTo($p, ['Loader-1', 'size' => 4]);

if (isset($_GET['err_main_loader'])) {
if ($p->getApp()->hasRequestQueryParam('err_main_loader')) {
throw new Exception('Exception from Main Loader');
}

Expand All @@ -39,9 +39,9 @@
$loaderSub->set(static function (Loader $p) use ($m) {
Header::addTo($p, ['Loader-2', 'size' => 4]);

if (isset($_GET['err_sub_loader'])) {
if ($p->getApp()->hasRequestQueryParam('err_sub_loader')) {
throw new Exception('Exception from Sub Loader');
} elseif (isset($_GET['err_sub_loader2'])) {
} elseif ($p->getApp()->hasRequestQueryParam('err_sub_loader2')) {
throw new \Error('Exception II from Sub Loader');
}

Expand Down
2 changes: 1 addition & 1 deletion demos/_unit-test/stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public function getMetadata($key = null)
}
});

$sizeBytes = $_GET['size_mb'] * 1024 * 1024;
$sizeBytes = (int) $app->getRequestQueryParam('size_mb') * 1024 * 1024;

$stream = new $hugePseudoStreamClass(static function (int $pos) {
return "\n\0" . str_repeat($pos . ',', 1024);
Expand Down
2 changes: 1 addition & 1 deletion demos/basic/label.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
$del = Label::addTo($app, ['Zoe', 'image' => 'https://fomantic-ui.com/images/avatar/small/ade.jpg', 'iconRight' => 'delete']);
$del->on('click', '.delete', $del->js()->fadeOut());

$val = isset($_GET['toggle']) && $_GET['toggle'];
$val = $app->hasRequestQueryParam('toggle') && $app->getRequestQueryParam('toggle');
$toggle = Label::addTo($app, ['icon' => 'toggle ' . ($val ? 'on' : 'off')])->set('Value: ' . $val);
$toggle->on('click', new JsReload($toggle, ['toggle' => $val ? null : 1]));

Expand Down
2 changes: 1 addition & 1 deletion demos/collection/multitable.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function setModel(Model $model, array $route = []): void
$table = Table::addTo($this->addColumn(), ['header' => false, 'class.very basic selectable' => true])->setStyle('cursor', 'pointer');
$table->setModel($model, [$model->titleField]);

$selections = explode(',', $_GET[$this->name] ?? '');
$selections = explode(',', $this->getApp()->tryGetRequestQueryParam($this->name) ?? '');

if ($selections[0]) {
$table->js(true)->find('tr[data-id=' . $selections[0] . ']')->addClass('active');
Expand Down
2 changes: 1 addition & 1 deletion demos/collection/table.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';

if ($_GET['id'] ?? null) {
if ($app->tryGetRequestQueryParam('id')) {
$app->layout->js(true, new JsToast('Details link is in simulation mode.'));
}

Expand Down
2 changes: 1 addition & 1 deletion demos/form/form3.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
->on('click', new JsReload($seg, ['m' => 'stat']));

$form = Form::addTo($seg, ['layout' => [Form\Layout\Columns::class]]);
$modelClass = ['country' => Country::class, 'file' => File::class][$_GET['m'] ?? ''] ?? Stat::class;
$modelClass = ['country' => Country::class, 'file' => File::class][$app->tryGetRequestQueryParam('m')] ?? Stat::class;
$form->setModel((new $modelClass($app->db))->loadAny());

$form->onSubmit(static function (Form $form) {
Expand Down
19 changes: 18 additions & 1 deletion demos/init-app.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,23 @@
]);
$app->title = 'Agile UI Demo v' . $app->version;

unset($_SERVER);
unset($_GET);
unset($_POST);
unset($_FILES);
if (isset($_COOKIE)) { // @phpstan-ignore-line https://github.com/phpstan/phpstan/issues/9953
$sessionCookieName = function_exists('session_name') ? session_name() : false;
foreach (array_keys($_COOKIE) as $k) {
if ($k !== $sessionCookieName) {
unset($_COOKIE[$k]);
}
}
if ($_COOKIE === []) {
unset($_COOKIE);
}
}
unset($_SESSION);

if ($app->callExit !== true) {
$app->stickyGet('APP_CALL_EXIT');
}
Expand Down Expand Up @@ -85,7 +102,7 @@ public static function get_class(\Closure $createAnonymousClassFx): string
$demosUrl = $rootUrl . 'demos/';

// allow custom layout override
$app->initLayout([!isset($_GET['layout']) ? Layout\Maestro::class : $app->stickyGet('layout')]);
$app->initLayout([!$app->hasRequestQueryParam('layout') ? Layout\Maestro::class : $app->stickyGet('layout')]);

$layout = $app->layout;
if ($layout instanceof Layout\NavigableInterface) {
Expand Down
4 changes: 2 additions & 2 deletions demos/interactive/jssortable.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@

$sortable = JsSortable::addTo($view, ['container' => 'ul', 'draggable' => 'li', 'dataLabel' => 'name']);

$sortable->onReorder(static function (array $order, string $src, int $pos, int $oldPos) {
if ($_GET['btn'] ?? null) {
$sortable->onReorder(static function (array $order, string $src, int $pos, int $oldPos) use ($app) {
if ($app->tryGetRequestQueryParam('btn')) {
return new JsToast(implode(' - ', $order));
}

Expand Down
2 changes: 1 addition & 1 deletion demos/interactive/loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
$loader->set(static function (Loader $p) {
// you may pass arguments to the loader, in this case it's "color"
sleep(1);
$color = $_GET['color'];
$color = $p->getApp()->getRequestQueryParam('color');
Header::addTo($p, ['Loader #1b - ' . $color]);
LoremIpsum::addTo(View::addTo($p, ['ui' => $color . ' segment']), ['size' => 1]);

Expand Down
2 changes: 1 addition & 1 deletion demos/interactive/loader2.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@

$countryLoader->set(static function (Loader $p) {
Form::addTo($p)->setModel(
(new Country($p->getApp()->db))->load($_GET['id'])
(new Country($p->getApp()->db))->load($p->getApp()->getRequestQueryParam('id'))
);
});
6 changes: 3 additions & 3 deletions demos/interactive/modal.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
// when $vp2Modal->jsShow() is activate, it will dynamically add this content to it
$vp2Modal->set(static function (View $p) use ($vp3Modal) {
ViewTester::addTo($p);
Message::addTo($p, [$_GET['color'] ?? 'No color'])->text->addParagraph('This text is loaded using a second modal.');
Message::addTo($p, [$p->getApp()->tryGetRequestQueryParam('color') ?? 'No color'])->text->addParagraph('This text is loaded using a second modal.');
Button::addTo($p)->set('Third modal')
->on('click', $vp3Modal->jsShow());
});
Expand Down Expand Up @@ -179,8 +179,8 @@
$stepModal->set(static function (View $p) use ($session, $previousAction, $nextAction) {
$page = $session->recall('page', 1);
$success = $session->recall('success', false);
if (isset($_GET['move'])) {
$move = $_GET['move'];
if ($p->getApp()->hasRequestQueryParam('move')) {
$move = $p->getApp()->getRequestQueryParam('move');
if ($move === 'next' && $success) {
++$page;
} elseif ($move === 'previous' && $page > 1) {
Expand Down
8 changes: 4 additions & 4 deletions demos/interactive/popup.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ protected function init(): void
$this->tRow->set('descr', 'click on link to remove item');

// We link to ourselves with this special GET argument to indicate that item must be removed.
if (isset($_GET[$this->name . '_remove'])) {
$this->removeItem($_GET['id']);
if ($this->getApp()->hasRequestQueryParam($this->name . '_remove')) {
$this->removeItem($this->getApp()->getRequestQueryParam('id'));

// redirect again, since we don't want this to stay in the URL
$this->getApp()->redirect([$this->name . '_remove' => false]);
Expand Down Expand Up @@ -242,8 +242,8 @@ public function linkCart(View $cart, JsExpressionable $jsAction = null): void
$signup->stickyGet('logged');
$signup->set(static function (View $pop) {
// content of the popup will be different depending on this condition.
if (isset($_GET['logged'])) {
Message::addTo($pop, ['You are already logged in as ' . $_GET['logged']]);
if ($pop->getApp()->hasRequestQueryParam('logged')) {
Message::addTo($pop, ['You are already logged in as ' . $pop->getApp()->getRequestQueryParam('logged')]);
Button::addTo($pop, ['Logout', 'class.primary' => true, 'icon' => 'sign out'])
->link($pop->getApp()->url());
} else {
Expand Down
2 changes: 1 addition & 1 deletion demos/interactive/tabs.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
// dynamic tab
$tabs->addTab('Dynamic Lorem Ipsum', static function (VirtualPage $vp) {
Message::addTo($vp, ['Every time you come to this tab, you will see a different text']);
LoremIpsum::addTo($vp, ['size' => (int) ($_GET['size'] ?? 1)]);
LoremIpsum::addTo($vp, ['size' => (int) ($vp->getApp()->tryGetRequestQueryParam('size') ?? 1)]);
}, ['apiSettings' => ['data' => ['size' => random_int(1, 4)]]]);

// modal tab
Expand Down
8 changes: 4 additions & 4 deletions demos/interactive/virtual.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
$virtualPage = VirtualPage::addTo($app->layout, ['urlTrigger' => 'in']);

// add content to virtual page
if (isset($_GET['p_id'])) {
Header::addTo($virtualPage, [$_GET['p_id']])->addClass('__atk-behat-test-car');
if ($app->hasRequestQueryParam('p_id')) {
Header::addTo($virtualPage, [$app->getRequestQueryParam('p_id')])->addClass('__atk-behat-test-car');
}
LoremIpsum::addTo($virtualPage, ['size' => 1]);
$virtualPageButton = Button::addTo($virtualPage, ['Back', 'icon' => 'left arrow']);
Expand Down Expand Up @@ -74,7 +74,7 @@

Button::addTo($bar)->set('Simulate slow load')
->on('click', new JsModal('My Popup Title', $virtualPage->getJsUrl('cut') . '&slow=true'));
if (isset($_GET['slow'])) {
if ($app->hasRequestQueryParam('slow')) {
sleep(1);
}

Expand All @@ -89,7 +89,7 @@

$frame = VirtualPage::addTo($app);
$frame->set(static function (VirtualPage $p) {
Header::addTo($p, ['Clicked row with ID = ' . ($_GET['id'] ?? '')]);
Header::addTo($p, ['Clicked row with ID = ' . $p->getApp()->tryGetRequestQueryParam('id')]);
});

$table->onRowClick(new JsModal('Row Clicked', $frame, ['id' => $table->jsRow()->data('id')]));
4 changes: 2 additions & 2 deletions demos/interactive/wizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
// and set a custom JS action or even set a different link. You can use recall()
// to access some values that were recorded on another steps.
$wizard->addStep(['Select Model', 'description' => '"Country" or "Stat"', 'icon' => 'table'], static function (Wizard $wizard) {
if (isset($_GET['name'])) {
$wizard->memorize('model', $_GET['name']);
if ($wizard->getApp()->hasRequestQueryParam('name')) {
$wizard->memorize('model', $wizard->getApp()->getRequestQueryParam('name'));
$wizard->getApp()->redirect($wizard->urlNext());
}

Expand Down
2 changes: 1 addition & 1 deletion demos/javascript/js.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
Button::addTo($app, ['Redirect'])
->on('click', null, $app->jsRedirect(['foo' => 'bar']));

if (isset($_GET['foo']) && $_GET['foo'] === 'bar') {
if ($app->hasRequestQueryParam('foo') && $app->getRequestQueryParam('foo') === 'bar') {
$app->redirect(['foo' => 'baz']);
}

Expand Down
2 changes: 1 addition & 1 deletion demos/javascript/reloading.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
// reloading with argument
Header::addTo($app, ['We can pass argument to reloader']);

$v = View::addTo($app, ['ui' => 'segment'])->set($_GET['val'] ?? 'No value');
$v = View::addTo($app, ['ui' => 'segment'])->set($app->tryGetRequestQueryParam('val') ?? 'No value');

Button::addTo($app, ['Set value to "hello"'])
->on('click', new JsReload($v, ['val' => 'hello']));
Expand Down
2 changes: 1 addition & 1 deletion demos/layout/layout-panel.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

$view = View::addTo($app, ['ui' => 'segment']);
$text = Text::addTo($view);
$text->set($_GET['txt'] ?? 'Not Complete');
$text->set($app->tryGetRequestQueryParam('txt') ?? 'Not Complete');

$panel1->onOpen(static function (Panel\Content $p) use ($view) {
$panel = View::addTo($p, ['ui' => 'basic segment']);
Expand Down
12 changes: 6 additions & 6 deletions demos/others/sticky2.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,29 @@

// This demo shows a local impact of a sticky parameters

if (isset($_GET['name'])) {
if ($app->hasRequestQueryParam('name')) {
// IMPORTANT: because this is an optional frame, I have to specify it's unique shortName explicitly, othrewise
// the name for a second frame will be affected by presence of GET['name'] parameter
$frame = View::addTo($app, ['ui' => 'red segment', 'shortName' => 'fr1']);
$frame->stickyGet('name');

// frame will generate URL with sticky parameter
Label::addTo($frame, ['Name:', 'detail' => $_GET['name'], 'class.black' => true])->link($frame->url());
Label::addTo($frame, ['Name:', 'detail' => $app->getRequestQueryParam('name'), 'class.black' => true])->link($frame->url());

// app still generates URL without localized sticky
Label::addTo($frame, ['Reset', 'iconRight' => 'close', 'class.black' => true])->link($app->url());
View::addTo($frame, ['ui' => 'hidden divider']);

// nested interactive elements will respect lockal sticky get
Button::addTo($frame, ['Triggering callback here will inherit color'])
->on('click', static function () {
return new JsToast('Color was = ' . $_GET['name']);
->on('click', static function () use ($app) {
return new JsToast('Color was = ' . $app->getRequestQueryParam('name'));
});

// next we have loader, which will dynamically load console which will dynamically output "success" message
Loader::addTo($frame)->set(static function (Loader $p) {
Console::addTo($p)->set(static function (Console $console) {
$console->output('success!, color is still ' . $_GET['name']);
$console->output('success!, color is still ' . $console->getApp()->getRequestQueryParam('name'));
});
});
}
Expand All @@ -53,7 +53,7 @@
$frame = View::addTo($app, ['ui' => 'green segment']);
Button::addTo($frame, ['does not inherit sticky get'])
->on('click', static function () use ($app) {
return new JsToast('$_GET = ' . $app->encodeJson($_GET));
return new JsToast('$_GET = ' . $app->encodeJson($app->getRequest()->getQueryParams()));
});

Header::addTo($app, ['Use of View::url()']);
Expand Down
2 changes: 1 addition & 1 deletion demos/tutorial/intro.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@

View::addTo($seg, ['ui' => 'divider']);

$count = $_GET['count'] ?? 1;
$count = $seg->getApp()->tryGetRequestQueryParam('count') ?? 1;
for ($i = 1; $i <= $count; ++$i) {
Button::addTo($seg, [(string) $i]);
}
Expand Down
4 changes: 2 additions & 2 deletions docs/app.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,12 @@ to provide a simple way to redirect for users who are not familiar with JavaScri
so well. Example:

```
if (!isset($_GET['age'])) {
if (!$app->hasRequestQueryParam('age')) {
$app->redirect(['age' => 18]);
}

Button::addTo($app, ['Increase age'])
->on('click', $app->jsRedirect(['age' => $_GET['age'] + 1]));
->on('click', $app->jsRedirect(['age' => $app->getRequestQueryParam('age') + 1]));
```

No much magic in these methods.
Expand Down
6 changes: 3 additions & 3 deletions docs/core.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ Agile UI implements advanced approach allowing any View object that you add into
declare "sticky GET arguments". Here is example:

```
if (isset($_GET['message'])) {
Message::addTo($app)->set($_GET['message']);
if ($app->hasRequestQueryParam('message')) {
Message::addTo($app)->set($app->getRequestQueryParam('message'));
}

Button::addTo($app, ['Trigger message'])->link(['message' => 'Hello World']);
Expand All @@ -96,7 +96,7 @@ In Agile UI you can request that some $_GET arguments are preserved and included

```
if ($this->getApp()->stickyGet('message')) {
Message::addTo($app)->set($_GET['message']);
Message::addTo($app)->set($app->getRequestQueryParam('message'));
}

Button::addTo($app, ['Trigger message'])->link(['message' => 'Hello World']);
Expand Down
2 changes: 1 addition & 1 deletion docs/js.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ The following code is safe:

```
$b = new Button();
$b->js(true)->text($_GET['button_text']);
$b->js(true)->text($app->getRequestQueryParam('button_text'));
```

Any malicious input through the GET arguments will be encoded as JS string before being included as an
Expand Down
4 changes: 2 additions & 2 deletions docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@ $grid->menu->addItem('Complete Selected',
])
);

if (isset($_GET['delete'])) {
foreach (explode(',', $_GET['delete']) as $id) {
if ($app->hasRequestQueryParam('delete')) {
foreach (explode(',', $app->getRequestQueryParam('delete')) as $id) {
$grid->model->delete($id);
}
}
Expand Down
4 changes: 2 additions & 2 deletions docs/render.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ class MyView extends View
{
parent::init();

if ($_GET[$this->name]) {
if ($this->getApp()->getRequestQueryParam($this->name)) {
\Atk4\Ui\Label::addTo($this, [
'Secret info is',
'class.big red' => true,
'detail' => $_GET[$this->name],
'detail' => $this->getApp()->getRequestQueryParam($this->name),
]);
}

Expand Down
2 changes: 1 addition & 1 deletion docs/rightpanel.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ $button->js(true)->data('btn', '1');
$button->on('click', $panel->jsOpen(['btn'], 'orange'));

$panel->onOpen(function (Panel\Content $p) {
$buttonNumber = $_GET['btn'] ?? null;
$buttonNumber = $p->getApp()->tryGetRequestQueryParam('btn');
$text = 'You loaded panel content using button #' . $buttonNumber;
Message::addTo($p, ['Panel 1', 'text' => $text]);
});
Expand Down
Loading