Proyectos de Subversion LeadersLinked - Backend

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
16701 efrain 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace LeadersLinked\Validator;
6
 
7
use Laminas\Validator\AbstractValidator;
8
use Laminas\Validator\NotEmpty;
9
 
10
class NotEmptyConditionalLessThan extends NotEmpty
11
{
12
    /**
13
     *
14
     * @var string
15
     */
16
    private $token;
17
 
18
    /**
19
     *
20
     * @var mixed
21
     */
22
    private $token_value;
23
 
24
    /**
25
     *
26
     * @var boolean
27
     */
28
    private $inclusive;
29
 
30
 
31
 
32
    public function __construct($options = null)
33
    {
34
 
35
        if (! array_key_exists('token', $options)) {
36
            throw new \InvalidArgumentException("Missing option 'token'");
37
        }
38
 
39
        if (! array_key_exists('token_value', $options)) {
40
            throw new \InvalidArgumentException("Missing option 'token_value'");
41
        }
42
 
43
        if (! array_key_exists('inclusive', $options)) {
44
 
45
            $options['inclusive'] = false;
46
 
47
        }
48
 
49
 
50
        $this->token        =  $options['token'];
51
        $this->token_value        =  $options['token_value'];
52
        $this->inclusive    =  $options['inclusive'];
53
 
54
        parent::__construct($options);
55
    }
56
 
57
    public function isValid($token_value, $context = null)
58
    {
59
        $token = isset($context[$this->token]) ? $context[$this->token] : '';
60
 
61
        if($this->inclusive) {
62
            $ok = $token <= $this->token_value;
63
        } else {
64
            $ok = $token < $this->token_value;
65
        }
66
 
67
        if($ok) {
68
            return parent::isValid($token_value, $context = null);
69
        } else {
70
            return true;
71
        }
72
    }
73
}