(non-PHPdoc)

@see \mithra62\Validate\RuleInterface::validate()
@ignore
766930
public function validate($field, $input, array $params = array())
    {
        try {
            if ($input == '' || empty($params['0'])) {
                return false;
            }
            
            $params = $params['0'];
            if (empty($params['ftp_hostname']) || empty($params['ftp_password']) || empty($params['ftp_username']) || empty($params['ftp_port'])) {
                return false;
            }
            
            $filesystem = new Remote(Ftp::getRemoteClient($params));
            if (! $filesystem->getAdapter()->listContents()) {
                return false;
            }
            
            $filesystem->getAdapter()->disconnect();
            return true;
        } catch (\Exception $e) {
            return false;
        }
    }
1167903
public function validate(&$error = null)
    {
        if (!$this->isCountryCodeValid()) {
            $error = 'IBAN country code not valid or not supported';
        } elseif (!$this->isLengthValid()) {
            $error = 'IBAN length is invalid';
        } elseif (!$this->isFormatValid()) {
            $error = 'IBAN format is invalid';
        } elseif (!$this->isChecksumValid()) {
            $error = 'IBAN checksum is invalid';
        } else {
            $error = '';
            return true;
        }

        return false;
    }
1227192
public function validate(array $parameters = array()) {
        $validated= false;
        $this->reset();
        $stopOnFail= isset($parameters['stopOnFail']) && $parameters['stopOnFail']
                ? true
                : false;
        $stopOnRuleFail= isset($parameters['stopOnRuleFail']) && $parameters['stopOnRuleFail']
                ? true
                : false;
        if (!empty($this->object->_validationRules)) {
            foreach ($this->object->_validationRules as $column => $rules) {
                $this->results[$column]= $this->object->isValidated($column);
                if (!$this->results[$column]) {
                    $columnResults= array();
                    foreach ($rules as $ruleName => $rule) {
                        $result= false;
                        if (is_array($rule['parameters'])) $rule['parameters']['column'] = $column;
                        switch ($rule['type']) {
                            case 'callable':
                                $callable= $rule['rule'];
                                if (is_callable($callable)) {
                                     $result= call_user_func_array($callable, array($this->object->_fields[$column],$rule['parameters']));
                                    if (!$result) $this->addMessage($column, $ruleName, isset($rule['parameters']['message']) ? $rule['parameters']['message'] : $ruleName . ' failed');
                                } else {
                                    $this->object->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Validation function {$callable} is not a valid callable function.");
                                }
                                break;
                            case 'preg_match':
                                $result= (boolean) preg_match($rule['rule'], $this->object->_fields[$column]);
                                if (!$result) $this->addMessage($column, $ruleName, isset($rule['parameters']['message']) ? $rule['parameters']['message'] : $ruleName . ' failed');
                                if ($this->object->xpdo->getDebug() === true)
                                    $this->object->xpdo->log(xPDO::LOG_LEVEL_DEBUG, "preg_match validation against {$rule['rule']} resulted in " . print_r($result, 1));
                                break;
                            case 'xPDOValidationRule':
                                if ($ruleClass= $rule['rule']) {
                                    if (strpos($ruleClass, '\\') === false && strpos($ruleClass, '.') === false) {
                                        $ruleClass = __NAMESPACE__ . '\\' . $ruleClass;
                                    }
                                    if ($ruleObject= new $ruleClass($this, $column, $ruleName)) {
                                        $callable= array($ruleObject, 'isValid');
                                        if (is_callable($callable)) {
                                            $callableParams= array($this->object->_fields[$column], $rule['parameters']);
                                            $result= call_user_func_array($callable, $callableParams);
                                        } else {
                                            $this->object->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Validation rule class {$rule['rule']} does not have an isValid() method.");
                                        }
                                    }
                                } else {
                                    $this->object->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not load validation rule class: {$rule['rule']}");
                                }
                                break;
                            default:
                                $this->object->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Unsupported validation rule: " . print_r($rule, true));
                                break;
                        }
                        $columnResults[$ruleName]= $result;
                        if (!$result && $stopOnRuleFail) {
                            break;
                        }
                    }
                    $this->results[$column]= !in_array(false, $columnResults, true) ? true : false;
                    if (!$this->results[$column] && $stopOnFail) {
                        break;
                    }
                }
                if ($this->results[$column]) {
                    $this->object->_validated[$column]= $column;
                }
            }
            if (empty($this->results) || !in_array(false, $this->results, true)) {
                $validated = true;
                if ($this->object->xpdo->getDebug() === true)
                    $this->object->xpdo->log(xPDO::LOG_LEVEL_WARN, "Validation succeeded: " . print_r($this->results, true));
            } elseif ($this->object->xpdo->getDebug() === true) {
                $this->object->xpdo->log(xPDO::LOG_LEVEL_WARN, "Validation failed: " . print_r($this->results, true));
            }
        } else {
            if ($this->object->xpdo->getDebug() === true) $this->object->xpdo->log(xPDO::LOG_LEVEL_DEBUG, "Validation called but no rules were found.");
            $validated = true;
        }
        return $validated;
    }
634523
public function validate($rule, $value)
    {
        $arguments = $this->buildArgumentArray($rule, $value);

        $method = $this->makeRuleMethod($rule);

        if ($this->userDefinedExists($method)) {
            $class = NameResolver::makeRulesFileName();

            return call_user_func_array([$class, $method], $arguments);
        } elseif (method_exists(Rules::class, $method)) {
            return call_user_func_array([Rules::class, $method], $arguments);
        }

        throw InvalidSettingsRule::ruleNotFound($rule, $method);
    }
735805
protected function _validate($value)
    {
        $value = trim($value);
        return ((string) $value === $this->sanitize($value));
    }
259141
public function validate()
    {
        $this->debug->groupCollapsed(__METHOD__, $this->attribs['name']);
        $this->props['isValid'] = true;
        $this->classRemove($this->props['attribsContainer'], 'has-error');
        $attribs = $this->attribs;
        if (\in_array($attribs['type'], array('checkbox','radio','select'))) {  // these types use the 'options' array
            $this->validateCrs();
        } elseif (\in_array($attribs['type'], array('submit','reset','image'))) {
            $this->debug->log('not checking');
        } elseif (!empty($this->props['newPage'])) {
            $this->debug->log('not checking newPage');
        } elseif (\in_array($attribs['type'], array('file'))) {
            $this->debug->log($attribs['name'].' is a file type');
            if ($this->isRequired() && empty($attribs['disabled']) && empty($attribs['value'])) {
                $this->flag();
            }
        } elseif ($this->isRequired() || $this->props['flagNonReqInvalid']) {
            if (!empty($attribs['placeholder']) && $attribs['value'] === $attribs['placeholder']) {
                $this->debug->log('value == placeholder');
                $attribs['value'] = null;
            }
            $this->validateFromAttributes();
        }
        if ($this->props['isValid']) {
            $isValid = $this->doValidate();
            // validate callback may call flag() directly
            if ($this->props['isValid'] && !$isValid) {
                $this->flag();
            }
        }
        $this->debug->groupEnd();
        return $this->props['isValid'];
    }
933878
public function validate() {
        if (!$this->_data) {
            return false;
        }

        $fields = $this->getFields();
        $messages = $this->getMessages();

        foreach ($this->_data as $field => $value) {
            if (empty($this->_rules[$field])) {
                continue;
            }

            foreach ($this->_rules[$field] as $rule => $params) {
                $options = $params['options'];
                $arguments = $options;
                array_unshift($arguments, $value);

                // Use G11n if it is available
                if (class_exists('Titon\G11n\Utility\Validate')) {
                    $class = 'Titon\G11n\Utility\Validate';
                } else {
                    $class = 'Titon\Utility\Validate';
                }

                if (!call_user_func(array($class, 'hasMethod'), $rule)) {
                    throw new InvalidValidationRuleException(sprintf('Validation rule %s does not exist', $rule));
                }

                // Prepare messages
                $message = $params['message'];

                if (!$message && isset($messages[$rule])) {
                    $message = $messages[$rule];
                }

                if ($message) {
                    $message = String::insert($message, array_map(function($value) {
                        return is_array($value) ? implode(', ', $value) : $value;
                    }, $options + array(
                        'field' => $field,
                        'title' => $fields[$field]
                    )));
                } else {
                    throw new InvalidValidationRuleException(sprintf('Error message for rule %s does not exist', $rule));
                }

                if (!call_user_func_array(array($class, $rule), $arguments)) {
                    $this->addError($field, $message);
                    break;
                }
            }
        }

        return empty($this->_errors);
    }
772147
public function validate($value)
    {
        return ($value instanceof \stdClass && count((array) $value) <= $this->size)
            || parent::validate($value);
    }
1141391
public function validate(array $input, array $ruleset)
    {
        $this->errors = array();

        foreach ($ruleset as $field => $rules) {
            #if(!array_key_exists($field, $input))
            #{
            #   continue;
            #}

            $rules = explode('|', $rules);

            if (in_array('required', $rules) || (isset($input[$field]) && trim($input[$field]) != '')) {
                foreach ($rules as $rule) {
                    $method = null;
                    $param = null;

                    if (strstr($rule, ',') !== false) {
                        // has params

                        $rule = explode(',', $rule);
                        $method = 'validate_'.$rule[0];
                        $param = $rule[1];
                        $rule = $rule[0];
                    } else {
                        $method = 'validate_'.$rule;
                    }

                    if (is_callable(array($this, $method))) {

                        $result = $this->$method($field, $input, $param);

                        if (is_array($result)) {
                            // Validation Failed

                            $this->errors[] = $result;
                        }
                    } elseif (isset($this->validation_methods[$rule])) {
                        if (isset($input[$field])) {
                            $result = call_user_func($this->validation_methods[$rule], $field, $input, $param);


                            if (!$result) {
                                // Validation Failed

                                $this->errors[] = array(
                                    'field' => $field,
                                    'value' => $input[$field],
                                    'rule' => $method,
                                    'param' => $param,
                                );
                            }
                        }
                    } else {
                        throw new Exception("Validator method '$method' does not exist.");
                    }
                }
            }
        }

        $this->compileMessage();

        return $this;
    }
427188
public function validate($value, Constraint $constraint)
    {
        $block = $constraint->block;
        if ($block instanceof BlockInterface && true === $block->isTransverse() && !empty($value)) {
            $blockCode = $this->repository->findOneTransverseBlockByCode($value, $block->getLanguage(), $block->getSiteId());
            if (null !== $blockCode && $blockCode->getId() !== $block->getId()) {
                $this->context->buildViolation($constraint->message)
                    ->atPath('code')
                    ->addViolation();
            }
        }

    }
586823
protected function validate()
    {
        $args = $this->dispatcher->getParam('args');
        if (isset($this->actions[$this->actionName])) {
            $action = $this->actions[$this->actionName];
            $action->validate($args);
        }
    }
314805
public function validate($args)
    {
        $check = $this->normalizeArgs(is_array($args) ? $args : []);

        return is_array($check) ? true : $check;
    }
667716
public function validate($validator)
    {
        if ($this->checkHostname($this->Value())) {
            return true;
        }

        $validator->validationError(
            $this->getName(),
            _t('DomainNameField.INVALID_DOMAIN', 'Invalid domain name'),
            'validation'
        );
        return false;
    }
694960
public function validate(&$params)
    {
        if (!is_array($params)) {
            throw new InvalidArgumentException('Please use array params when call validate.');
        }
        $rules = $this->validators;

        if (count($params) < count($rules)) {
            if (!isset($this->defaultValues) || empty($this->defaultValues)) {
                throw new InvalidArgumentException('The params are less than validators.');
            }
            $defaultValues = $this->defaultValues;

            foreach ($defaultValues as $key => $value) {
                if (!isset($params[$key])) {
                    $params[$key] = $value;
                }

            }
        } elseif (count($params) > count($rules)) {
            throw new InvalidArgumentException('The params are more than validators.');
        }
        foreach ($rules as $key => $rule) {
            if (isset($params[$key])) {
                if (is_array($rule)) {
                    $isError = true;

                    foreach ($rule as $subRule) {
                        if (call_user_func([$subRule, 'validate'], $params[$key]) === true) {
                            $isError = false;
                            break;
                        }
                    }
                    if ($isError) {
                        throw new RuntimeException('Wrong type of ' . $this->method . ' method argument ' . $key . '.');
                    }
                } else {
                    if (call_user_func([$rule, 'validate'], $params[$key]) === false) {
                        throw new RuntimeException('Wrong type of ' . $this->method . ' method argument ' . $key . '.');
                    }
                }
            } else {
                throw new RuntimeException($this->method . ' method argument ' . $key . ' doesn\'t have default value.');
            }
        }
        return true;
    }
967633
public function validate()
    {
        $valid = true;
        $message = null;
        $type = $this->Type;

        // Check if empty strings
        switch ($type) {
            case 'URL':
            case 'Email':
            case 'Phone':
                if ($this->{$type} == '') {
                    $valid = false;
                    $message = _t(
                        __CLASS__ . '.VALIDATIONERROR_EMPTY'.strtoupper($type),
                        'You must enter a {TypeLabel}',
                        [
                            'TypeLabel' => $this->TypeLabel
                        ]
                    );
                }
                break;
            case 'File':
            case 'SiteTree':
                if ($type && empty($this->{$type.'ID'})) {
                    $valid = false;
                    $message = _t(
                        __CLASS__ . '.VALIDATIONERROR_OBJECT',
                        'Please select a {TypeLabel}',
                        [
                            'TypeLabel' => $this->TypeLabel
                        ]
                    );
                }
                break;
        }
        // if its already failed don't bother checking the rest
        if ($valid) {
            switch ($type) {
                case 'URL':
                    $allowedFirst = ['#', '/'];
                    if (!in_array(substr($this->URL, 0, 1), $allowedFirst) && !filter_var($this->URL, FILTER_VALIDATE_URL)) {
                        $valid = false;
                        $message = _t(
                            __CLASS__ . '.VALIDATIONERROR_VALIDURL',
                            'Please enter a valid URL.  Be sure to include http:// for an external URL. or begin your internal url/anchor with a "/" character'
                        );
                    }
                    break;
                case 'Email':
                    if (!filter_var($this->Email, FILTER_VALIDATE_EMAIL)) {
                        $valid = false;
                        $message = _t(
                            __CLASS__ . '.VALIDATIONERROR_VALIDEMAIL',
                            'Please enter a valid Email address'
                        );
                    }
                    break;
                case 'Phone':
                    if (!preg_match("/^\+?[0-9a-zA-Z\-\s]*[\,\#]?[0-9\-\s]*$/", $this->Phone)) {
                        $valid = false;
                        $message = _t(
                            __CLASS__ . '.VALIDATIONERROR_VALIDPHONE',
                            'Please enter a valid Phone number'
                        );
                    }
                    break;
            }
        }

        $result = ValidationResult::create();
        if (!$valid) {
            $result->addError($message);
        }

        $this->extend('updateValidate', $result);

        return $result;
    }
954637
public function validate($rules = [], $errors = [])
    {
        foreach ($rules as $param => $subRules) {
            $paramValue = $this->getParam($param);
            foreach ($subRules as $key => $rule) {
                $isError = false;
                if (!is_array($rule)) {
                    switch ($rule) {
                        case self::VALIDATE_REQUIRED:
                            if (is_null($paramValue)) {
                                $isError = true;
                            }
                            break;
                        case self::VALIDATE_MOBILE:
                            if (!ValidationHelper::isMobile($paramValue)) {
                                $isError = true;
                            }
                            break;
                    }
                } else {
                    switch ($key) {
                    case self::VALIDATE_ENUM:
                        if (!in_array($paramValue, $rule)) {
                            $isError = true;
                        }
                        break;
                    }
                }
                if ($isError) {
                    $errCode = self::ERROR_INVALID_PARAM;
                    $errMsg = self::errorMsg[self::ERROR_INVALID_PARAM];
                    if (is_array($rule)) {
                        $rule = $key;
                    }
                    if (isset($errors[$param][$rule]['code'])) {
                        $errCode = $errors[$param][$rule]['code'];
                    }
                    if (isset($errors[$param][$rule]['msg'])) {
                        $errMsg = str_replace('{param}', $param, $errors[$param][$rule]['msg']);
                    }
                    throw new ParamException($errMsg, $errCode);
                }
            }
        }
    }
308345
public function validate($input): bool
    {
        $this->error = null; // clean
        foreach ($this->rules as $rule) {
            if (!$rule->validate($input)) {
                // apply custom description or use description from rule
                $this->setError($this->description ?? $rule->getDescription());
                return false;
            }
        }
        return true;
    }