1 | <?php |
||
13 | abstract class ActiveRecord |
||
14 | { |
||
15 | /** |
||
16 | * The core model object |
||
17 | * @var object |
||
18 | */ |
||
19 | protected $object; |
||
20 | |||
21 | /** |
||
22 | * The object type in WordPress |
||
23 | */ |
||
24 | const OBJECT_TYPE = ''; |
||
25 | |||
26 | /** |
||
27 | * The name of the primary ID property on the object |
||
28 | */ |
||
29 | const ID_PROPERTY = ''; |
||
30 | |||
31 | /** |
||
32 | * Save the changes to the database. |
||
33 | * |
||
34 | * @return $this |
||
35 | */ |
||
36 | public function save() |
||
42 | |||
43 | /** |
||
44 | * Delete the record from the database. |
||
45 | * |
||
46 | * @return $this |
||
47 | */ |
||
48 | public function delete() |
||
54 | |||
55 | /** |
||
56 | * Load and set the object from the database. |
||
57 | * |
||
58 | * @return $this |
||
59 | */ |
||
60 | public function refresh() |
||
66 | |||
67 | /** |
||
68 | * Meta API for this type |
||
69 | * |
||
70 | * @param string $key Meta key to retreive or empty to retreive all. |
||
71 | * |
||
72 | * @return object |
||
73 | */ |
||
74 | public function meta($key = '') |
||
84 | |||
85 | /** |
||
86 | * Update the core object |
||
87 | * |
||
88 | * @param object $object |
||
89 | * |
||
90 | * @return $this |
||
91 | */ |
||
92 | public function setObject($object) |
||
98 | |||
99 | /** |
||
100 | * Set the primary ID on the model. |
||
101 | * |
||
102 | * @param string|int $id The model's ID |
||
103 | * |
||
104 | * @return $this |
||
105 | */ |
||
106 | public function setId($id) |
||
112 | |||
113 | /** |
||
114 | * Get the map of action => class for resolving active actions. |
||
115 | * |
||
116 | * @return array |
||
117 | */ |
||
118 | abstract protected function actionClasses(); |
||
119 | |||
120 | /** |
||
121 | * Perform a database action. |
||
122 | * |
||
123 | * @return void |
||
124 | */ |
||
125 | protected function activeAction($action) |
||
133 | |||
134 | /** |
||
135 | * Execute the active action |
||
136 | * |
||
137 | * @return void |
||
138 | */ |
||
139 | protected function executeAction(Executable $action) |
||
143 | |||
144 | /** |
||
145 | * Magic getter. |
||
146 | * |
||
147 | * @param string $property |
||
148 | * |
||
149 | * @return mixed |
||
150 | */ |
||
151 | public function __get($property) |
||
163 | |||
164 | /** |
||
165 | * Magic Isset Checker. |
||
166 | * |
||
167 | * @return bool |
||
168 | */ |
||
169 | public function __isset($property) |
||
173 | |||
174 | /** |
||
175 | * Magic setter. |
||
176 | * |
||
177 | * @param string $property The property name |
||
178 | * @param mixed $value The new property value |
||
179 | */ |
||
180 | public function __set($property, $value) |
||
186 | } |
||
187 |