@@ -12,8 +12,18 @@ abstract class QueryFilter
12
12
/** @var Builder */
13
13
protected $ realBuilder ;
14
14
15
+ /**
16
+ * Here, default parameters for functions are saved
17
+ * @var array
18
+ */
15
19
public array $ default = [];
16
20
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
+
17
27
public function __construct (Builder $ builder )
18
28
{
19
29
$ this ->realBuilder = $ builder ;
@@ -36,11 +46,18 @@ public function apply(array $validated)
36
46
{
37
47
$ validatedKeys = array_keys ($ validated );
38
48
$ defaultKeys = array_keys ($ this ->default );
49
+ $ fallbackKeys = array_keys ($ this ->fallback );
50
+
39
51
foreach ($ this ->filters () as $ filter ) {
40
52
if (in_array ($ filter , $ validatedKeys )) {
41
53
$ this ->$ filter ($ validated [$ filter ], $ validated );
42
54
} elseif (in_array ($ filter , $ defaultKeys )) {
43
55
$ 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 );
44
61
}
45
62
}
46
63
return $ this ;
0 commit comments