Skip to content

Commit 8dd4f7b

Browse files
Replace $_GET/$_POST/$_FILES with App::getRequestXxx() (#2101)
Co-authored-by: Michael Voříšek <mvorisek@mvorisek.cz>
1 parent 41ab1c4 commit 8dd4f7b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+277
-119
lines changed

demos/_includes/ReloadTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ protected function init(): void
1717
$label = Label::addTo($this, ['Testing...', 'detail' => '', 'class.red' => true]);
1818
$reload = new JsReload($this, [$this->name => 'ok']);
1919

20-
if (isset($_GET[$this->name])) {
20+
if ($this->getApp()->hasRequestQueryParam($this->name)) {
2121
$label->class[] = 'green';
2222
$label->content = 'Reload success';
2323
} else {

demos/_includes/ViewTester.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ protected function init(): void
2222
$label = Label::addTo($this, ['CallBack', 'detail' => 'fail', 'class.red' => true]);
2323
$reload = new JsReload($this, [$this->name => 'ok']);
2424

25-
if (isset($_GET[$this->name])) {
25+
if ($this->getApp()->hasRequestQueryParam($this->name)) {
2626
$label->class[] = 'green';
2727
$label->detail = 'success';
2828
} else {

demos/_unit-test/callback-nested.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
$loader->set(static function (Loader $p) use ($m) {
2929
Header::addTo($p, ['Loader-1', 'size' => 4]);
3030

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

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

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

demos/_unit-test/stream.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public function getMetadata($key = null)
128128
}
129129
});
130130

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

133133
$stream = new $hugePseudoStreamClass(static function (int $pos) {
134134
return "\n\0" . str_repeat($pos . ',', 1024);

demos/basic/label.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
$del = Label::addTo($app, ['Zoe', 'image' => 'https://fomantic-ui.com/images/avatar/small/ade.jpg', 'iconRight' => 'delete']);
3030
$del->on('click', '.delete', $del->js()->fadeOut());
3131

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

demos/collection/multitable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function setModel(Model $model, array $route = []): void
3232
$table = Table::addTo($this->addColumn(), ['header' => false, 'class.very basic selectable' => true])->setStyle('cursor', 'pointer');
3333
$table->setModel($model, [$model->titleField]);
3434

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

3737
if ($selections[0]) {
3838
$table->js(true)->find('tr[data-id=' . $selections[0] . ']')->addClass('active');

demos/collection/table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/** @var \Atk4\Ui\App $app */
1515
require_once __DIR__ . '/../init-app.php';
1616

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

demos/form/form3.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
->on('click', new JsReload($seg, ['m' => 'stat']));
3030

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

3535
$form->onSubmit(static function (Form $form) {

demos/init-app.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,23 @@
3131
]);
3232
$app->title = 'Agile UI Demo v' . $app->version;
3333

34+
unset($_SERVER);
35+
unset($_GET);
36+
unset($_POST);
37+
unset($_FILES);
38+
if (isset($_COOKIE)) { // @phpstan-ignore-line https://github.com/phpstan/phpstan/issues/9953
39+
$sessionCookieName = function_exists('session_name') ? session_name() : false;
40+
foreach (array_keys($_COOKIE) as $k) {
41+
if ($k !== $sessionCookieName) {
42+
unset($_COOKIE[$k]);
43+
}
44+
}
45+
if ($_COOKIE === []) {
46+
unset($_COOKIE);
47+
}
48+
}
49+
unset($_SESSION);
50+
3451
if ($app->callExit !== true) {
3552
$app->stickyGet('APP_CALL_EXIT');
3653
}
@@ -85,7 +102,7 @@ public static function get_class(\Closure $createAnonymousClassFx): string
85102
$demosUrl = $rootUrl . 'demos/';
86103

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

90107
$layout = $app->layout;
91108
if ($layout instanceof Layout\NavigableInterface) {

demos/interactive/jssortable.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636

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

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

0 commit comments

Comments
 (0)