File tree Expand file tree Collapse file tree 5 files changed +261
-158
lines changed
Expand file tree Collapse file tree 5 files changed +261
-158
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Utopia \Http \Validator ;
4+
5+ use Utopia \Http \Validator ;
6+
7+ /**
8+ * Ensure all of the validators from a list passed the check
9+ *
10+ * @package Utopia\Validator
11+ */
12+ class AllOf extends Validator
13+ {
14+ /**
15+ * @param array<Validator> $validators
16+ */
17+ public function __construct (protected array $ validators , protected string $ type = self ::TYPE_MIXED )
18+ {
19+ }
20+
21+ /**
22+ * Get Description
23+ *
24+ * Returns validator description
25+ *
26+ * @return string
27+ */
28+ public function getDescription (): string
29+ {
30+ $ description = '' ;
31+ foreach ($ this ->validators as $ key => $ rule ) {
32+ $ description .= ++$ key . '. ' . $ rule ->getDescription () . " \n" ;
33+ }
34+
35+ return $ description ;
36+ }
37+
38+ /**
39+ * Is valid
40+ *
41+ * Validation will pass when all rules are valid if only one of the rules is invalid validation will fail.
42+ *
43+ * @param mixed $value
44+ * @return bool
45+ */
46+ public function isValid (mixed $ value ): bool
47+ {
48+ foreach ($ this ->validators as $ rule ) {
49+ $ valid = $ rule ->isValid ($ value );
50+
51+ if (!$ valid ) {
52+ return false ;
53+ }
54+ }
55+
56+ return true ;
57+ }
58+
59+ /**
60+ * Get Type
61+ *
62+ * Returns validator type.
63+ *
64+ * @return string
65+ */
66+ public function getType (): string
67+ {
68+ return $ this ->type ;
69+ }
70+
71+ /**
72+ * Is array
73+ *
74+ * Function will return true if object is array.
75+ *
76+ * @return bool
77+ */
78+ public function isArray (): bool
79+ {
80+ return true ;
81+ }
82+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Utopia \Http \Validator ;
4+
5+ use Utopia \Http \Validator ;
6+
7+ /**
8+ * Ensure at least one validator from a list passed the check
9+ *
10+ * @package Utopia\Validator
11+ */
12+ class AnyOf extends Validator
13+ {
14+ /**
15+ * @param array<Validator> $validators
16+ */
17+ public function __construct (protected array $ validators , protected string $ type = self ::TYPE_MIXED )
18+ {
19+ }
20+
21+ /**
22+ * Get Description
23+ *
24+ * Returns validator description
25+ *
26+ * @return string
27+ */
28+ public function getDescription (): string
29+ {
30+ $ description = '' ;
31+ foreach ($ this ->validators as $ key => $ rule ) {
32+ $ description .= ++$ key . '. ' . $ rule ->getDescription () . " \n" ;
33+ }
34+
35+ return $ description ;
36+ }
37+
38+ /**
39+ * Is valid
40+ *
41+ * Validation will pass when all rules are valid if only one of the rules is invalid validation will fail.
42+ *
43+ * @param mixed $value
44+ * @return bool
45+ */
46+ public function isValid (mixed $ value ): bool
47+ {
48+ foreach ($ this ->validators as $ rule ) {
49+ $ valid = $ rule ->isValid ($ value );
50+
51+ if ($ valid ) {
52+ return true ;
53+ }
54+ }
55+
56+ return false ;
57+ }
58+
59+ /**
60+ * Get Type
61+ *
62+ * Returns validator type.
63+ *
64+ * @return string
65+ */
66+ public function getType (): string
67+ {
68+ return $ this ->type ;
69+ }
70+
71+ /**
72+ * Is array
73+ *
74+ * Function will return true if object is array.
75+ *
76+ * @return bool
77+ */
78+ public function isArray (): bool
79+ {
80+ return true ;
81+ }
82+ }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Utopia \Http \Validator ;
4+
5+ use Utopia \Http \Validator ;
6+
7+ /**
8+ * Ensure no validators from a list passed the check
9+ *
10+ * @package Utopia\Validator
11+ */
12+ class NoneOf extends Validator
13+ {
14+ /**
15+ * @param array<Validator> $validators
16+ */
17+ public function __construct (protected array $ validators , protected string $ type = self ::TYPE_MIXED )
18+ {
19+ }
20+
21+ /**
22+ * Get Description
23+ *
24+ * Returns validator description
25+ *
26+ * @return string
27+ */
28+ public function getDescription (): string
29+ {
30+ $ description = '' ;
31+ foreach ($ this ->validators as $ key => $ rule ) {
32+ $ description .= ++$ key . '. ' . $ rule ->getDescription () . " \n" ;
33+ }
34+
35+ return $ description ;
36+ }
37+
38+ /**
39+ * Is valid
40+ *
41+ * Validation will pass when all rules are valid if only one of the rules is invalid validation will fail.
42+ *
43+ * @param mixed $value
44+ * @return bool
45+ */
46+ public function isValid (mixed $ value ): bool
47+ {
48+ foreach ($ this ->validators as $ rule ) {
49+ $ valid = $ rule ->isValid ($ value );
50+
51+ if ($ valid ) {
52+ return false ;
53+ }
54+ }
55+
56+ return true ;
57+ }
58+
59+ /**
60+ * Get Type
61+ *
62+ * Returns validator type.
63+ *
64+ * @return string
65+ */
66+ public function getType (): string
67+ {
68+ return $ this ->type ;
69+ }
70+
71+ /**
72+ * Is array
73+ *
74+ * Function will return true if object is array.
75+ *
76+ * @return bool
77+ */
78+ public function isArray (): bool
79+ {
80+ return true ;
81+ }
82+ }
You can’t perform that action at this time.
0 commit comments