Currency.php
3 years ago
Email.php
3 years ago
Integer.php
3 years ago
Max.php
3 years ago
Min.php
3 years ago
Numeric.php
3 years ago
Required.php
3 years ago
Size.php
3 years ago
Required.php
53 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @license GPL-2.0-or-later |
| 4 | * |
| 5 | * Modified by impress-org on 27-April-2023 using Strauss. |
| 6 | * @see https://github.com/BrianHenryIE/strauss |
| 7 | */ |
| 8 | |
| 9 | declare(strict_types=1); |
| 10 | |
| 11 | namespace Give\Vendors\StellarWP\Validation\Rules; |
| 12 | |
| 13 | use Closure; |
| 14 | use Give\Vendors\StellarWP\Validation\Contracts\ValidatesOnFrontEnd; |
| 15 | use Give\Vendors\StellarWP\Validation\Contracts\ValidationRule; |
| 16 | |
| 17 | class Required implements ValidationRule, ValidatesOnFrontEnd |
| 18 | { |
| 19 | /** |
| 20 | * @inheritDoc |
| 21 | */ |
| 22 | public static function id(): string |
| 23 | { |
| 24 | return 'required'; |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * @inheritDoc |
| 29 | */ |
| 30 | public static function fromString(string $options = null): ValidationRule |
| 31 | { |
| 32 | return new self(); |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * @inheritDoc |
| 37 | */ |
| 38 | public function __invoke($value, Closure $fail, string $key, array $values) |
| 39 | { |
| 40 | if (!isset($values[$key]) || $value === null || $value === '') { |
| 41 | $fail(sprintf(__('%s is required', 'give'), '{field}')); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * @inheritDoc |
| 47 | */ |
| 48 | public function serializeOption(): bool |
| 49 | { |
| 50 | return true; |
| 51 | } |
| 52 | } |
| 53 |