Validation.php
62 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Maps validation rule string names to their rule class implementations. |
| 5 | * Serves as the central registry consumed by the Validator to resolve rule tokens like required, email, and unique. |
| 6 | * Keeps rule discovery declarative and extensible. |
| 7 | * |
| 8 | * @package Framework |
| 9 | * @subpackage Validation\Constants |
| 10 | * @since 1.0.0 |
| 11 | */ |
| 12 | namespace Kirki\Framework\Validation\Constants; |
| 13 | |
| 14 | \defined('ABSPATH') || exit; |
| 15 | use Kirki\Framework\Validation\Rules\AfterRule; |
| 16 | use Kirki\Framework\Validation\Rules\ArrayRule; |
| 17 | use Kirki\Framework\Validation\Rules\BooleanRule; |
| 18 | use Kirki\Framework\Validation\Rules\DateFormatRule; |
| 19 | use Kirki\Framework\Validation\Rules\DateRule; |
| 20 | use Kirki\Framework\Validation\Rules\DateTimeRule; |
| 21 | use Kirki\Framework\Validation\Rules\EmailRule; |
| 22 | use Kirki\Framework\Validation\Rules\EmailUniqueRule; |
| 23 | use Kirki\Framework\Validation\Rules\ExistsRule; |
| 24 | use Kirki\Framework\Validation\Rules\FloatRule; |
| 25 | use Kirki\Framework\Validation\Rules\GreaterThanEqualRule; |
| 26 | use Kirki\Framework\Validation\Rules\GreaterThanRule; |
| 27 | use Kirki\Framework\Validation\Rules\InRule; |
| 28 | use Kirki\Framework\Validation\Rules\IntegerRule; |
| 29 | use Kirki\Framework\Validation\Rules\IsValidImageIdRule; |
| 30 | use Kirki\Framework\Validation\Rules\LessThanEqualRule; |
| 31 | use Kirki\Framework\Validation\Rules\LessThanRule; |
| 32 | use Kirki\Framework\Validation\Rules\MaxRule; |
| 33 | use Kirki\Framework\Validation\Rules\MinRule; |
| 34 | use Kirki\Framework\Validation\Rules\NotInRule; |
| 35 | use Kirki\Framework\Validation\Rules\NullableRule; |
| 36 | use Kirki\Framework\Validation\Rules\NumberRule; |
| 37 | use Kirki\Framework\Validation\Rules\ObjectRule; |
| 38 | use Kirki\Framework\Validation\Rules\ProhibitedIfRule; |
| 39 | use Kirki\Framework\Validation\Rules\ProhibitedRule; |
| 40 | use Kirki\Framework\Validation\Rules\RegexRule; |
| 41 | use Kirki\Framework\Validation\Rules\RequiredIfExists; |
| 42 | use Kirki\Framework\Validation\Rules\RequiredIfRule; |
| 43 | use Kirki\Framework\Validation\Rules\RequiredIfSiblingRule; |
| 44 | use Kirki\Framework\Validation\Rules\RequiredRule; |
| 45 | use Kirki\Framework\Validation\Rules\SameAsRule; |
| 46 | use Kirki\Framework\Validation\Rules\Sanitizer; |
| 47 | use Kirki\Framework\Validation\Rules\StringRule; |
| 48 | use Kirki\Framework\Validation\Rules\UniqueRule; |
| 49 | use Kirki\Framework\Validation\Rules\UrlRule; |
| 50 | use Kirki\Framework\Validation\Rules\UserExists; |
| 51 | class Validation |
| 52 | { |
| 53 | /** |
| 54 | * The rules to validator method map |
| 55 | * |
| 56 | * @var array |
| 57 | * |
| 58 | * @since 3.3.0 |
| 59 | */ |
| 60 | public const RULE_MAP = ['required' => RequiredRule::class, 'string' => StringRule::class, 'array' => ArrayRule::class, 'object' => ObjectRule::class, 'boolean' => BooleanRule::class, 'integer' => IntegerRule::class, 'number' => NumberRule::class, 'float' => FloatRule::class, 'email' => EmailRule::class, 'email_unique' => EmailUniqueRule::class, 'unique' => UniqueRule::class, 'url' => UrlRule::class, 'exists' => ExistsRule::class, 'min' => MinRule::class, 'max' => MaxRule::class, 'in' => InRule::class, 'not_in' => NotInRule::class, 'regex' => RegexRule::class, 'sanitize' => Sanitizer::class, 'same_as' => SameAsRule::class, 'nullable' => NullableRule::class, 'date' => DateRule::class, 'datetime' => DateTimeRule::class, 'date_format' => DateFormatRule::class, 'is_valid_image_id' => IsValidImageIdRule::class, 'required_if' => RequiredIfRule::class, 'required_if_sibling' => RequiredIfSiblingRule::class, 'prohibited' => ProhibitedRule::class, 'prohibited_if' => ProhibitedIfRule::class, 'required_if_exists' => RequiredIfExists::class, 'user_exists' => UserExists::class, 'after' => AfterRule::class, 'gt' => GreaterThanRule::class, 'gte' => GreaterThanEqualRule::class, 'lt' => LessThanRule::class, 'lte' => LessThanEqualRule::class]; |
| 61 | } |
| 62 |