| @@ 47-63 (lines=17) @@ | ||
| 44 | * |
|
| 45 | * @return bool|int |
|
| 46 | */ |
|
| 47 | public function with($value, $with, bool $asString = true) |
|
| 48 | { |
|
| 49 | if ($this->notEmpty($value, $asString)) { |
|
| 50 | return true; |
|
| 51 | } |
|
| 52 | ||
| 53 | $with = (array)$with; |
|
| 54 | foreach ($with as $field) { |
|
| 55 | if (!$this->isEmpty($field, $asString)) { |
|
| 56 | //External field presented, BUT value must not be empty! |
|
| 57 | return false; |
|
| 58 | } |
|
| 59 | } |
|
| 60 | ||
| 61 | //Value is empty, but no external fields are set = value not required |
|
| 62 | return Validator::STOP_VALIDATION; |
|
| 63 | } |
|
| 64 | ||
| 65 | /** |
|
| 66 | * Check if field not empty but only if all of listed fields presented and not empty. |
|
| @@ 75-91 (lines=17) @@ | ||
| 72 | * |
|
| 73 | * @return bool|int |
|
| 74 | */ |
|
| 75 | public function withAll($value, $withAll, bool $asString = true) |
|
| 76 | { |
|
| 77 | if ($this->notEmpty($value, $asString)) { |
|
| 78 | return true; |
|
| 79 | } |
|
| 80 | ||
| 81 | $withAll = (array)$withAll; |
|
| 82 | foreach ($withAll as $field) { |
|
| 83 | if ($this->isEmpty($field, $asString)) { |
|
| 84 | //External field is missing, value becomes non required |
|
| 85 | return Validator::STOP_VALIDATION; |
|
| 86 | } |
|
| 87 | } |
|
| 88 | ||
| 89 | //Value is empty but all external field not empty |
|
| 90 | return false; |
|
| 91 | } |
|
| 92 | ||
| 93 | /** |
|
| 94 | * Check if field not empty but only if one of listed fields missing or empty. |
|
| @@ 104-120 (lines=17) @@ | ||
| 101 | * |
|
| 102 | * @return bool|int |
|
| 103 | */ |
|
| 104 | public function without($value, $without, bool $asString = true) |
|
| 105 | { |
|
| 106 | if ($this->notEmpty($value, $asString)) { |
|
| 107 | return true; |
|
| 108 | } |
|
| 109 | ||
| 110 | $without = (array)$without; |
|
| 111 | foreach ($without as $field) { |
|
| 112 | if (!$this->isEmpty($field, $asString)) { |
|
| 113 | //External field set, field becomes non required |
|
| 114 | return Validator::STOP_VALIDATION; |
|
| 115 | } |
|
| 116 | } |
|
| 117 | ||
| 118 | //Value is empty and no external fields are set |
|
| 119 | return false; |
|
| 120 | } |
|
| 121 | ||
| 122 | /** |
|
| 123 | * Check if field not empty but only if all of listed fields missing or empty. |
|