From f55f6d445d9328b272f8b323efbde82b69ad1647 Mon Sep 17 00:00:00 2001 From: Alma Armas Date: Wed, 27 Jan 2021 18:50:59 +0000 Subject: [PATCH] Add SimplePresenter::findParam --- chandler/MVC/SimplePresenter.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/chandler/MVC/SimplePresenter.php b/chandler/MVC/SimplePresenter.php index 3a4c0cc..065b9ce 100644 --- a/chandler/MVC/SimplePresenter.php +++ b/chandler/MVC/SimplePresenter.php @@ -166,9 +166,10 @@ abstract class SimplePresenter implements IPresenter return $_GET[$index] ?? NULL; } - protected function postParam(string $index): ?string + protected function postParam(string $index, bool $csrfCheck = true): ?string { - $this->assertNoCSRF(); + if($csrfCheck) + $this->assertNoCSRF(); return $_POST[$index] ?? NULL; } @@ -186,6 +187,21 @@ abstract class SimplePresenter implements IPresenter return $GLOBALS["jsonInputCache"][$index] ?? NULL; } + protected function findParam(string $index, array $searchIn = ["json", "post", "query"]): ?string + { + $res = NULL; + foreach($searchIn as $search) { + if($search === "json") + $res = $this->jsonParam($index) ?? $res; + else if($search === "post") + $res = $this->postParam($index, false) ?? $res; + else if($search === "query") + $res = $this->queryParam($index) ?? $res; + } + + return $res; + } + protected function checkbox(string $name): bool { return ($this->postParam($name) ?? "off") === "on";