sessionStorage = new SessionStorage(); $this->persistentStorage = new PersistentStorage(); } public function getSessionStorage(): SessionStorage { return $this->sessionStorage; } public function getPersistentStorage(): PersistentStorage { return $this->persistentStorage; } public function set(string $varname, $value) { $this->vars[$varname] = $value; } public function get(string $varname, $default=null): mixed { return $this->vars[$varname] ?? $default; } public function expand(string $input): string { $expanded = preg_replace_callback('/(%\{(.+?)\})/', function ($m) { $k = $m[1]; if (str_contains($k, ':')) { [$type, $k] = explode(":", $k, 2); } else { $type = "var"; } switch ($type) { case 'var': return $this->get($k, null); case 'env': return getenv($k); } }, $input); return $expanded; } } class SessionStorage implements StorageInterface { protected $data = []; public function set(string $k, $value) { $this->data[$k] = $value; } public function get(string $k, $default=null): mixed { return $this->data[$k] ?? $default; } public function has(string $k): bool { return array_key_exists($k, $this->data); } public function delete(string $k): void { unset($this->data[$k]); } } class PersistentStorage implements StorageInterface { protected $data = []; public function set(string $k, $value) { $this->data[$k] = $value; } public function get(string $k, $default=null): mixed { return $this->data[$k] ?? $default; } public function has(string $k): bool { return array_key_exists($k, $this->data); } public function delete(string $k): void { unset($this->data[$k]); } } interface StorageInterface { public function set(string $k, $value); public function get(string $k, $default=null): mixed; public function has(string $k): bool; public function delete(string $k): void; }