2020-05-31 17:00:05 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
2020-09-10 22:47:58 +02:00
|
|
|
namespace Venom\Core;
|
2020-05-31 17:00:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
class ArgumentHandler
|
|
|
|
{
|
|
|
|
public static ?ArgumentHandler $instance = null;
|
|
|
|
private array $arguments = [];
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
foreach ($_GET as $key => $item) {
|
|
|
|
$this->arguments[htmlspecialchars($key)] = htmlspecialchars($item);
|
|
|
|
}
|
|
|
|
foreach ($_POST as $key => $item) {
|
|
|
|
$this->arguments[htmlspecialchars($key)] = htmlspecialchars($item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function get(): ArgumentHandler
|
|
|
|
{
|
2020-09-10 22:47:58 +02:00
|
|
|
if (self::$instance === null) {
|
2020-05-31 17:00:05 +02:00
|
|
|
self::$instance = new ArgumentHandler();
|
|
|
|
}
|
|
|
|
return self::$instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getItem(string $key, $default = null)
|
|
|
|
{
|
2020-09-20 17:15:20 +02:00
|
|
|
return $this->arguments[$key] ?? $default;
|
2020-05-31 17:00:05 +02:00
|
|
|
}
|
2020-07-24 11:08:07 +02:00
|
|
|
|
2020-09-20 17:15:20 +02:00
|
|
|
public function setItem(string $key, $item): void
|
2020-07-24 11:08:07 +02:00
|
|
|
{
|
|
|
|
$this->arguments[$key] = $item;
|
|
|
|
}
|
2020-09-20 17:15:20 +02:00
|
|
|
|
|
|
|
public function hasItem(string $key): bool
|
|
|
|
{
|
|
|
|
return isset($this->arguments[$key]);
|
|
|
|
}
|
2020-05-31 17:00:05 +02:00
|
|
|
}
|