2024-08-17 17:03:07 +04:00
|
|
|
<?php
|
|
|
|
namespace nur\sery\wip\php\access;
|
|
|
|
|
|
|
|
use nur\sery\cl;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class PostAccess: accès à une valeur de $_POST
|
|
|
|
*/
|
2024-08-17 21:34:05 +04:00
|
|
|
class PostAccess extends FormAccess {
|
2024-08-17 18:11:11 +04:00
|
|
|
function exists(): bool {
|
2024-08-17 17:03:07 +04:00
|
|
|
$key = $this->key;
|
|
|
|
if ($key === null) return false;
|
|
|
|
return array_key_exists($key, $_POST);
|
|
|
|
}
|
|
|
|
|
2024-08-17 18:11:11 +04:00
|
|
|
public function available(): bool {
|
2024-08-17 17:03:07 +04:00
|
|
|
$key = $this->key;
|
|
|
|
if ($key === null) return false;
|
|
|
|
if (array_key_exists($key, $_POST)) {
|
|
|
|
return $this->allowEmpty || $_POST[$key] !== "";
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-17 18:11:11 +04:00
|
|
|
function get($default=null) {
|
2024-08-17 17:03:07 +04:00
|
|
|
$key = $this->key;
|
|
|
|
if ($key === null) return $default;
|
|
|
|
if (array_key_exists($key, $_POST)) {
|
|
|
|
$value = $_POST[$key];
|
|
|
|
if ($value === "" && !$this->allowEmpty) return $default;
|
|
|
|
return $value;
|
|
|
|
} else {
|
|
|
|
return $default;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-17 18:11:11 +04:00
|
|
|
function set($value): void {
|
2024-08-17 17:03:07 +04:00
|
|
|
$key = $this->key;
|
|
|
|
if ($key === null) return;
|
|
|
|
cl::set($_POST, $key, $value);
|
|
|
|
}
|
|
|
|
|
2024-08-17 18:11:11 +04:00
|
|
|
function del(): void {
|
2024-08-17 17:03:07 +04:00
|
|
|
$key = $this->key;
|
|
|
|
if ($key === null) return;
|
|
|
|
cl::del($_POST, $key);
|
|
|
|
}
|
|
|
|
}
|