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 Proxy
14: | *
15: | * @template TWraps of \Opencart\System\Engine\Model
16: | *
17: | * @mixin TWraps
18: | */
19: | class Proxy {
20: | /**
21: | * @var array<string, object>
22: | */
23: | protected array $data = [];
24: |
25: | /**
26: | * __get
27: | *
28: | * @param string $key
29: | *
30: | * @return mixed
31: | */
32: | public function &__get(string $key) {
33: | if (isset($this->data[$key])) {
34: | return $this->data[$key];
35: | } else {
36: | throw new \Exception('Error: Could not call proxy key ' . $key . '!');
37: | }
38: | }
39: |
40: | /**
41: | * __set
42: | *
43: | * @param string $key
44: | * @param object $value
45: | *
46: | * @return void
47: | */
48: | public function __set(string $key, object $value): void {
49: | $this->data[$key] = $value;
50: | }
51: |
52: | /**
53: | * __isset
54: | *
55: | * @param string $key
56: | *
57: | * @return bool
58: | */
59: | public function __isset(string $key): bool {
60: | return isset($this->data[$key]);
61: | }
62: |
63: | /**
64: | * __unset
65: | *
66: | * @param string $key
67: | *
68: | * @return void
69: | */
70: | public function __unset(string $key): void {
71: | unset($this->data[$key]);
72: | }
73: |
74: | /**
75: | * __call
76: | *
77: | * @param string $method
78: | * @param array<string, mixed> $args
79: | *
80: | * @return mixed
81: | */
82: | public function __call(string $method, array $args) {
83: | // Hack for pass-by-reference
84: | foreach ($args as $key => &$value);
85: |
86: | if (isset($this->data[$method])) {
87: | return ($this->data[$method])(...$args);
88: | } else {
89: | $trace = debug_backtrace();
90: |
91: | throw new \Exception('<b>Notice</b>: Undefined property: Proxy::' . $method . ' in <b>' . $trace[0]['file'] . '</b> on line <b>' . $trace[0]['line'] . '</b>');
92: | }
93: | }
94: | }
95: |

OpenCart API API documentation generated by ApiGen dev-master