File tree Expand file tree Collapse file tree 4 files changed +40
-2
lines changed Expand file tree Collapse file tree 4 files changed +40
-2
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,8 @@ class In extends Rule
9
9
10
10
protected $ message = "The :attribute is not allowing :value " ;
11
11
12
+ protected $ strict = false ;
13
+
12
14
public function fillParameters (array $ params )
13
15
{
14
16
if (count ($ params ) == 1 AND is_array ($ params [0 ])) {
@@ -18,12 +20,17 @@ public function fillParameters(array $params)
18
20
return $ this ;
19
21
}
20
22
23
+ public function strict ($ strict = true )
24
+ {
25
+ $ this ->strict = $ strict ;
26
+ }
27
+
21
28
public function check ($ value )
22
29
{
23
30
$ this ->requireParameters (['allowed_values ' ]);
24
31
25
32
$ allowed_values = $ this ->parameter ('allowed_values ' );
26
- return in_array ($ value , $ allowed_values );
33
+ return in_array ($ value , $ allowed_values, $ this -> strict );
27
34
}
28
35
29
36
}
Original file line number Diff line number Diff line change @@ -9,6 +9,8 @@ class NotIn extends Rule
9
9
10
10
protected $ message = "The :attribute is not allowing :value " ;
11
11
12
+ protected $ strict = false ;
13
+
12
14
public function fillParameters (array $ params )
13
15
{
14
16
if (count ($ params ) == 1 AND is_array ($ params [0 ])) {
@@ -18,11 +20,16 @@ public function fillParameters(array $params)
18
20
return $ this ;
19
21
}
20
22
23
+ public function strict ($ strict = true )
24
+ {
25
+ $ this ->strict = $ strict ;
26
+ }
27
+
21
28
public function check ($ value )
22
29
{
23
30
$ this ->requireParameters (['disallowed_values ' ]);
24
31
$ disallowed_values = (array ) $ this ->parameter ('disallowed_values ' );
25
- return !in_array ($ value , $ disallowed_values );
32
+ return !in_array ($ value , $ disallowed_values, $ this -> strict );
26
33
}
27
34
28
35
}
Original file line number Diff line number Diff line change @@ -21,4 +21,16 @@ public function testInvalids()
21
21
$ this ->assertFalse ($ this ->rule ->fillParameters ([1 ,2 ,3 ])->check (4 ));
22
22
}
23
23
24
+ public function testStricts ()
25
+ {
26
+ // Not strict
27
+ $ this ->assertTrue ($ this ->rule ->fillParameters (['1 ' , '2 ' , '3 ' ])->check (1 ));
28
+ $ this ->assertTrue ($ this ->rule ->fillParameters (['1 ' , '2 ' , '3 ' ])->check (true ));
29
+
30
+ // Strict
31
+ $ this ->rule ->strict ();
32
+ $ this ->assertFalse ($ this ->rule ->fillParameters (['1 ' , '2 ' , '3 ' ])->check (1 ));
33
+ $ this ->assertFalse ($ this ->rule ->fillParameters (['1 ' , '2 ' , '3 ' ])->check (1 ));
34
+ }
35
+
24
36
}
Original file line number Diff line number Diff line change @@ -21,4 +21,16 @@ public function testInvalids()
21
21
$ this ->assertFalse ($ this ->rule ->fillParameters (['bar ' , 'baz ' , 'qux ' ])->check ('bar ' ));
22
22
}
23
23
24
+ public function testStricts ()
25
+ {
26
+ // Not strict
27
+ $ this ->assertFalse ($ this ->rule ->fillParameters (['1 ' , '2 ' , '3 ' ])->check (1 ));
28
+ $ this ->assertFalse ($ this ->rule ->fillParameters (['1 ' , '2 ' , '3 ' ])->check (true ));
29
+
30
+ // Strict
31
+ $ this ->rule ->strict ();
32
+ $ this ->assertTrue ($ this ->rule ->fillParameters (['1 ' , '2 ' , '3 ' ])->check (1 ));
33
+ $ this ->assertTrue ($ this ->rule ->fillParameters (['1 ' , '2 ' , '3 ' ])->check (1 ));
34
+ }
35
+
24
36
}
You can’t perform that action at this time.
0 commit comments