Proyectos de Subversion LeadersLinked - Backend

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 www 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 NotEmptyConditional extends NotEmpty
11
{
12
    /**
13
     *
14
     * @var string
15
     */
16
    private $token;
17
 
18
    /**
19
     *
20
     * @var $mixed
21
     */
22
    private $condition;
23
 
24
 
25
    public function __construct($options = null)
26
    {
27
 
28
        if (! array_key_exists('token', $options)) {
29
            throw new \InvalidArgumentException("Missing option 'token'");
30
        }
31
 
32
        if (! array_key_exists('condition', $options)) {
33
            throw new \InvalidArgumentException("Missing option 'condition'");
34
        }
35
 
36
 
37
        $this->token        =  $options['token'];
38
        $this->condition    =  $options['condition'];
39
 
40
        parent::__construct($options);
41
    }
42
 
43
    public function isValid($value, $context = null)
44
    {
45
        $token = isset($context[$this->token]) ? $context[$this->token] : '';
46
        if($token == $this->condition) {
47
            return parent::isValid($value, $context = null);
48
        } else {
49
            return true;
50
        }
51
    }
52
}