@@ -199,12 +199,12 @@ protected function _findByPk(mixed $pk): ?array
199
199
}
200
200
201
201
/**
202
- * @param array<string, mixed> $where
202
+ * @param array<string, mixed>|Where $where
203
203
* @param array<string, string>|string $orderBy
204
204
* @return array<string, mixed>|null
205
205
* @throws \Doctrine\DBAL\Exception
206
206
*/
207
- protected function _findOne (array $ where , array |string $ orderBy = []): ?array
207
+ protected function _findOne (array | Where $ where , array |string $ orderBy = []): ?array
208
208
{
209
209
$ query = $ this ->select ();
210
210
$ this ->buildWhere ($ query , $ where );
@@ -241,14 +241,7 @@ protected function _findAll(
241
241
): array
242
242
{
243
243
$ query = $ this ->select ();
244
- if (is_array ($ where )) {
245
- $ this ->buildWhere ($ query , $ where );
246
- } else {
247
- $ query ->where ($ where ->string );
248
- foreach ($ where ->params as $ param => $ value ) {
249
- $ query ->setParameter ($ param , $ value );
250
- }
251
- }
244
+ $ this ->buildWhere ($ query , $ where );
252
245
$ this ->applyOrderBy ($ query , $ orderBy );
253
246
if ($ limit > 0 ) {
254
247
$ query ->setMaxResults ($ limit );
@@ -332,40 +325,47 @@ protected function select(string $select = '*'): QueryBuilder
332
325
}
333
326
334
327
/**
335
- * @param array<string, mixed> $where
328
+ * @param array<string, mixed>|Where $where
336
329
*/
337
- private function buildWhere (QueryBuilder $ query , array $ where ): void
330
+ private function buildWhere (QueryBuilder $ query , array | Where $ where ): void
338
331
{
339
- foreach ($ where as $ column => $ value ) {
340
- if ($ value instanceof \BackedEnum) {
341
- $ value = $ value ->value ;
342
- } elseif ($ value instanceof \UnitEnum) {
343
- $ value = $ value ->name ;
344
- }
332
+ if (is_array ($ where )) {
333
+ foreach ($ where as $ column => $ value ) {
334
+ if ($ value instanceof \BackedEnum) {
335
+ $ value = $ value ->value ;
336
+ } elseif ($ value instanceof \UnitEnum) {
337
+ $ value = $ value ->name ;
338
+ }
345
339
346
- if (is_null ($ value )) {
347
- $ query ->andWhere ($ column . ' IS NULL ' );
348
- } elseif (is_array ($ value ) && count ($ value ) === 2 && \in_array ($ value [0 ], self ::COMPARISON_SIGNS )) {
349
- $ comparisonSign = $ value [0 ];
350
- $ comparisonValue = $ value [1 ];
340
+ if (is_null ($ value )) {
341
+ $ query ->andWhere ($ column . ' IS NULL ' );
342
+ } elseif (is_array ($ value ) && count ($ value ) === 2 && \in_array ($ value [0 ], self ::COMPARISON_SIGNS )) {
343
+ $ comparisonSign = $ value [0 ];
344
+ $ comparisonValue = $ value [1 ];
351
345
352
- // Handle special case of "!= null"
353
- if ($ comparisonSign === '!= ' && is_null ($ comparisonValue )) {
354
- $ query ->andWhere ($ column . ' IS NOT NULL ' );
346
+ // Handle special case of "!= null"
347
+ if ($ comparisonSign === '!= ' && is_null ($ comparisonValue )) {
348
+ $ query ->andWhere ($ column . ' IS NOT NULL ' );
349
+ } else {
350
+ $ query ->andWhere ($ column . ' ' . $ comparisonSign . ' : ' . $ column )
351
+ ->setParameter ($ column , $ comparisonValue );
352
+ }
353
+ } elseif (is_array ($ value )) {
354
+ $ placeholders = [];
355
+ foreach ($ value as $ index => $ val ) {
356
+ $ placeholders [] = ': ' . $ column . $ index ;
357
+ $ query ->setParameter ($ column . $ index , $ val );
358
+ }
359
+ $ query ->andWhere ($ column . ' IN( ' . implode (', ' , $ placeholders ) . ') ' );
355
360
} else {
356
- $ query ->andWhere ($ column . ' ' . $ comparisonSign . ' : ' . $ column )
357
- ->setParameter ($ column , $ comparisonValue );
358
- }
359
- } elseif (is_array ($ value )) {
360
- $ placeholders = [];
361
- foreach ($ value as $ index => $ val ) {
362
- $ placeholders [] = ': ' . $ column . $ index ;
363
- $ query ->setParameter ($ column . $ index , $ val );
361
+ $ query ->andWhere ($ column . ' = : ' . $ column )
362
+ ->setParameter ($ column , $ value );
364
363
}
365
- $ query ->andWhere ($ column . ' IN( ' . implode (', ' , $ placeholders ) . ') ' );
366
- } else {
367
- $ query ->andWhere ($ column . ' = : ' . $ column )
368
- ->setParameter ($ column , $ value );
364
+ }
365
+ } else {
366
+ $ query ->where ($ where ->string );
367
+ foreach ($ where ->params as $ param => $ value ) {
368
+ $ query ->setParameter ($ param , $ value );
369
369
}
370
370
}
371
371
}
0 commit comments