-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathFilterScope.php
48 lines (45 loc) · 1014 Bytes
/
FilterScope.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
41
42
43
44
45
46
47
48
<?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;
/**
* FilterScope applies specified scope method passing filter value inside it.
*
* Configuration example:
*
* ```php
* DataProvider(Item::class)
* ->filters([
* 'allow_purchase' => new FilterScope('allowPurchase'),
* ]);
* ```
*
* Model example:
*
* ```php
* class Item extends Model
* {
* public function scopeAllowPurchase(Builder $query, bool $allowPurchase)
* {
* // ...
* }
* }
* ```
*
* @author Paul Klimov <[email protected]>
* @since 1.0
*/
class FilterScope extends FilterRelatedRecursive
{
/**
* {@inheritdoc}
*/
protected function applyInternal(object $source, string $target, string $name, $value): object
{
$source->{$this->target}($value);
return $source;
}
}