Validate property

@param string $name
@param mixed $value
@throws \Rio\Exception
@return mixed
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;
    }
889448
public function validate($value)
    {
        $verifiers = $this->getVerifiers();
        foreach ($verifiers as $pv) {
            try {
                $pv->verify($value);
            } catch (VerifyException $e) {
                throw new IllegalPropertyException($e->getMessage(), $e->getCode(), $e);
            }
        }
    }
772147
public function validate($value)
    {
        return ($value instanceof \stdClass && count((array) $value) <= $this->size)
            || parent::validate($value);
    }
645934
public function isValid( $name, $value = null )
    {
        if( !isset( $this->enums[$name] ) ) {
            return false;
        } elseif( $value === null ) {
            return true;
        }
        return !isset( $value ) || in_array( $value, $this->enums[$name] );
    }
489620
private function validateValue(string $name, string $value, string $pattern): void
    {
        if (!preg_match("#^$pattern$#", $value)) {
            throw InvalidAttribute::badFormat($name, $value, $pattern);
        }
    }
434942
public function validate($name, $value)
    {
        $meta = $this->schema->getPropertyEntryByIdentifier($name);

        if (!$meta) {
            throw new Exception("Meta informação para propriedade {$name} não encontrada no schema", 400);
        }
        $meta = is_array($meta) ? $meta[0] : $meta;

        $meta = $meta->toArray();

        return $this->hydrate($meta, $value);
    }
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.");
    }
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']);
        }
    }
821789
public function option($name, $value) {
		$this->validateName($name);
		return $this->merge([$name => $value]);
	}
390748
public function validate($value)
    {
        $return = new ValidateResult($value, false);
        $failure = null;

        if (!is_object($value)) {
            $failure = 'type';
            //error
            goto err;
        }

        $valueProperties = get_object_vars($value);

        $valuePropertiesCount = count($valueProperties);

        if ($valuePropertiesCount < $this->minProperties) {
            //error
            $failure = 'minProperties';
            goto err;
        } elseif ($this->maxProperties !== null
            && $valuePropertiesCount > $this->maxProperties
        ) {
            $failure = 'maxProperties';
            //error
            goto err;
        }

        /**
         * @param \stdClass $propertyValues
         * @param array $expression
         * @return bool
         * @throws \Exception When an unknown function is set
         */
        $evaluate = function (
            \stdClass $propertyValues,
            array $expression
        ) use (&$evaluate) {
            $functions = (object) [
                /**
                 * @return bool
                 */
                'member' => function (
                    string $operator,
                    string $propertyKey,
                    array  $memberValues
                ) use ($propertyValues) {
                    if (!property_exists($propertyValues, $propertyKey)) {
                        return false;
                    }

                    $propertyValue = $propertyValues->{$propertyKey};

                    return in_array($propertyValue, $memberValues);
                },
                /**
                 * @return bool
                 * @since 0.10.0
                 */
                'subset' => function (
                    string $operator,
                    array  $subsetValues,
                    string $propertyKey
                ) use ($propertyValues) {
                    if (!property_exists($propertyValues, $propertyKey)) {
                        return false;
                    }

                    $propertyValue = $propertyValues->{$propertyKey};

                    if (!is_array($propertyValue)) {
                        $propertyValue = [$propertyValue];
                    }

                    $propertyValue = array_unique($propertyValue);
                    $subsetValues  = array_unique($subsetValues);

                    $intersect = array_intersect($propertyValue, $subsetValues);

                    return count($subsetValues) === count($intersect);
                },
                'or' => function (
                    string $operator,
                    array ...$list
                ) use (
                    $propertyValues,
                    &$evaluate
                ) {
                    return array_reduce(
                        $list,
                        function (
                            bool $carry,
                            array $item
                        ) use (
                            $propertyValues,
                            $evaluate
                        ) {
                            return $carry || $evaluate($propertyValues, $item);
                        },
                        false
                    );
                }
            ];

            $functionKey = $expression[0];

            //is atom (bool)
            if (is_bool($functionKey)) {
                return $functionKey;
            }

            if (!isset($functions->{$functionKey})) {
                throw new \Exception(sprintf(
                    'Unknown function "%s"',
                    $functionKey
                ));
            }

            $function = $functions->{$functionKey};

            return $function(...$expression);
        };

        //validate x-visibility
        if ($this->{'x-visibility'} !== null) {
            $xVisibility = $this->{'x-visibility'};

            foreach ($xVisibility as $propertyKey => $expression) {
                if (!property_exists($value, $propertyKey)) {
                    $this->required = array_diff(
                        $this->required,
                        [$propertyKey]
                    );
                } else {
                    //evaluate if property is visible
                    $evaluation = $evaluate(
                        $value,
                        $expression
                    );

                    /*//remove from required
                    if (!$evaluation) {
                        var_dump($this->required);

                        $this->required = array_diff(
                            $this->required,
                            [$propertyKey]
                        );

                        var_dump($this->required);
                    }*/

                    //if is defined and evaluation is false throw exception
                    if (!$evaluation && isset($value->{$propertyKey})) {
                        $return->errorObject = new IncorrectParametersException([
                            'type' => static::getType(),
                            'failure' => 'x-visibility',
                            'properties' => [$propertyKey]
                        ]);

                        return $return;
                    }
                }
            }
        }

        //Check if required properties are set and find if any of them are missing
        if ($this->required !== null || !empty($this->required)) {
            //Find missing properties
            $missingProperties = [];

            foreach ($this->required as $key) {
                if (!array_key_exists($key, $valueProperties)) {
                    //Push key to missing
                    $missingProperties[] = $key;
                }
            }

            if (!empty($missingProperties)) {
                //error, missing properties
                $return->errorObject = new MissingParametersException(
                    $missingProperties
                );
                return $return;
            }
        }

        //Return default if it's empty
        if ($valuePropertiesCount === 0 && property_exists($this, 'default')) {
            $return->value = $this->default;
            $return->status = true;
            return $return;
        }

        $overallPropertyStatus = true;
        $errorObjects = [];
        $missingObjects = [];
        $missingDependencies = [];

        //Validate all validator's properties
        foreach ($this->properties as $key => $property) {
            //If this property key exists in given $value, validate it
            if (array_key_exists($key, $valueProperties)) {
                $propertyValue = $valueProperties[$key];
                $propertyValidateResult = $property->validate($propertyValue);

                //Check dependencies, if key is set, it's dependencies must also be set
                if (isset($this->dependencies->{$key})) {
                    foreach ($this->dependencies->{$key} as $dependencyKey) {
                        if (!array_key_exists($dependencyKey, $valueProperties)) {
                            $missingDependencies[] = $dependencyKey;
                            //set status to false
                            $overallPropertyStatus = false;
                        }
                    }
                }

                //Determine $overallPropertyStatus
                $overallPropertyStatus = $overallPropertyStatus && $propertyValidateResult->status;

                if (!$propertyValidateResult->status) {
                    if (!$propertyValidateResult->errorObject) {
                        $errorObjects[$key] = [];
                    } else {
                        switch (get_class($propertyValidateResult->errorObject)) {
                            case MissingParametersException::class:
                                $missingObjects[$key] = $propertyValidateResult->errorObject->getParameters();
                                break;
                            case IncorrectParametersException::class:
                                $errorObjects[$key] = $propertyValidateResult->errorObject->getParameters();
                                break;
                            default:
                                $errorObjects[$key] = [];
                        }
                    }
                }

                //use type casted value
                $value->{$key} = $propertyValidateResult->value;
            } elseif (property_exists($property, 'default')) {
                //Else use default property's value
                $value->{$key} = $property->default;
            }
        }

        if (!$overallPropertyStatus) {
            $return->status = $overallPropertyStatus;

            //error
            $errorObject = [];

            if (!empty($errorObjects)) {
                $errorObject[] = [
                 'type' => static::getType(),
                 'failure' => 'properties',
                 'properties' => $errorObjects
                ];
            }

            if (!empty($missingObjects)) {
                $errorObject[] = [
                 'type' => static::getType(),
                 'failure' => 'missing',
                 'properties' => $missingObjects
                ];
            }

            if (!empty($missingDependencies)) {
                $errorObject[] = [
                    'type' => static::getType(),
                    'failure' => 'dependencies',
                    'properties' => $missingDependencies
                ];
            }

            if (!empty($missingDependencies)) {
                $return->errorObject = new MissingParametersException(
                    $missingDependencies
                );
            } elseif (!empty($missingObjects)) {
                $return->errorObject = new MissingParametersException(
                    $missingObjects
                );
            } else {
                $return->errorObject = new IncorrectParametersException(
                    $errorObject
                );
            }

            return $return;
        }

        //Check if additionalProperties are set
        if ($this->additionalProperties === false) {
            $foundAdditionalProperties = [];

            foreach ($valueProperties as $key => $property) {
                if (!property_exists($this->properties, $key)) {
                    $foundAdditionalProperties[] = $key;
                }
            }

            if (!empty($foundAdditionalProperties)) {
                $return->errorObject = new IncorrectParametersException([[
                    'type' => static::getType(),
                    'failure' => 'additionalProperties',
                    'properties' => $foundAdditionalProperties
                ]]);
                return $return;
            }
        }

        //success
        $return->status = true;

        //Apply type casted
        $return->value = $value;

        return $this->validateCommon($value, $return);

        err:
        $return->errorObject = new IncorrectParametersException([
            'type' => static::getType(),
            'failure' => $failure
        ]);

        return $this->validateCommon($value, $return);
    }
1140104
public function validate($value) {
        return (string)$value == (string)$this->filter($value) ? $value : Filter::ERR_INVALID;
    }
946749
protected function validateConfig($name, $value)
	{
		switch ($name)
		{
			case 'offset':
			case 'totalItems':
				// make sure it's an integer
				if ($value != intval($value))
				{
					$value = 0;
				}
				// and that it's within bounds
				$value = max(0, $value);
			break;

			// validate integer values
			case 'current':
			case 'limit':
			case 'totalPages':
			case 'numberOfLinks':
			case 'uriSegment':
				// make sure it's an integer
				if ($value != intval($value))
				{
					$value = 1;
				}
				// and that it's within bounds
				$value = max(1, $value);
			break;

			// validate booleans
			case 'showFirst':
			case 'showLast':
				if ( ! is_bool($value))
				{
					$value = (bool) $value;
				}
			break;

			// possible alignment values
			case 'align':
				if ( ! in_array($value = strtolower($value), array('left', 'center', 'right')))
				{
					$value = 'center';
				}
			break;

			// validate the link offset, and adjust if needed
			case 'linkOffset':
				// make sure we have a fraction between 0 and 1
				if ($value > 1)
				{
					$value = $value / 100;
				}

				// and that it's within bounds
				$value = max(0.01, min($value, 0.99));
			break;
		}

		return $value;
	}
1011805
protected function validateValue($property, $value)
    {
        $this->isPropertyValid($property);

        $regEx = '/^' . self::CONFIRMATION_PROPERTIES[$property] . '$/';

        if (preg_match($regEx, $value) != 1) {
            throw new InvalidArgumentException("The value " . $value . " for the property " . $property . ", is invalid");
        }

        return $value;
    }
665715
public function validate($value) {
        if(!is_string($value)) {
            throw new DataType('value', 'string', $value);
        }
        
        try {
            $filesize = @filesize($value);            
        } catch (Exception $ex) {
            $filesize = false;
        }

        if($filesize===false) {
            throw new \Wellid\Exception\FileNotFound($value, 'file for Filesize validator');
        }
        
        if($filesize>$this->max) {
            return new ValidationResult(false, 'File is too large');
        }

        return new ValidationResult(true);
    }
1198850
private function setPaginationLink($name, $value)
    {
        if (! is_object($value) and ! is_string($value) and ! is_null($value)) {
            throw new ValidationException(
                'property "' . $name . '" has to be an object, a string or null, "' .
                gettype($value) . '" given.'
            );
        }

        if (is_string($value)) {
            $this->set($name, strval($value));
        } elseif (is_object($value)) {
            $this->setLink($name, $value);
        }
    }
250002
public function validate($value)
    {
        $result = Ok::unit();

        foreach ($this->allowedTypes as $type) {
            $typeChecker = preg_match('/^&/', $type) ? $this->getCustomType($type) : $this->createProperty($type);
            $result = $typeChecker->validate($value);

            if ($result instanceof Ok) {
                return $result;
            }
        }
        return $result;
    }
492192
public function validateValue($value) {
        $validationResultSet = new ValidationResultSet();
        foreach($this->validators as $validator) {
            $validationResultSet->add($validator->validate($value));
        }
        return $validationResultSet;
    }