-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
FilterIn.php
40 lines (37 loc) · 966 Bytes
/
FilterIn.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
/**
* @link https://github.com/illuminatech
* @copyright Copyright (c) 2019 Illuminatech
* @license [New BSD License](http://www.opensource.org/licenses/bsd-license.php)
*/
namespace Illuminatech\DataProvider\Filters;
/**
* FilterIn picks up records with attribute value inside requested set.
*
* Usage example:
*
* ```php
* DataProvider(Item::class)
* ->filters([
* 'categories' => new FilterIn('category_id'),
* ]);
* ```
*
* Requested set can be specified either as comma-separated string or as array.
*
* @author Paul Klimov <[email protected]>
* @since 1.0
*/
class FilterIn extends FilterRelatedRecursive
{
/**
* {@inheritdoc}
*/
protected function applyInternal(object $source, string $target, string $name, $value): object
{
if (is_scalar($value)) {
$value = array_map('trim', explode(',', $value));
}
return $source->whereIn($target, $value);
}
}