@@ -73,7 +73,7 @@ function (...$arguments): Model {
73
73
Request::macro (
74
74
'getFiltered ' ,
75
75
/**
76
- * @param string|int $filter can be 'alpha', 'alnum', 'digits', 'int', 'boolean' or an int flag
76
+ * @param string|int $filter can be 'alpha', 'alnum', 'digits' or an int flag
77
77
* @see ParameterBag::filter(), \filter_var() for $filter and $options
78
78
* @see ParameterBag::getAlpha()
79
79
* @see ParameterBag::getAlnum()
@@ -89,16 +89,28 @@ function (
89
89
): mixed {
90
90
/** @var Request $this */
91
91
if (\is_int ($ filter )) {
92
- if ($ this ->attributes ->has ($ key )) {
93
- return $ this ->attributes ->filter ($ key , $ default , $ filter , $ options );
94
- }
95
-
96
- if ($ this ->query ->has ($ key )) {
97
- return $ this ->query ->filter ($ key , $ default , $ filter , $ options );
98
- }
99
-
100
- if ($ this ->request ->has ($ key )) {
101
- return $ this ->request ->filter ($ key , $ default , $ filter , $ options );
92
+ try {
93
+ if ($ this ->attributes ->has ($ key )) {
94
+ return $ this ->attributes ->filter ($ key , $ default , $ filter , $ options );
95
+ }
96
+
97
+ if ($ this ->query ->has ($ key )) {
98
+ return $ this ->query ->filter ($ key , $ default , $ filter , $ options );
99
+ }
100
+
101
+ if ($ this ->request ->has ($ key )) {
102
+ return $ this ->request ->filter ($ key , $ default , $ filter , $ options );
103
+ }
104
+ } catch (\UnexpectedValueException $ e ) {
105
+ if (\config ('crud.REQUEST_GET_FILTERED_MACRO_SHOULD_THROW_ON_FAILURE ' , false )) {
106
+ throw $ e ;
107
+ }
108
+
109
+ if (!\is_array ($ options ) && $ options ) {
110
+ $ options = ['flags ' => $ options ];
111
+ }
112
+
113
+ return ($ options ['flags ' ] ?? 0 ) & \FILTER_NULL_ON_FAILURE ? null : false ;
102
114
}
103
115
104
116
return $ default ;
@@ -107,7 +119,7 @@ function (
107
119
if ($ filter !== '' ) {
108
120
$ filter = \ucfirst (\strtolower ($ filter ));
109
121
110
- if (!\in_array ($ filter , ['Alpha ' , 'Alnum ' , 'Digits ' , ' Int ' , ' Boolean ' ], true )) {
122
+ if (!\in_array ($ filter , ['Alpha ' , 'Alnum ' , 'Digits ' ], true )) {
111
123
$ filter = '' ;
112
124
}
113
125
}
@@ -122,8 +134,10 @@ function (
122
134
if ($ this ->request ->has ($ key )) {
123
135
return $ this ->request ->{'get ' . $ filter }($ key , $ default );
124
136
}
137
+ } catch (\UnexpectedValueException ) {
125
138
} catch (\Throwable $ e ) {
126
- Log::error ($ e ->getMessage (), $ e ->getTrace ());
139
+ Log::error (__FILE__ . ': ' . __LINE__ . ' Request::getFiltered macro error: ' .
140
+ $ e ->getMessage () . ' for: ' . \json_encode (\func_get_args ()), $ e ->getTrace ());
127
141
}
128
142
129
143
return $ default ;
0 commit comments