Added detailed list of received/given likes in user profiles
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / data / DatabaseObjectDecorator.class.php
1 <?php
2 namespace wcf\data;
3 use wcf\system\exception\SystemException;
4
5 /**
6 * Basic implementation for object decorators.
7 *
8 * @author Marcel Werk
9 * @copyright 2001-2014 WoltLab GmbH
10 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
11 * @package com.woltlab.wcf
12 * @subpackage data
13 * @category Community Framework
14 */
15 abstract class DatabaseObjectDecorator extends DatabaseObject {
16 /**
17 * name of the base class
18 * @var string
19 */
20 protected static $baseClass = '';
21
22 /**
23 * decorated object
24 * @var \wcf\data\DatabaseObject
25 */
26 protected $object = null;
27
28 /**
29 * Creates a new DatabaseObjectDecorator object.
30 *
31 * @param \wcf\data\DatabaseObject $object
32 */
33 public function __construct(DatabaseObject $object) {
34 if (empty(static::$baseClass)) {
35 throw new SystemException('Base class not specified');
36 }
37
38 if (!($object instanceof static::$baseClass)) {
39 throw new SystemException("Object does not match '".static::$baseClass."' (given object is of class '".get_class($object)."')");
40 }
41
42 $this->object = $object;
43 }
44
45 /**
46 * @see \wcf\data\IStorableObject::__get()
47 */
48 public function __get($name) {
49 return $this->object->__get($name);
50 }
51
52 /**
53 * @see \wcf\data\IStorableObject::__isset()
54 */
55 public function __isset($name) {
56 return $this->object->__isset($name);
57 }
58
59 /**
60 * @see \wcf\data\DatabaseObject::getObjectID()
61 */
62 public function getObjectID() {
63 return $this->object->getObjectID();
64 }
65
66 /**
67 * Delegates inaccessible methods calls to the decorated object.
68 *
69 * @param string $name
70 * @param array $arguments
71 * @return mixed
72 */
73 public function __call($name, $arguments) {
74 if (!method_exists($this->object, $name) && !($this->object instanceof DatabaseObjectDecorator)) {
75 throw new SystemException("unknown method '".$name."'");
76 }
77
78 return call_user_func_array(array($this->object, $name), $arguments);
79 }
80
81 /**
82 * @see \wcf\data\IStorableObject::getDatabaseTableAlias()
83 */
84 public static function getDatabaseTableAlias() {
85 return call_user_func(array(static::$baseClass, 'getDatabaseTableAlias'));
86 }
87
88 /**
89 * @see \wcf\data\IStorableObject::getDatabaseTableName()
90 */
91 public static function getDatabaseTableName() {
92 return call_user_func(array(static::$baseClass, 'getDatabaseTableName'));
93 }
94
95 /**
96 * @see \wcf\data\IStorableObject::getDatabaseTableIndexIsIdentity()
97 */
98 public static function getDatabaseTableIndexIsIdentity() {
99 return call_user_func(array(static::$baseClass, 'getDatabaseTableIndexIsIdentity'));
100 }
101
102 /**
103 * @see \wcf\data\IStorableObject::getDatabaseTableIndexName()
104 */
105 public static function getDatabaseTableIndexName() {
106 return call_user_func(array(static::$baseClass, 'getDatabaseTableIndexName'));
107 }
108
109 /**
110 * Returns the name of the base class.
111 *
112 * @return string
113 */
114 public static function getBaseClass() {
115 return static::$baseClass;
116 }
117
118 /**
119 * Returns the decorated object
120 *
121 * @return \wcf\data\DatabaseObject
122 */
123 public function getDecoratedObject() {
124 return $this->object;
125 }
126 }