Detect Input Errors
@param string $value        Validation target value
@param string $type         Data type
@param array  $restrictions Restrictions
@return array エラーメッセージを含む配列。 エラーがない場合、0件の配列が返ります。
552648
public function detect_errors($value, $type, $restrictions = array()){
		$errors = array();

		$is_required = @$restrictions['required'];
		if( $is_required && !strlen($value) ){
			// NOT NULL 制約
			// 空白文字も NULL と同様に扱う
			array_push($errors, 'Required.');
			return $errors;
		}
		if( !$is_required && !strlen($value) ){
			// NOT NULL 制約 がなくて値が空白の場合
			// 空白文字も NULL と同様に扱う
			return $errors;
		}

		$type_info = $this->exdb->form_elements()->get_type_info($type);
		if( is_callable($type_info['validate']) ){
			$errors = $type_info['validate']($value, $restrictions);
		}
		return $errors;
	}
693172
private function valid($types, $value) {
        $types = (array) $types;

        foreach($types as $type) {
            switch($type) {
            case self::T_NULL:
                if(is_null($value)) {
                    return true;
                }
                break;
            case self::T_INT:
                if(is_int($value)) {
                    return true;
                }
                break;
            case self::T_STR:
                if(is_string($value)) {
                    return true;
                }
                break;
            case self::T_ARR:
                if(is_array($value)) {
                    return true;
                }
                break;
            }
        }

        return false;
    }
873849
public function validate($value) {
        if(!is_string($value)) {
            throw new DataType('value', 'string', $value);
        }
        
        if(!password_verify($value, $this->hash)) {
            return new ValidationResult(false, 'Wrong password');
        }        
        return new ValidationResult(true);
    }
893762
private function validate($value, $rule, $param)
    {
        if (in_array($rule, $this->reserved)) {
            return array($value, null);
        }
        if (is_array($value) && !in_array($rule, array('minLength', 'maxLength', 'rangeLength'))) {
            $values = $value;
            $errors = array();
            foreach ($values as $key => $value) {
                list($value, $error) = $this->validate($value, $rule, $param);
                $values[$key] = $value;
                if ($error) {
                    $errors[$key] = $error;
                }
            }

            return array($values, !empty($errors) ? array_shift($errors) : null);
        }
        $error = null;
        if ($rule == 'remote') {
            if ('true' != $result = $this->remote($value, $param)) {
                $error = ($result == 'false') ? $this->errorMessage($rule, $param) : $result;
            }
        } elseif (isset($this->rules[$rule]) && is_callable($this->rules[$rule])) {
            if (!is_bool($result = $this->rules[$rule]($value, $param))) {
                $value = $result;
            }
            if ($result === false) {
                $error = $this->errorMessage($rule, $param);
            }
        } elseif (in_array($rule, $this->methods)) {
            if (!is_bool($result = self::$rule($value, $param))) {
                $value = $result;
            }
            if ($result === false) {
                $error = $this->errorMessage($rule, $param);
            }
        }

        return array($value, $error);
    }
1013447
protected function validate_version( $value, $type = '' ) {
		if ( false === $value || empty( $value ) || is_null( $value ) ) {
			return false;
		}

		if ( 'option' === $type ) {
			return version_compare( $this->option_version, $value, '=' );
		}

		return version_compare( $this->transient_version, $value, '=' );
	}
37110
public function validate($value, Constraint $constraint)
    {
        if (!$value instanceof FieldDefinitionData) {
            return;
        }

        $contentTypeData = $value->contentTypeData;
        foreach ($contentTypeData->fieldDefinitionsData as $fieldDefData) {
            if ($fieldDefData === $value) {
                continue;
            }

            if ($value->identifier === $fieldDefData->identifier) {
                $this->context->buildViolation($constraint->message)
                    ->atPath('identifier')
                    ->setParameter('%identifier%', $value->identifier)
                    ->addViolation();
            }
        }
    }
540652
private static function hasType( $value, array $allowedTypes ) {
		// Apply strtolower because gettype returns "NULL" for null values.
		$type = strtolower( gettype( $value ) );

		if ( in_array( $type, $allowedTypes ) ) {
			return true;
		}

		if ( in_array( 'callable', $allowedTypes ) && is_callable( $value ) ) {
			return true;
		}

		if ( is_object( $value ) && self::isInstanceOf( $value, $allowedTypes ) ) {
			return true;
		}

		if ( is_array( $value ) && in_array( 'Traversable', $allowedTypes ) ) {
			return true;
		}

		return false;
	}
515760
public function validate($value, Constraint $constraint)
    {
        if (!$constraint instanceof NotCompromisedPassword) {
            throw new UnexpectedTypeException($constraint, NotCompromisedPassword::class);
        }

        if ($this->disabled) {
            return;
        }

        if (null !== $value && !is_scalar($value) && !(\is_object($value) && method_exists($value, '__toString'))) {
            throw new UnexpectedValueException($value, 'string');
        }

        $value = (string) $value;
        if ('' === $value) {
            return;
        }

        if ('UTF-8' !== $this->charset) {
            $value = mb_convert_encoding($value, 'UTF-8', $this->charset);
        }

        $hash = strtoupper(sha1($value));
        $hashPrefix = substr($hash, 0, 5);
        $url = sprintf(self::RANGE_API, $hashPrefix);

        try {
            $result = $this->httpClient->request('GET', $url)->getContent();
        } catch (ExceptionInterface $e) {
            if ($constraint->skipOnError) {
                return;
            }

            throw $e;
        }

        foreach (explode("\r\n", $result) as $line) {
            list($hashSuffix, $count) = explode(':', $line);

            if ($hashPrefix.$hashSuffix === $hash && $constraint->threshold <= (int) $count) {
                $this->context->buildViolation($constraint->message)
                    ->setCode(NotCompromisedPassword::COMPROMISED_PASSWORD_ERROR)
                    ->addViolation();

                return;
            }
        }
    }
696725
private function isType(string $type, $value)
    {
        switch ($type) {
            case 'bool':
                return is_bool($value);

            case 'int':
                return is_int($value);

            case 'float':
                return is_float($value) || is_int($value);

            case 'string':
                return is_string($value);

            case 'array':
                return is_array($value);

            default:
                throw new InvalidParamsException('Type match error');
        }
    }
918084
static function constrain($value, $constraint, $params = [], $helper = NULL) {
    $constraint_method = get_called_class() . '::check' . $constraint;

    if (! is_callable($constraint_method)) throw new \InvalidArgumentException('Invalid constraint method ' . $constraint_method . ' called');

    return call_user_func_array($constraint_method, [$value, (array) $params, $helper]);
  }
254702
protected function checkRestriction(...$values)
    {
        if ($this->mustRestrict()) {
            foreach ($values as $value) {
                if (!$value instanceof $this->type) {
                    throw new UnsupportedTypeException(
                        sprintf(
                            'The value of type "%s" doesn\'t match type restriction "%s"',
                            $this->getValueType($value),
                            $this->type
                        )
                    );
                }
            }
        }
    }
302147
private function validateType($variable, string $type = 'string', $default = null)
    {
        if (substr($type, -2) == '[]') {
            if (!is_array($variable)) {
                return $default;
            }

            $return = [];
            $hasValue = false;
            foreach ($variable as $key => $current) {
                $return[$key] = $this->validateType($current, substr($type, 0, -2));

                if (!is_null($return[$key])) {
                    $hasValue = true;
                }
            }

            return $hasValue ? $return : $default;
        }

        $options = ['flags' => FILTER_NULL_ON_FAILURE];

        if ($default) {
            $options['options']['default'] = $default;
        }

        switch ($type) {
            case 'int':
            case 'integer':
                $variable = filter_var($variable, FILTER_VALIDATE_INT, $options);
                break;

            case 'float':
                $variable = filter_var($variable, FILTER_VALIDATE_FLOAT, $options);
                break;

            case 'bool':
            case 'boolean':
                if (!is_null($variable)) {
                    $variable = filter_var($variable, FILTER_VALIDATE_BOOLEAN, $options);
                } else {
                    $variable = $default;
                }
                break;

            case 'string':
                $variable = trim(filter_var($variable, FILTER_SANITIZE_STRING, $options));
                $variable = $variable === '' ? $default : $variable;
                break;

            case 'array':
                if (!is_array($variable)) {
                    $variable = $default;
                }
                break;

            case 'date':
            case 'datetime':
            case 'time':
                $variable = $this->parseDate($type, $variable);
                break;

            default:
                throw new \LogicException(sprintf("Invalid filter type '%s'", $type));
        }

        return $variable;
    }
1058258
public function validate($value, Constraint $constraint)
    {
        if ($value === null) {
            return;
        }

        if (!$constraint instanceof Range) {
            throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Range');
        }

        if ($value instanceof \DateTime || $value instanceof \DateTimeInterface) {
            $newValue = clone $value;
            $newValue->setTime(0, 0, 0);
            $value = $newValue;
        }

        if (is_array($constraint->min)) {
            if (!(array_key_exists('service', $constraint->min) && array_key_exists('method', $constraint->min))) {
                throw new ConstraintDefinitionException(sprintf('The value of the option "min" as a factory expects the keys "service" and "method".'));
            }

            $minFactory = array($this->container->get($constraint->min['service']), $constraint->min['method']);
            if (!is_callable($minFactory)) {
                throw new ConstraintDefinitionException(sprintf('"%s::%s" targeted by Range constraint is not a valid callable.', get_class($minFactory[0]), $minFactory[1]));
            }

            $min = call_user_func($minFactory);
            if ($min instanceof \DateTime || $min instanceof \DateTimeInterface) {
                $constraint->min = clone $min;
            } else {
                $constraint->min = $min;
            }
        }

        if (is_array($constraint->max)) {
            if (!(array_key_exists('service', $constraint->max) && array_key_exists('method', $constraint->max))) {
                throw new ConstraintDefinitionException(sprintf('The value of the option "max" as a factory expects the keys "service" and "method".'));
            }

            $maxFactory = array($this->container->get($constraint->max['service']), $constraint->max['method']);
            if (!is_callable($maxFactory)) {
                throw new ConstraintDefinitionException(sprintf('"%s::%s" targeted by Range constraint is not a valid callable.', get_class($maxFactory[0]), $maxFactory[1]));
            }

            $max = call_user_func($maxFactory);
            if ($max instanceof \DateTime || $max instanceof \DateTimeInterface) {
                $constraint->max = clone $max;
            } else {
                $constraint->max = $max;
            }
        }

        return parent::validate($value, $constraint);
    }
14996
public function validate($value, Constraint $constraint)
    {
        if (!$value instanceof FieldDefinitionData) {
            return;
        }

        $fieldType = $this->fieldTypeService->getFieldType($value->getFieldTypeIdentifier());
        $this->processValidationErrors($fieldType->validateValidatorConfiguration($value->validatorConfiguration));
    }
823591
private function _check($value, $rule_type, $rule_value)
    {
        switch ($rule_type) {
            case 'required':
                return !empty($value);
                break;
            case 'func':
                return call_user_func($rule_value, $value);
                break;
            case 'regex':
                return $this->match($value, $rule_value);
                break;
            case 'type':
                return $this->$rule_value($value);
                break;
            case 'max':
            case 'min':
            case 'range':
            case 'in':
                return $this->$rule_type($value, $rule_value);
                break;
            default:
                return true;
        }
    }
732035
private function validatePaginationValue($value, ?array $ruleIndexes): int
    {
        // no validation rule means we should accept any input value
        if ($ruleIndexes === null) {
            return is_numeric($value) === true ? (int)$value : 0;
        }

        $ruleIndex = $this->serializerClass::readRuleMainIndex($ruleIndexes);

        $this->validationStarts(static::PARAM_PAGE, $ruleIndexes);
        $this->validateAndThrowOnError(static::PARAM_PAGE, $value, $ruleIndex);
        $this->validateEnds(static::PARAM_PAGE, $ruleIndexes);

        $validatedValue = $this->readSingleCapturedValue();

        return (int)$validatedValue;
    }
191046
public function addTypeError($value, $type = '') {
        $type = $type ?: $this->getType();

        $this->validation->addError(
            $this->getName(),
            'type',
            [
                'type' => $type,
                'value' => is_scalar($value) ? $value : null,
                'messageCode' => is_scalar($value) ? "{value} is not a valid $type." : "The value is not a valid $type."
            ]
        );

        return $this;
    }