<?php
namespace ThurData\Servers\KerioEmail\App\Validators;
use ThurData\Servers\KerioEmail\Core\UI\Widget\Forms\Validators\BaseValidator;
use ThurData\Servers\KerioEmail\Core\UI\Widget\Forms\Validators\boolen;

/**
 * Class EmailValidator
 * User: ThurData
 * Date: 2019-10-01
 * Time: 08:29
 */

class EmailValidator extends BaseValidator
{

    /**
     * return true if data is valid, false if not,
     * add error messages to $errorsList
     *
     * @param $data mixed
     * @param $additionalData mixed
     * @return boolen
     */
    protected function validate($data, $additionalData = null)
    {
        /**
         * if is empty
         */
        if(!strlen(trim($data)) > 0)
        {
            return true;
        }

        /**
         * check if correct email
         */
        if (filter_var($data, FILTER_VALIDATE_EMAIL))
        {
            $this->addValidationError('incorrectEmailAddress');
            return false;
        }

        return true;
    }
}