Run the value through the configured validator

@param mixed $value
@param Parameter $definition
@access protected

@throw Exception

@return mixed
19678
protected function validateValue($value, $definition)
    {
        try {
            return $definition->getValidator()->validate($value);
        } catch (\Exception $e) {
            throw new \Exception(sprintf('[%s] %s', $definition->getName(), $e->getMessage()));
        }
    }
1276189
public function validateValueType($value)
    {
        if ($this->hasOption(Entity\Reflection\Property\Option\Primary::KEY)
            && (Entity\Reflection\Property\Option\Primary::isEmpty($value))
        ) {
            throw new Exception\InvalidArgumentException(
                "Primary value can not be empty string or null!",
                $value
            );
        }

        if ($value === null) {
            return;
        }

        // Enumeration
        if ($this->hasOption(Entity\Reflection\Property\Option\Enum::KEY)
            && !$this->getOption(Entity\Reflection\Property\Option\Enum::KEY)->isValid($value)
        ) {
            throw new Exception\InvalidArgumentException(
                "Value " . $value . " is not from defined entity enumeration "
                . "range on property " . $this->name . "!",
                $value
            );
        }

        // Scalar or array type
        if (self::isScalarType($this->type) || $this->type === self::TYPE_ARRAY) {

            if (gettype($value) === $this->type) {
                return;
            }
            throw new Exception\InvalidArgumentException(
                "Expected " . $this->type . " but " . gettype($value)
                . " given on property " . $this->name . "!",
                $value
            );
        }

        // Object validation
        $givenType = gettype($value);
        if ($givenType === "object") {
            $givenType = get_class($value);
        }

        if ($this->type === self::TYPE_ENTITY) {
            // Entity

            $expectedEntityClass = Convention::nameToClass($this->typeOption, Convention::ENTITY_MASK);
            if ($value instanceof $expectedEntityClass) {
                return;
            } else {
                throw new Exception\InvalidArgumentException(
                    "Expected entity " . $this->typeOption . " but " . $givenType
                    . " given on property " . $this->name . "!",
                    $value
                );
            }
        } elseif ($this->type === self::TYPE_COLLECTION) {
            // Collection

            $entityClass = Convention::nameToClass($this->typeOption, Convention::ENTITY_MASK);
            if (!$value instanceof Entity\Collection) {

                throw new Exception\InvalidArgumentException(
                    "Expected entity collection but " . $givenType . " given on"
                    . " property " . $this->name . "!",
                    $value
                );
            } elseif ($value->getEntityClass() !== $entityClass) {
                throw new Exception\InvalidArgumentException(
                    "Expected collection of entity " . $entityClass
                    . " but collection of entity " . $value->getEntityClass()
                    . " given on property " . $this->name . "!",
                    $value
                );
            } else {
                return;
            }
        } elseif ($this->type === self::TYPE_DATETIME) {
            // DateTime

            if ($value instanceof \DateTime) {
                return;
            } else {
                throw new Exception\InvalidArgumentException(
                    "Expected DateTime but " . $givenType . " given on"
                    . " property " . $this->name . "!",
                    $value
                );
            }
        } elseif ($this->type === self::TYPE_DATE) {
            // Date

            if ($value instanceof \DateTime) {
                return;
            } else {
                throw new Exception\InvalidArgumentException(
                    "Expected date as DateTime object but " . $givenType
                    . " given on property " . $this->name . "!",
                    $value
                );
            }
        } else {
            // Unexpected

            throw new \Exception("Unsupported type " . $this->type . "!");
        }
    }
890311
public function validate($value) {
        if(filter_var($value, FILTER_VALIDATE_INT)===false) {
            return new ValidationResult(false, 'Not a valid integer');
        }        
        return new ValidationResult(true);
    }
520064
private function validateLogicalOperator($value) 
    {
        $operator = strtoupper(trim($value));
        $isValid = in_array($operator, $this->logicalOperators);
        
        if($isValid === true) {
            return $operator;
        } 
        
        throw new \Exception("Logical operator $value is not supported.");
    }
1036365
protected function _validate_range($value, $parameter)
    {
        if (preg_match('#^(-?[\.\d]+)-(-?[\d\.]+)$#', $parameter, $match)) {
            return $value >= $match[1] && $value <= $match[2] ? $value : null;
        } else {
            throw new InvalidValueException(['range validator `:parameter` parameters is not {min}-{max} format', 'parameter' => $parameter]);
        }
    }
1187454
public function validate($value, &$filtered = null)
    {
        $this->error = null;

        if ($value === null)
            return $this->options['nullable'] ?? false;
        
        $filtered = $value;
        if ($this->type === Validator::EXISTS)
            return true;
        
        $o = $this->options;
        if ($this->type !== Validator::VALIDATE_CUSTOM && !$this->matchType($value, $filtered))
            return false;

        if (isset($o['custom']) && is_callable($o['custom']))
        {
            try
            {
                $valid = $o['custom']($value);
                if (!is_bool($valid))
                    throw new \RuntimeException("Validator did not return boolean: " . WF::str($valid));
            }
            catch (ValidationException $e)
            {
                $this->error = $e->getError();
                $valid = false;
            }
            return $valid;
        }

        return true;
    }
757674
protected function validate($value)
	{
		if ($value < $this->minValue || $value > $this->maxValue)
		{
			throw new InvalidArgumentException('Value ' . $value . ' is out of bounds (' . $this->minValue . '..' . $this->maxValue . ')');
		}
	}
540973
protected function parseScope($value)
    {
        switch ($value) {
            case 'singleton':
                return Configuration::SCOPE_SINGLETON;
            case 'prototype':
                return Configuration::SCOPE_PROTOTYPE;
            case 'session':
                return Configuration::SCOPE_SESSION;
            default:
                throw new InvalidObjectConfigurationException('Invalid scope "' . $value . '"', 1167574991);
        }
    }
933940
protected function _validate_exists($value, $parameter = null)
    {
        $context = $this->_context;

        if (!$value) {
            return $value;
        }
        $field = $context->field;
        if ($parameter) {
            $className = $parameter;
        } else {
            $modelName = get_class($context->model);
            if (preg_match('#^(.*)_id$#', $field, $match)) {
                $className = substr($modelName, 0, strrpos($modelName, '\\') + 1) . Text::camelize($match[1]);
                if (!class_exists($className)) {
                    $className = $this->alias->get('@ns.app') . '\\Models\\' . Text::camelize($match[1]);
                }
            } else {
                throw new InvalidValueException(['validate `:field` field failed: related model class name is not provided', 'field' => $field]);
            }
        }

        if (!class_exists($className)) {
            throw new InvalidValueException(['validate `:1` field failed: related `:2` model class is not exists.', $field, $className]);
        }

        /**
         * @var \ManaPHP\Model $model
         * @var \ManaPHP\Model $className
         */
        $model = new $className;
        return $className::exists([$model->getPrimaryKey() => $value]) ? $value : null;
    }
1182870
public function checkType($value)
    {
        if (isset($this->name) && null !== $this->name) {
            $fn = 'is_'.$this->name;

            return $fn($value);
        }

        throw new \Exception('Invalid name or name not defined for primitive type.');
    }
1299700
public function isValid($value = null, array $chain = []): bool
    {
        $this->parseChain($chain);

        if (empty($this->chain)) {
            throw new RuntimeException('No validators found in chain');
        }

        $this->results = [];
        $isValid = true;
        foreach ($this->chain as $name => $validator) {
            $result = $validator->isValid($value);
            $this->errors[$name] = $validator->getErrors();
            if ($result === true) {
                $this->results[$name] = true;
            } else {
                $this->results[$name] = false;
                $isValid = false;
            }
        }

        return $isValid;
    }
1147946
public function validateValue($value)
    {
        if (!$value instanceof MoneyInterface) {
            throw new Exception\InvalidArgumentException(
                sprintf(
                    'Value of type "%s" is invalid for %s; must implement "%s"',
                    is_object($value) ? get_class($value) : gettype($value),
                    get_class($this),
                    MoneyInterface::class
                )
            );
        }
    }
337690
protected function validate($name, $value)
    {
        if (isset($this->properties[$name]) === false ||
            isset($this->properties[$name]['type']) === false) {
            throw new Exception('Invalid property "' . $name . '"');
        }

        try {
            $value = Validate::property($this->properties[$name], $value);
        } catch (Exception $e) {
            throw new Exception('Invalid value for property "' . $name . '" (' . $e->getMessage() . ')');
        }

        return $value;
    }
721765
protected function validateIs($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
    {
        if (count($args) == 0) {
            throw new ValidatorConfigException("Validator 'is' must have argument in validator list for parameter {$parameter}");
        }

        //$value = $this->getValue($parameter);

        if ($value === null) {
            return null;
        }

        if (!is_scalar($value)) {
            return Message::getMessage(Message::PRIMITIVE, [
                'param' => $parameter
            ]);
        }

        $value = trim((string)$value);

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

        if ($value !== $args[0]) {
            return Message::getMessage(Message::IS, [
                'param' => $parameter,
                'value' => $value
            ]);
        }

        return null;
    }
1363965
public function validate($value)
  {
    if ($value && !($value instanceof \Symfony\Component\HttpFoundation\File\File)) {
      Exception::ThrowError(Exception::VALUE_IS_NOT_FILE);
    }

    return parent::validate($value);
  }
1164615
public function validate($field, $value, $validator) {

		if(empty($value)) return false;
		if(!filter_var($value, FILTER_VALIDATE_URL)) return false;

		$url = parse_url($value);
		if(!in_array($url['scheme'], $this->allowed_protocols)) return false;

		if($this->allowed_domains === null) return true;

		return in_array($url['host'], $this->allowed_domains);

	}
85314
public function validate($value)
    {
        // if value required, then only valueTrue is allowed
        if ($this->required && $value !== $this->valueTrue) {
            throw new ValidationException([$this->name => 'Must be selected']);
        }
    }