1 | <?php |
||
12 | abstract class ActiveRecord |
||
13 | { |
||
14 | /** |
||
15 | * The core model object |
||
16 | * @var object |
||
17 | */ |
||
18 | protected $object; |
||
19 | |||
20 | /** |
||
21 | * The object type in WordPress |
||
22 | */ |
||
23 | const OBJECT_TYPE = ''; |
||
24 | |||
25 | /** |
||
26 | * The name of the primary ID property on the object |
||
27 | */ |
||
28 | const ID_PROPERTY = ''; |
||
29 | |||
30 | /** |
||
31 | * Save the changes to the database. |
||
32 | * |
||
33 | * @return $this |
||
34 | */ |
||
35 | public function save() |
||
41 | |||
42 | /** |
||
43 | * Delete the record from the database. |
||
44 | * |
||
45 | * @return $this |
||
46 | */ |
||
47 | public function delete() |
||
53 | |||
54 | /** |
||
55 | * Load and set the object from the database. |
||
56 | * |
||
57 | * @return $this |
||
58 | */ |
||
59 | public function refresh() |
||
65 | |||
66 | /** |
||
67 | * Simple existence checking |
||
68 | * |
||
69 | * @return bool |
||
70 | */ |
||
71 | public function exists() |
||
75 | |||
76 | /** |
||
77 | * Meta API for this type |
||
78 | * |
||
79 | * @param string $key Meta key to retreive or empty to retreive all. |
||
80 | * |
||
81 | * @return object |
||
82 | */ |
||
83 | public function meta($key = '') |
||
93 | |||
94 | /** |
||
95 | * Update the core object |
||
96 | * |
||
97 | * @param object $object |
||
98 | */ |
||
99 | public function setObject($object) |
||
105 | |||
106 | /** |
||
107 | * Set the primary ID on the model. |
||
108 | * |
||
109 | * @param string|int $id The model's ID |
||
110 | * |
||
111 | * @return $this |
||
112 | */ |
||
113 | public function setId($id) { |
||
118 | |||
119 | /** |
||
120 | * Get the map of action => class for resolving active actions. |
||
121 | * |
||
122 | * @return array |
||
123 | */ |
||
124 | abstract protected function actionClasses(); |
||
125 | |||
126 | /** |
||
127 | * Perform a database action. |
||
128 | * |
||
129 | * @return void |
||
130 | */ |
||
131 | protected function activeAction($action) |
||
139 | |||
140 | /** |
||
141 | * Execute the active action |
||
142 | */ |
||
143 | private function executeAction(Executable $action) |
||
147 | |||
148 | /** |
||
149 | * Magic getter. |
||
150 | * |
||
151 | * @param string $property |
||
152 | * |
||
153 | * @return mixed |
||
154 | */ |
||
155 | public function __get($property) |
||
167 | |||
168 | /** |
||
169 | * Magic Isset Checker. |
||
170 | */ |
||
171 | public function __isset($property) |
||
175 | |||
176 | /** |
||
177 | * Magic setter. |
||
178 | * |
||
179 | * @param string $property The property name |
||
180 | * @param mixed $value The new property value |
||
181 | */ |
||
182 | public function __set($property, $value) |
||
188 | } |
||
189 |