1 | <?php |
||
7 | trait QueryBuilderTrait |
||
8 | { |
||
9 | /** |
||
10 | * @var |
||
11 | */ |
||
12 | protected $options = []; |
||
13 | /** |
||
14 | * @var |
||
15 | */ |
||
16 | protected $where = []; |
||
17 | /** |
||
18 | * @var |
||
19 | */ |
||
20 | protected $properties = []; |
||
21 | |||
22 | /** |
||
23 | * Retrieve all Items. |
||
24 | * |
||
25 | * @param array $options |
||
26 | * |
||
27 | * @return array |
||
28 | */ |
||
29 | protected function all($options = []) |
||
33 | |||
34 | /** |
||
35 | * Retrieve single Item. |
||
36 | * |
||
37 | * @param int $id |
||
38 | * @param array $options |
||
39 | * |
||
40 | * @return object |
||
41 | */ |
||
42 | protected function find($id, $options = []) |
||
46 | |||
47 | /** |
||
48 | * Create new Item. |
||
49 | * |
||
50 | * @param array $data |
||
51 | * |
||
52 | * @return object |
||
53 | */ |
||
54 | protected function create($data) |
||
58 | |||
59 | /** |
||
60 | * Update Existing Item. |
||
61 | * |
||
62 | * @param int $id |
||
63 | * @param array $data |
||
64 | * |
||
65 | * @return object |
||
66 | */ |
||
67 | protected function update($id, $data) |
||
71 | |||
72 | /** |
||
73 | * Destroy Item. |
||
74 | * |
||
75 | * @param int $id |
||
76 | * @param array $options |
||
77 | * |
||
78 | * @return object |
||
79 | */ |
||
80 | protected function delete($id, $options = []) |
||
84 | |||
85 | /** |
||
86 | * Batch Update. |
||
87 | * |
||
88 | * @param array $data |
||
89 | * |
||
90 | * @return object |
||
91 | */ |
||
92 | protected function batch($data) |
||
96 | |||
97 | /** |
||
98 | * Retrieve data. |
||
99 | * |
||
100 | * @return array |
||
101 | */ |
||
102 | protected function get() |
||
112 | |||
113 | /** |
||
114 | * Retrieve data. |
||
115 | * |
||
116 | * @return object |
||
117 | */ |
||
118 | protected function first() |
||
122 | |||
123 | /** |
||
124 | * Set options for woocommerce request. |
||
125 | * |
||
126 | * @param array $parameters |
||
127 | * |
||
128 | * @return object $this |
||
129 | */ |
||
130 | protected function options($parameters) |
||
146 | |||
147 | /** |
||
148 | * Join options for woocommerce request. |
||
149 | * |
||
150 | * @param array $parameters |
||
151 | * |
||
152 | * @return object $this |
||
153 | */ |
||
154 | protected function where(...$parameters) |
||
175 | |||
176 | /** |
||
177 | * Set order direction. |
||
178 | * |
||
179 | * @param string $name |
||
180 | * @param string $direction |
||
181 | * |
||
182 | * @return object $this |
||
183 | */ |
||
184 | protected function orderBy($name, $direction = 'desc') |
||
191 | |||
192 | /** |
||
193 | * Paginate results. |
||
194 | * |
||
195 | * @param int $per_page |
||
196 | * @param int $current_page |
||
197 | * |
||
198 | * @return array |
||
199 | */ |
||
200 | protected function paginate($per_page, $current_page = 1) |
||
233 | |||
234 | /** |
||
235 | * Count all results. |
||
236 | * |
||
237 | * @return int |
||
238 | */ |
||
239 | protected function count() |
||
250 | |||
251 | /** |
||
252 | * Store data. |
||
253 | * |
||
254 | * @return array |
||
255 | */ |
||
256 | public function save() |
||
262 | } |
||
263 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: