AfterRule.php
3 weeks ago
ArrayRule.php
3 weeks ago
BaseRule.php
3 weeks ago
BooleanRule.php
3 weeks ago
DateFormatRule.php
3 weeks ago
DateRule.php
3 weeks ago
DateTimeRule.php
3 weeks ago
EmailRule.php
3 weeks ago
EmailUniqueRule.php
3 weeks ago
ExistsRule.php
3 weeks ago
FloatRule.php
3 weeks ago
GreaterThanEqualRule.php
3 weeks ago
GreaterThanRule.php
3 weeks ago
InRule.php
3 weeks ago
IntegerRule.php
3 weeks ago
IsValidImageIdRule.php
3 weeks ago
LessThanEqualRule.php
3 weeks ago
LessThanRule.php
3 weeks ago
MaxRule.php
3 weeks ago
MinRule.php
3 weeks ago
NotInRule.php
3 weeks ago
NullableRule.php
3 weeks ago
NumberRule.php
3 weeks ago
ObjectRule.php
3 weeks ago
ProhibitedIfRule.php
3 weeks ago
ProhibitedRule.php
3 weeks ago
RegexRule.php
3 weeks ago
RequiredIfExists.php
3 weeks ago
RequiredIfRule.php
3 weeks ago
RequiredIfSiblingRule.php
3 weeks ago
RequiredRule.php
3 weeks ago
SameAsRule.php
3 weeks ago
Sanitizer.php
3 weeks ago
StringRule.php
3 weeks ago
UniqueRule.php
3 weeks ago
UrlRule.php
3 weeks ago
UserExists.php
3 weeks ago
LessThanEqualRule.php
53 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Rule to ensure the value is after the given date. |
| 5 | * |
| 6 | * @package Framework |
| 7 | * @subpackage Validation\Rules |
| 8 | * @since 1.0.0 |
| 9 | */ |
| 10 | namespace Kirki\Framework\Validation\Rules; |
| 11 | |
| 12 | \defined('ABSPATH') || exit; |
| 13 | use Kirki\Framework\Supports\Date; |
| 14 | use Kirki\Framework\Supports\Str; |
| 15 | use function Kirki\Framework\message; |
| 16 | class LessThanEqualRule extends BaseRule |
| 17 | { |
| 18 | /** |
| 19 | * Check if the rule is valid. |
| 20 | * |
| 21 | * @return bool |
| 22 | * |
| 23 | * @since 1.0.0 |
| 24 | */ |
| 25 | public function validate_rule() |
| 26 | { |
| 27 | $current_value = $this->value; |
| 28 | $target_value = $this->rule_value; |
| 29 | if (!\is_numeric($target_value) && \array_key_exists($target_value, $this->data)) { |
| 30 | $target_value = $this->data[$target_value]; |
| 31 | } |
| 32 | $target_value = Str::to_number($target_value); |
| 33 | if (\is_int($target_value)) { |
| 34 | $current_value = (int) $current_value; |
| 35 | } |
| 36 | if (\is_float($target_value)) { |
| 37 | $current_value = (float) $current_value; |
| 38 | } |
| 39 | return $current_value <= $target_value; |
| 40 | } |
| 41 | /** |
| 42 | * Get the error message if the rule is not valid. |
| 43 | * |
| 44 | * @return string |
| 45 | * |
| 46 | * @since 1.0.0 |
| 47 | */ |
| 48 | public function get_error_message() |
| 49 | { |
| 50 | return message('validator.lte', $this->last_key_segment(), $this->rule_value); |
| 51 | } |
| 52 | } |
| 53 |