summaryrefslogtreecommitdiff
path: root/libs/SimpleValidator/Validators/Equals.php
blob: 6b69dd80702e4855a27a247f82a4f2e77fc94851 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php

namespace SimpleValidator\Validators;

class Equals extends Base
{
    private $field2;

    public function __construct($field1, $field2, $error_message)
    {
        parent::__construct($field1, $error_message);
        $this->field2 = $field2;
    }

    public function execute(array $data)
    {
        if ($this->isFieldNotEmpty($data)) {
            if (! isset($data[$this->field2])) {
                return false;
            }

            return $data[$this->field] === $data[$this->field2];
        }

        return true;
    }
}