1: <?php
2: /**
3: * @package OpenCart
4: *
5: * @author Daniel Kerr
6: * @copyright Copyright (c) 2005 - 2022, OpenCart, Ltd. (https://www.opencart.com/)
7: * @license https://opensource.org/licenses/GPL-3.0
8: *
9: * @see https://www.opencart.com
10: */
11: namespace Opencart\System\Engine;
12: /**
13: * Class Registry
14: */
15: class Registry {
16: /**
17: * @var array<string, object>
18: */
19: private array $data = [];
20:
21: /**
22: * __get
23: *
24: * https://www.php.net/manual/en/language.oop5.overloading.php#object.get
25: *
26: * @param string $key
27: *
28: * @return ?object
29: */
30: public function __get(string $key): ?object {
31: return $this->get($key);
32: }
33:
34: /**
35: * __set
36: *
37: * https://www.php.net/manual/en/language.oop5.overloading.php#object.set
38: *
39: * @param string $key
40: * @param object $value
41: *
42: * @return void
43: */
44: public function __set(string $key, object $value): void {
45: $this->set($key, $value);
46: }
47:
48: /**
49: * __isset
50: *
51: * https://www.php.net/manual/en/language.oop5.overloading.php#object.set
52: *
53: * @param string $key
54: *
55: * @return bool
56: */
57: public function __isset(string $key): bool {
58: return $this->has($key);
59: }
60:
61: /**
62: * Get
63: *
64: * @param string $key
65: *
66: * @return ?object
67: */
68: public function get(string $key): ?object {
69: return $this->data[$key] ?? null;
70: }
71:
72: /**
73: * Set
74: *
75: * @param string $key
76: * @param object $value
77: *
78: * @return void
79: */
80: public function set(string $key, object $value): void {
81: $this->data[$key] = $value;
82: }
83:
84: /**
85: * Has
86: *
87: * @param string $key
88: *
89: * @return bool
90: */
91: public function has(string $key): bool {
92: return isset($this->data[$key]);
93: }
94:
95: /**
96: * Unset
97: *
98: * Unsets registry value by key.
99: *
100: * @param string $key
101: *
102: * @return void
103: */
104: public function unset(string $key): void {
105: unset($this->data[$key]);
106: }
107: }
108: