AutorÃa | Ultima modificación | Ver Log |
<?php
declare(strict_types=1);
namespace LeadersLinked\Validator;
use Laminas\Validator\AbstractValidator;
use Laminas\Validator\NotEmpty;
class NotEmptyConditionalLessThan extends NotEmpty
{
/**
*
* @var string
*/
private $token;
/**
*
* @var mixed
*/
private $token_value;
/**
*
* @var boolean
*/
private $inclusive;
public function __construct($options = null)
{
if (! array_key_exists('token', $options)) {
throw new \InvalidArgumentException("Missing option 'token'");
}
if (! array_key_exists('token_value', $options)) {
throw new \InvalidArgumentException("Missing option 'token_value'");
}
if (! array_key_exists('inclusive', $options)) {
$options['inclusive'] = false;
}
$this->token = $options['token'];
$this->token_value = $options['token_value'];
$this->inclusive = $options['inclusive'];
parent::__construct($options);
}
public function isValid($token_value, $context = null)
{
$token = isset($context[$this->token]) ? $context[$this->token] : '';
if($this->inclusive) {
$ok = $token <= $this->token_value;
} else {
$ok = $token < $this->token_value;
}
if($ok) {
return parent::isValid($token_value, $context = null);
} else {
return true;
}
}
}