Skip to content

Commit 9ba908b

Browse files
authored
Merge pull request #5 from oooiik/4-if-not-setting
fallback
2 parents 139bf38 + 5de084a commit 9ba908b

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/Filters/QueryFilter.php

+17
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,18 @@ abstract class QueryFilter
1212
/** @var Builder */
1313
protected $realBuilder;
1414

15+
/**
16+
* Here, default parameters for functions are saved
17+
* @var array
18+
*/
1519
public array $default = [];
1620

21+
/**
22+
* Here, if a function does not work, a helper function is shown for it
23+
* @var array
24+
*/
25+
public array $fallback = [];
26+
1727
public function __construct(Builder $builder)
1828
{
1929
$this->realBuilder = $builder;
@@ -36,11 +46,18 @@ public function apply(array $validated)
3646
{
3747
$validatedKeys = array_keys($validated);
3848
$defaultKeys = array_keys($this->default);
49+
$fallbackKeys = array_keys($this->fallback);
50+
3951
foreach ($this->filters() as $filter) {
4052
if (in_array($filter, $validatedKeys)) {
4153
$this->$filter($validated[$filter], $validated);
4254
} elseif (in_array($filter, $defaultKeys)) {
4355
$this->$filter($this->default[$filter], $validated);
56+
} elseif (in_array($filter, $fallbackKeys)) {
57+
if(!in_array($this->fallback[$filter], $this->filters())){
58+
throw new \BadMethodCallException("This method not found!", 500);
59+
}
60+
$this->{$this->fallback[$filter]}(null, $validated);
4461
}
4562
}
4663
return $this;

0 commit comments

Comments
 (0)