2024-08-17 17:03:07 +04:00
|
|
|
<?php
|
|
|
|
namespace nur\sery\wip\php\access;
|
|
|
|
|
|
|
|
use nur\sery\cl;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class GetAccess: accès à une valeur de $_GET
|
|
|
|
*/
|
2024-08-17 21:34:05 +04:00
|
|
|
class GetAccess 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, $_GET);
|
|
|
|
}
|
|
|
|
|
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, $_GET)) {
|
|
|
|
return $this->allowEmpty || $_GET[$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, $_GET)) {
|
|
|
|
$value = $_GET[$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($_GET, $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($_GET, $key);
|
|
|
|
}
|
|
|
|
}
|