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
Integer.php
62 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\Sanitizer; |
| 15 | use Give\Vendors\StellarWP\Validation\Contracts\ValidatesOnFrontEnd; |
| 16 | use Give\Vendors\StellarWP\Validation\Contracts\ValidationRule; |
| 17 | |
| 18 | class Integer implements ValidationRule, ValidatesOnFrontEnd, Sanitizer |
| 19 | { |
| 20 | /** |
| 21 | * @inheritDoc |
| 22 | */ |
| 23 | public static function id(): string |
| 24 | { |
| 25 | return 'integer'; |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * @inheritDoc |
| 30 | */ |
| 31 | public static function fromString(string $options = null): ValidationRule |
| 32 | { |
| 33 | return new self(); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * @inheritDoc |
| 38 | */ |
| 39 | public function sanitize($value) |
| 40 | { |
| 41 | return (int)$value; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * @inheritDoc |
| 46 | */ |
| 47 | public function serializeOption() |
| 48 | { |
| 49 | return null; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * @inheritDoc |
| 54 | */ |
| 55 | public function __invoke($value, Closure $fail, string $key, array $values) |
| 56 | { |
| 57 | if (is_bool($value) || false === filter_var($value, FILTER_VALIDATE_INT)) { |
| 58 | $fail(sprintf(__('%s must be an integer', 'give'), '{field}')); |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 |