@@ -19,7 +19,7 @@ class FilterVar
19
19
/**
20
20
* Create a new FilterVar instance.
21
21
*
22
- * @param array<string, mixed> $config Configuration array, optionally containing 'custom_filters'
22
+ * @param array<string, mixed> $config Configuration array, optionally containing 'custom_filters'
23
23
*/
24
24
public function __construct (array $ config = [])
25
25
{
@@ -35,47 +35,49 @@ protected function getDefaultFilters(): array
35
35
{
36
36
return [
37
37
'Capitalize ' => Filters \Capitalize::class,
38
- 'Cast ' => Filters \Cast::class,
39
- 'Escape ' => Filters \EscapeHTML::class,
38
+ 'Cast ' => Filters \Cast::class,
39
+ 'Escape ' => Filters \EscapeHTML::class,
40
40
'FormatDate ' => Filters \FormatDate::class,
41
- 'Lowercase ' => Filters \Lowercase::class,
42
- 'Uppercase ' => Filters \Uppercase::class,
43
- 'Trim ' => Filters \Trim::class,
44
- 'StripTags ' => Filters \StripTags::class,
45
- 'Digit ' => Filters \Digit::class,
46
- 'FilterIf ' => Filters \FilterIf::class,
41
+ 'Lowercase ' => Filters \Lowercase::class,
42
+ 'Uppercase ' => Filters \Uppercase::class,
43
+ 'Trim ' => Filters \Trim::class,
44
+ 'StripTags ' => Filters \StripTags::class,
45
+ 'Digit ' => Filters \Digit::class,
46
+ 'FilterIf ' => Filters \FilterIf::class,
47
47
];
48
48
}
49
49
50
50
/**
51
51
* Apply a single filter to a value.
52
52
*
53
- * @param array{0: string, 1?: array<string, mixed>} $rule Filter name and optional options
54
- * @param mixed $value The value to filter
55
- * @return mixed The filtered value
53
+ * @param array{0: string, 1?: array<string, mixed>} $rule Filter name and optional options
54
+ * @param mixed $value The value to filter
56
55
*
57
56
* @throws InvalidArgumentException If the filter name is not registered
57
+ *
58
+ * @return mixed The filtered value
58
59
*/
59
60
protected function applyFilter (array $ rule , mixed $ value ): mixed
60
61
{
61
62
$ name = $ rule [0 ];
62
63
$ options = $ rule [1 ] ?? [];
63
64
64
- if (! isset ($ this ->filters [$ name ])) {
65
+ if (!isset ($ this ->filters [$ name ])) {
65
66
throw new InvalidArgumentException ("No filter registered for the name ' $ name'. " );
66
67
}
67
68
68
69
/** @var Filter $filter */
69
- $ filter = new $ this ->filters [$ name ];
70
+ $ filter = new $ this ->filters [$ name ]() ;
70
71
71
72
return $ filter ->apply ($ value , $ options );
72
73
}
73
74
74
75
/**
75
76
* Apply a chain of filters to a value based on a rule string.
76
77
*
77
- * @param string $ruleString Filter rules (e.g., "trim|uppercase")
78
- * @param mixed $value The value to filter
78
+ * @param string $ruleString Filter rules (e.g., "trim|uppercase")
79
+ * @param mixed $value The value to filter
80
+ *
79
81
* @return mixed The filtered value
80
82
*/
81
83
public function filterValue (string $ ruleString , mixed $ value ): mixed
0 commit comments