1 | <?php |
||
24 | trait ActiveRecord |
||
25 | { |
||
26 | /** |
||
27 | * @return string |
||
28 | */ |
||
29 | public abstract static function recordClass(): string; |
||
30 | |||
31 | /** |
||
32 | * @return string |
||
33 | */ |
||
34 | public static function recordClassInstance(): string |
||
38 | |||
39 | /** |
||
40 | * @return int|null |
||
41 | */ |
||
42 | protected static function cacheDuration() |
||
46 | |||
47 | /** |
||
48 | * @return null|Dependency |
||
49 | */ |
||
50 | protected static function cacheDependency() |
||
54 | |||
55 | /** |
||
56 | * @param array $config |
||
57 | * @return \yii\db\ActiveQuery |
||
58 | */ |
||
59 | public static function getQuery($config = []): ActiveQuery |
||
75 | |||
76 | /** |
||
77 | * @return Connection |
||
78 | */ |
||
79 | public static function getDb(): Connection |
||
86 | |||
87 | /** |
||
88 | * @return TableSchema |
||
89 | * @throws \yii\base\InvalidConfigException |
||
90 | */ |
||
91 | public static function getTableSchema(): TableSchema |
||
98 | |||
99 | /******************************************* |
||
100 | * CREATE |
||
101 | *******************************************/ |
||
102 | |||
103 | /** |
||
104 | * @param array $attributes |
||
105 | * @param string $toScenario |
||
106 | * @return Record |
||
107 | */ |
||
108 | public function create(array $attributes = [], string $toScenario = null): Record |
||
128 | |||
129 | |||
130 | /******************************************* |
||
131 | * FIND / GET |
||
132 | *******************************************/ |
||
133 | |||
134 | /** |
||
135 | * @param string $toScenario |
||
136 | * @return Record[] |
||
137 | */ |
||
138 | public function findAll(string $toScenario = null) |
||
142 | |||
143 | /** |
||
144 | * @param $identifier |
||
145 | * @param string|null $toScenario |
||
146 | * @return Record|null |
||
147 | */ |
||
148 | public function find($identifier, string $toScenario = null) |
||
159 | |||
160 | /** |
||
161 | * @param $identifier |
||
162 | * @param string $toScenario |
||
163 | * @return Record |
||
164 | * @throws RecordNotFoundException |
||
165 | */ |
||
166 | public function get($identifier, string $toScenario = null): Record |
||
174 | |||
175 | |||
176 | /******************************************* |
||
177 | * ONE CONDITION |
||
178 | *******************************************/ |
||
179 | |||
180 | /** |
||
181 | * @param $condition |
||
182 | * @param string $toScenario |
||
183 | * @return Record|null |
||
184 | */ |
||
185 | public function findByCondition($condition, string $toScenario = null) |
||
192 | |||
193 | /** |
||
194 | * @param $condition |
||
195 | * @param string $toScenario |
||
196 | * @return Record |
||
197 | * @throws RecordNotFoundException |
||
198 | */ |
||
199 | public function getByCondition($condition, string $toScenario = null) |
||
207 | |||
208 | |||
209 | /******************************************* |
||
210 | * ONE CRITERIA |
||
211 | *******************************************/ |
||
212 | |||
213 | /** |
||
214 | * @param $criteria |
||
215 | * @param string|null $toScenario |
||
216 | * @return mixed |
||
217 | */ |
||
218 | public function findByCriteria($criteria, string $toScenario = null) |
||
230 | |||
231 | /** |
||
232 | * @param $criteria |
||
233 | * @param string $toScenario |
||
234 | * @return Record |
||
235 | * @throws RecordNotFoundException |
||
236 | */ |
||
237 | public function getByCriteria($criteria, string $toScenario = null) |
||
245 | |||
246 | |||
247 | /******************************************* |
||
248 | * ALL CONDITION |
||
249 | *******************************************/ |
||
250 | |||
251 | /** |
||
252 | * @param array $condition |
||
253 | * @param string $toScenario |
||
254 | * @return Record[] |
||
255 | */ |
||
256 | public function findAllByCondition($condition = [], string $toScenario = null) |
||
263 | |||
264 | /** |
||
265 | * @param array $condition |
||
266 | * @param string $toScenario |
||
267 | * @return Record[] |
||
268 | * @throws RecordNotFoundException |
||
269 | */ |
||
270 | public function getAllByCondition($condition = [], string $toScenario = null) |
||
278 | |||
279 | /******************************************* |
||
280 | * ALL CRITERIA |
||
281 | *******************************************/ |
||
282 | |||
283 | /** |
||
284 | * @param array $criteria |
||
285 | * @param string $toScenario |
||
286 | * @return Record[] |
||
287 | */ |
||
288 | public function findAllByCriteria($criteria = [], string $toScenario = null) |
||
302 | |||
303 | /** |
||
304 | * @param array $criteria |
||
305 | * @param string $toScenario |
||
306 | * @return Record[] |
||
307 | * @throws RecordNotFoundException |
||
308 | */ |
||
309 | public function getAllByCriteria($criteria = [], string $toScenario = null) |
||
317 | |||
318 | |||
319 | /******************************************* |
||
320 | * CACHE |
||
321 | *******************************************/ |
||
322 | |||
323 | /** |
||
324 | * @param ActiveQuery $query |
||
325 | * @return Record|null |
||
326 | */ |
||
327 | protected function queryOne(ActiveQuery $query) |
||
345 | |||
346 | /** |
||
347 | * @param ActiveQuery $query |
||
348 | * @return Record[] |
||
349 | */ |
||
350 | protected function queryAll(ActiveQuery $query) |
||
368 | |||
369 | /******************************************* |
||
370 | * EXCEPTIONS |
||
371 | *******************************************/ |
||
372 | |||
373 | /** |
||
374 | * @throws RecordNotFoundException |
||
375 | */ |
||
376 | protected function notFoundException() |
||
384 | } |
||
385 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.