Commit | Line | Data |
---|---|---|
11ade432 | 1 | <?php |
a9229942 | 2 | |
11ade432 | 3 | namespace wcf\data; |
a9229942 | 4 | |
11ade432 | 5 | use wcf\system\exception\SystemException; |
11ade432 AE |
6 | |
7 | /** | |
8 | * Basic implementation for object decorators. | |
a9229942 TD |
9 | * |
10 | * @author Marcel Werk | |
11 | * @copyright 2001-2019 WoltLab GmbH | |
12 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> | |
13 | * @package WoltLabSuite\Core\Data | |
11ade432 | 14 | */ |
a9229942 TD |
15 | abstract class DatabaseObjectDecorator extends DatabaseObject |
16 | { | |
17 | /** | |
18 | * name of the base class | |
19 | * @var string | |
20 | */ | |
21 | protected static $baseClass = ''; | |
22 | ||
23 | /** | |
24 | * decorated object | |
25 | * @var DatabaseObject | |
26 | */ | |
27 | protected $object; | |
28 | ||
29 | /** @noinspection PhpMissingParentConstructorInspection */ | |
30 | ||
31 | /** | |
32 | * Creates a new DatabaseObjectDecorator object. | |
33 | * | |
34 | * @param DatabaseObject $object | |
35 | * @throws SystemException | |
36 | */ | |
37 | public function __construct(DatabaseObject $object) | |
38 | { | |
39 | if (empty(static::$baseClass)) { | |
40 | throw new SystemException('Base class not specified'); | |
41 | } | |
42 | ||
43 | if (!($object instanceof static::$baseClass)) { | |
44 | throw new SystemException("Object does not match '" . static::$baseClass . "' (given object is of class '" . \get_class($object) . "')"); | |
45 | } | |
46 | ||
47 | $this->object = $object; | |
48 | } | |
49 | ||
50 | /** | |
51 | * @inheritDoc | |
52 | */ | |
53 | public function __get($name) | |
54 | { | |
55 | return $this->object->__get($name); | |
56 | } | |
57 | ||
58 | /** | |
59 | * @inheritDoc | |
60 | */ | |
61 | public function __isset($name) | |
62 | { | |
63 | return $this->object->__isset($name); | |
64 | } | |
65 | ||
66 | /** | |
67 | * @inheritDoc | |
68 | */ | |
69 | public function getObjectID() | |
70 | { | |
71 | return $this->object->getObjectID(); | |
72 | } | |
73 | ||
74 | /** | |
75 | * @inheritDoc | |
76 | */ | |
77 | public function getData() | |
78 | { | |
79 | return $this->object->getData(); | |
80 | } | |
81 | ||
82 | /** | |
83 | * Delegates inaccessible methods calls to the decorated object. | |
84 | * | |
85 | * @param string $name | |
86 | * @param array $arguments | |
87 | * @return mixed | |
88 | * @throws SystemException | |
89 | */ | |
90 | public function __call($name, $arguments) | |
91 | { | |
92 | if (!\method_exists($this->object, $name) && !($this->object instanceof self)) { | |
93 | throw new SystemException("unknown method '" . $name . "'"); | |
94 | } | |
95 | ||
96 | return \call_user_func_array([$this->object, $name], $arguments); | |
97 | } | |
98 | ||
99 | /** | |
100 | * @inheritDoc | |
101 | */ | |
102 | public static function getDatabaseTableAlias() | |
103 | { | |
104 | return \call_user_func([static::$baseClass, 'getDatabaseTableAlias']); | |
105 | } | |
106 | ||
107 | /** | |
108 | * @inheritDoc | |
109 | */ | |
110 | public static function getDatabaseTableName() | |
111 | { | |
112 | return \call_user_func([static::$baseClass, 'getDatabaseTableName']); | |
113 | } | |
114 | ||
115 | /** | |
116 | * @inheritDoc | |
117 | */ | |
118 | public static function getDatabaseTableIndexIsIdentity() | |
119 | { | |
120 | return \call_user_func([static::$baseClass, 'getDatabaseTableIndexIsIdentity']); | |
121 | } | |
122 | ||
123 | /** | |
124 | * @inheritDoc | |
125 | */ | |
126 | public static function getDatabaseTableIndexName() | |
127 | { | |
128 | return \call_user_func([static::$baseClass, 'getDatabaseTableIndexName']); | |
129 | } | |
130 | ||
131 | /** | |
132 | * Returns the name of the base class. | |
133 | * | |
134 | * @return string | |
135 | */ | |
136 | public static function getBaseClass() | |
137 | { | |
138 | return static::$baseClass; | |
139 | } | |
140 | ||
141 | /** | |
142 | * Returns the decorated object | |
143 | * | |
144 | * @return DatabaseObject | |
145 | */ | |
146 | public function getDecoratedObject() | |
147 | { | |
148 | return $this->object; | |
149 | } | |
11ade432 | 150 | } |