@@ -66,11 +66,11 @@ protected static function matchStrictType (
6666 {
6767 return match ($ typeOfNeedle )
6868 {
69- 'INT ' => (int ) $ needle ,
70- 'BOOL ' => filter_var ($ needle , FILTER_VALIDATE_BOOLEAN ),
71- 'FLOAT ' => (float ) $ needle ,
72- 'ARRAY ' => json_decode ($ needle , true ),
73- default => $ needle ,
69+ 'INT ' => (int ) $ needle ,
70+ 'BOOL ' => filter_var ($ needle , FILTER_VALIDATE_BOOLEAN ),
71+ 'FLOAT ' => (float ) $ needle ,
72+ 'ARRAY ' => json_decode ($ needle , true ),
73+ default => $ needle ,
7474 };
7575 }
7676
@@ -140,6 +140,23 @@ private static function matches (string $needle, string $haystack): bool
140140 return true ;
141141 }
142142
143+ /**
144+ * MATCH INT<MIN, MAX>
145+ */
146+ if (preg_match ('/INT<(\d+)(?:,\s*(\d+))?>/ ' , $ haystack , $ matches ) && $ typeOfNeedle === 'INT ' )
147+ {
148+ $ min = (int ) $ matches [1 ];
149+ $ max = (int ) $ matches [2 ] ?? null ;
150+ $ needle = (int ) $ needle ;
151+
152+ if ((!$ max && $ min < $ needle ) || $ max && ($ needle < $ min || $ needle > $ max ))
153+ {
154+ $ requested = !$ max ? "INT min ( $ min) " : "INT min ( $ min), max( $ max) " ;
155+ throw new Exception ("Invalid request parameter type. { {$ requested }} requested, but got { {$ needle }} " );
156+ }
157+ return true ;
158+ }
159+
143160 InvalidTypesException::catchInvalidStrictTypes ($ haystack );
144161 return false ;
145162 }
@@ -186,9 +203,9 @@ protected static function typeOfString (string $string): string
186203 {
187204 return match (gettype ($ decoded ))
188205 {
189- 'object ' => 'JSON ' ,
190- 'array ' => 'ARRAY ' ,
191- default => 'STRING ' ,
206+ 'object ' => 'JSON ' ,
207+ 'array ' => 'ARRAY ' ,
208+ default => 'STRING ' ,
192209 };
193210 }
194211
0 commit comments