Add SimplePresenter::findParam

This commit is contained in:
Alma Armas 2021-01-27 18:50:59 +00:00
parent 65da4abe33
commit f55f6d445d
1 changed files with 18 additions and 2 deletions

View File

@ -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";