1 | <?php |
||
16 | abstract class WC_Data { |
||
17 | |||
18 | /** |
||
19 | * Core data for this object, name value pairs (name + default value). |
||
20 | * @var array |
||
21 | */ |
||
22 | protected $_data = array(); |
||
23 | |||
24 | /** |
||
25 | * Stores meta in cache for future reads. |
||
26 | * A group must be set to to enable caching. |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $_cache_group = ''; |
||
30 | |||
31 | /** |
||
32 | * Meta type. This should match up with |
||
33 | * the types avaiable at https://codex.wordpress.org/Function_Reference/add_metadata. |
||
34 | * WP defines 'post', 'user', 'comment', and 'term'. |
||
35 | */ |
||
36 | protected $_meta_type = 'post'; |
||
37 | |||
38 | /** |
||
39 | * This only needs set if you are using a custom metadata type (for example payment tokens. |
||
40 | * This should be the name of the field your table uses for associating meta with objects. |
||
41 | * For example, in payment_tokenmeta, this would be payment_token_id. |
||
42 | * @var string |
||
43 | */ |
||
44 | protected $object_id_field_for_meta = ''; |
||
45 | |||
46 | /** |
||
47 | * Stores additonal meta data. |
||
48 | * @var array |
||
49 | */ |
||
50 | protected $_meta_data = array(); |
||
51 | |||
52 | /** |
||
53 | * Internal meta keys we don't want exposed for the object. |
||
54 | * @var array |
||
55 | */ |
||
56 | protected $_internal_meta_keys = array(); |
||
57 | |||
58 | /** |
||
59 | * Returns the unique ID for this object. |
||
60 | * @return int |
||
61 | */ |
||
62 | abstract public function get_id(); |
||
63 | |||
64 | /** |
||
65 | * Creates new object in the database. |
||
66 | */ |
||
67 | abstract public function create(); |
||
68 | |||
69 | /** |
||
70 | * Read object from the database. |
||
71 | * @param int ID of the object to load. |
||
72 | */ |
||
73 | abstract public function read( $id ); |
||
74 | |||
75 | /** |
||
76 | * Updates object data in the database. |
||
77 | */ |
||
78 | abstract public function update(); |
||
79 | |||
80 | /** |
||
81 | * Updates object data in the database. |
||
82 | */ |
||
83 | abstract public function delete(); |
||
84 | |||
85 | /** |
||
86 | * Save should create or update based on object existance. |
||
87 | */ |
||
88 | abstract public function save(); |
||
89 | |||
90 | /** |
||
91 | * Change data to JSON format. |
||
92 | * @return string Data in JSON format. |
||
93 | */ |
||
94 | public function __toString() { |
||
97 | |||
98 | /** |
||
99 | * Returns all data for this object. |
||
100 | * @return array |
||
101 | */ |
||
102 | public function get_data() { |
||
105 | |||
106 | /** |
||
107 | * Get All Meta Data |
||
108 | * @since 2.6.0 |
||
109 | * @return array |
||
110 | */ |
||
111 | public function get_meta_data() { |
||
114 | |||
115 | /** |
||
116 | * Internal meta keys we don't want exposed as part of meta_data. This is in |
||
117 | * addition to all data props with _ prefix. |
||
118 | * @since 2.6.0 |
||
119 | * @return array() |
||
|
|||
120 | */ |
||
121 | protected function prefix_key( $key ) { |
||
124 | |||
125 | /** |
||
126 | * Internal meta keys we don't want exposed as part of meta_data. This is in |
||
127 | * addition to all data props with _ prefix. |
||
128 | * @since 2.6.0 |
||
129 | * @return array() |
||
130 | */ |
||
131 | protected function get_internal_meta_keys() { |
||
134 | |||
135 | /** |
||
136 | * Get Meta Data by Key. |
||
137 | * @since 2.6.0 |
||
138 | * @param string $key |
||
139 | * @param bool $single return first found meta with key, or all with $key |
||
140 | * @return mixed |
||
141 | */ |
||
142 | public function get_meta( $key = '', $single = true ) { |
||
156 | |||
157 | /** |
||
158 | * Set all meta data from array. |
||
159 | * @since 2.6.0 |
||
160 | * @param array $data Key/Value pairs |
||
161 | */ |
||
162 | public function set_meta_data( $data ) { |
||
176 | |||
177 | /** |
||
178 | * Add meta data. |
||
179 | * @since 2.6.0 |
||
180 | * @param array $key Meta key |
||
181 | * @param array $value Meta value |
||
182 | * @param array $unique Should this be a unique key? |
||
183 | */ |
||
184 | public function add_meta_data( $key, $value, $unique = false ) { |
||
194 | |||
195 | /** |
||
196 | * Update meta data by key or ID, if provided. |
||
197 | * @since 2.6.0 |
||
198 | * @param string $key |
||
199 | * @param string $value |
||
200 | * @param int $meta_id |
||
201 | */ |
||
202 | public function update_meta_data( $key, $value, $meta_id = '' ) { |
||
217 | |||
218 | /** |
||
219 | * Delete meta data. |
||
220 | * @since 2.6.0 |
||
221 | * @param array $key Meta key |
||
222 | */ |
||
223 | public function delete_meta_data( $key ) { |
||
227 | |||
228 | /** |
||
229 | * Read Meta Data from the database. Ignore any internal properties. |
||
230 | * @since 2.6.0 |
||
231 | */ |
||
232 | protected function read_meta_data() { |
||
275 | |||
276 | /** |
||
277 | * Update Meta Data in the database. |
||
278 | * @since 2.6.0 |
||
279 | */ |
||
280 | protected function save_meta_data() { |
||
313 | |||
314 | /** |
||
315 | * Table structure is slightly different between meta types, this function will return what we need to know. |
||
316 | * @since 2.6.0 |
||
317 | * @return array Array elements: table, object_id_field, meta_id_field |
||
318 | */ |
||
319 | protected function _get_db_info() { |
||
348 | |||
349 | } |
||
350 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.