Ekdant-Online-Store/system/engine/registry.php
2024-08-06 18:06:00 +05:45

95 lines
1.6 KiB
PHP

<?php
/**
* @package OpenCart
* @author Daniel Kerr
* @copyright Copyright (c) 2005 - 2022, OpenCart, Ltd. (https://www.opencart.com/)
* @license https://opensource.org/licenses/GPL-3.0
* @link https://www.opencart.com
*/
namespace Opencart\System\Engine;
/**
* Class Registry
*/
class Registry {
/**
* @var array
*/
private array $data = [];
/**
* __get
*
* https://www.php.net/manual/en/language.oop5.overloading.php#object.get
*
* @param string $key
*
* @return object
*/
public function __get(string $key): object|null {
return $this->get($key);
}
/**
* __set
*
* https://www.php.net/manual/en/language.oop5.overloading.php#object.set
*
* @param string $key
* @param object $value
*
* @return null
*/
public function __set(string $key, object $value): void {
$this->set($key, $value);
}
/**
* Get
*
* @param string $key
*
* @return object
*/
public function get(string $key): object|null {
return isset($this->data[$key]) ? $this->data[$key] : null;
}
/**
* Set
*
* @param string $key
* @param object $value
*
* @return void
*/
public function set(string $key, object $value): void {
$this->data[$key] = $value;
}
/**
* Has
*
* @param string $key
*
* @return bool
*/
public function has(string $key): bool {
return isset($this->data[$key]);
}
/**
* Unset
*
* Unsets registry value by key.
*
* @param string $key
*
* @return null
*/
public function unset(string $key): void {
if (isset($this->data[$key])) {
unset($this->data[$key]);
}
}
}