![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/extmag/core/Helper/ |
<?php /** * Copyright © Extmag. All rights reserved. */ namespace Extmag\Core\Helper; use RuntimeException; class Registry { protected $stack = []; protected $registry = []; /** * @param $name * @return mixed|null */ public function getValue($name) { return $this->stack[$name] ?? null; } /** * @param $name * @param $val * @return bool */ public function setValue($name, $val) { if (!isset($this->stack[$name])) { $this->stack[$name] = $val; return true; } return false; } /** * @param $name * @return bool */ public function unsValue($name) { if (isset($this->stack[$name])) { unset($this->stack[$name]); return true; } return false; } /** * @param $key * @return mixed|null */ public function registry($key) { if (isset($this->registry[$key])) { return $this->registry[$key]; } return null; } /** * @param $key * @param $value * @param $graceful * @return void */ public function register($key, $value, $graceful = false) { if (isset($this->registry[$key])) { if ($graceful) { return; } throw new RuntimeException('Registry key "' . $key . '" already exists'); } $this->registry[$key] = $value; } /** * @param $key * @return void */ public function unregister($key) { if (isset($this->registry[$key])) { if (is_object($this->registry[$key]) && method_exists($this->registry[$key], '__destruct') && is_callable([$this->registry[$key], '__destruct']) ) { $this->registry[$key]->__destruct(); } unset($this->registry[$key]); } } /** * @return void */ public function __destruct() { $keys = array_keys($this->registry); array_walk($keys, [$this, 'unregister']); } }