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
Numeric.php
61 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 Numeric implements ValidationRule, ValidatesOnFrontEnd |
| 18 | { |
| 19 | /** |
| 20 | * @inheritDoc |
| 21 | * |
| 22 | * @unreleased |
| 23 | */ |
| 24 | public static function id(): string |
| 25 | { |
| 26 | return 'numeric'; |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * @inheritDoc |
| 31 | * |
| 32 | * @unreleased |
| 33 | */ |
| 34 | public static function fromString(string $options = null): ValidationRule |
| 35 | { |
| 36 | return new self(); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * @inheritDoc |
| 41 | * |
| 42 | * @unreleased |
| 43 | */ |
| 44 | public function serializeOption() |
| 45 | { |
| 46 | return null; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * @inheritDoc |
| 51 | * |
| 52 | * @unreleased |
| 53 | */ |
| 54 | public function __invoke($value, Closure $fail, string $key, array $values) |
| 55 | { |
| 56 | if (!is_numeric($value)) { |
| 57 | $fail(sprintf(__('%s must be numeric', 'give'), '{field}')); |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 |