summaryrefslogtreecommitdiff
path: root/libs/SimpleValidator/Validators/MaxLength.php
blob: 6c4e777142852cd9905eb8aa9a170ae7ef20cf41 (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
<?php

namespace SimpleValidator\Validators;

class MaxLength extends Base
{
    private $max;

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

    public function execute(array $data)
    {
        if ($this->isFieldNotEmpty($data)) {
            $length = mb_strlen($data[$this->field], 'UTF-8');
            return $length <= $this->max;
        }

        return true;
    }
}