validate

@param string $name
@param mixed  $value

@return mixed
@throws TExceptionAbstract
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);
    }
820613
protected static function parseFieldValue($name, $value) {
		$field	= static::$validator->getField($name);
		if( $field ) {
			$field->getType()->parseValue($field, $value);
		}
		return parent::parseFieldValue($name, $value);
	}
126182
public function normalize($value)
    {
        if (is_null($value) || $value === '') {
            return;
        }
        if (is_bool($value)) {
            return $value;
        }

        if ($value === $this->valueTrue) {
            return true;
        }

        if ($value === $this->valueFalse) {
            return false;
        }

        if (is_numeric($value)) {
            return (bool) $value;
        }

        throw new ValidationException([$this->name => 'Must be a boolean value']);
    }
1231065
public static function validate($value)
    {
        $reflector = new ReflectionClass(static::class);

        foreach ($reflector->getConstants() as $allowedValue) {
            if ($value === $allowedValue) {
                return $allowedValue;
            }
        }

        throw new ArgumentException(
            sprintf(
                'Invalid value `%s` on enum `%s`',
                $value,
                static::class
            )
        );
    }
1317601
public function inputFormat($value, $name)
    {
        $value = (string) $value;

        if (Utils::isAddress($value)) {
            $value = mb_strtolower($value);

            if (Utils::isZeroPrefixed($value)) {
                $value = Utils::stripZero($value);
            }
        }
        $value = IntegerFormatter::format($value);

        return $value;
    }
477761
protected function evalDevHandle($value, $name)
    {
        $result = preg_match('/[^a-zA-Z]/', $value) === 0;
        if ($result === false) {
            $this->pool->messages->addMessage(static::KEY_CONFIG_ERROR . ucfirst($name));
        }

        return $result;
    }
345616
protected function validateType($value, $type, $name)
    {
        if (empty($type) || $type === 'mixed') {
            return;
        }

        if (isset($this->typeMap[$type])) {
            $test = 'is_' . $this->typeMap[$type];

            if (!call_user_func($test, $value)) {
                $givenType = gettype($value);

                throw new RuntimeException("Expected property '{$name}' to be a '{$type}'. '{$givenType}' given.");
            }

            return;
        }

        if (class_exists($type)) {
            if (!($value instanceof $type)) {
                $givenType = gettype($value);

                throw new RuntimeException("Expected property '{$name}' to be a '{$type}'. '{$givenType}' given.");
            }

            return;
        }

        throw new LogicException("Unrecognized type '{$type}' for property '{$name}'");
    }
226683
public function inputFormat($value, $name)
    {
        if (!Utils::isHex($value)) {
            throw new InvalidArgumentException('The value to inputFormat must be hex bytes.');
        }
        $value = Utils::stripZero($value);

        if (mb_strlen($value) % 2 !== 0) {
            $value = "0" . $value;
            // throw new InvalidArgumentException('The value to inputFormat has invalid length. Value: ' . $value);
        }

        if (mb_strlen($value) > 64) {
            throw new InvalidArgumentException('The value to inputFormat is too long.');
        }
        $l = floor((mb_strlen($value) + 63) / 64);
        $padding = (($l * 64 - mb_strlen($value) + 1) >= 0) ? $l * 64 - mb_strlen($value) : 0;

        return $value . implode('', array_fill(0, $padding, '0'));
    }
1055481
public function validate($value) {
        // Sadly php bug #67167 makes the following lines necessary
        if(is_null($value)) {
            return new ValidationResult(false, 'Not a valid boolean but NULL', self::ERR_NULL);
        }
        if(is_object($value)) {
            return new ValidationResult(false, 'Not a valid boolean but an object', self::ERR_OBJECT);
        }
        
        if(filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE)===null) {
            return new ValidationResult(false, 'Not a valid boolean', self::ERR_NOBOOLEAN);
        }        
        return new ValidationResult(true);
    }
371223
public function validateAttribute($name, $value = null){
        $returnValue = false;

        if(isset($this->attributes[$name])){

            if(is_null($value)){
                $value = $this->attributes[$name]->getValue();
            }

            $datatypeClass = $this->attributes[$name]->getType();
            if(is_subclass_of($datatypeClass, 'oat\\taoQtiItem\\model\\qti\\datatype\\Identifier')){

            }else{
                $returnValue = $datatypeClass::validate($value);
            }

            if(is_subclass_of($datatypeClass, 'oat\\taoQtiItem\\model\\qti\\datatype\\Identifier')){
                if($datatypeClass::validate($value)){
                    // validate itentifier
                    $relatedItem = $this->getRelatedItem();
                    if(!is_null($relatedItem)){
                        $idCollection = $relatedItem->getIdentifiedElements();
                        if($value instanceof IdentifiedElement && $idCollection->exists($value->getIdentifier())){
                            $returnValue = true;
                        }
                    }else{
                        common_Logger::w('iden');
                        throw new QtiModelException('Cannot verify identifier reference because the element is not in a QTI Item '.get_class($this).'::'.$name, 0);
                    }
                }
            }else{
                $returnValue = $datatypeClass::validate($value);
            }
        }else{
            throw new InvalidArgumentException('no attribute found with the name "'.$name.'"');
        }

        return $returnValue;
    }
1128505
public static function validate($value)
    {
        if (!is_array($value)) {
            return false;
        }
        if (isset($value['to']) && IdentityValidator::validate($value['to']) === false) {
            return false;
        }
        if (!isset($value['topics']) || !is_array($value['topics'])) {
            return false;
        }
        foreach ($value['topics'] as $topic) {
            if (is_array($topic)) {
                foreach ($topic as $subTopic) {
                    if (HexValidator::validate($subTopic) === false) {
                        return false;
                    }
                }
                continue;
            }
            if (HexValidator::validate($topic) === false) {
                if (!is_null($topic)) {
                    return false;
                }
            }
        }
        return true;
    }
75918
public function setOption($name, $value)
    {
        if (! in_array($name, $this->validOptions)) {
            throw new Error('Invalid option ' . $name . '. Valid options are : ' . join(', ', $this->validOptions));
        }
        // Check duplicate fields in header
        if ('header' == $name) {
            $cnt = array_count_values($value);
            $duplicates = array();
            foreach ($cnt as $f => $c) {
                if ($c > 1) {
                    $duplicates[$f] = $c;
                }
            }
            if (sizeof($duplicates) > 0) {
                $msg = 'Duplicate fields found in header : ' . join(', ', array_keys($duplicates));
                throw new Error($msg);
            }
        }
        $this->$name = $value;

        return $this;
    }
332654
protected function _validate($name, $value)
	{
 		switch ($name)
		{
			case 'offset':
			case 'total_items':
				// make sure it's an integer
				if ($value != intval($value))
				{
					$value = 0;
				}
				// and that it's within bounds
				$value = max(0, $value);
			break;

			// integer or string
			case 'uri_segment':
				if (is_numeric($value))
				{
					// make sure it's an integer
					if ($value != intval($value))
					{
						$value = 1;
					}
					// and that it's within bounds
					$value = max(1, $value);
				}
			break;

			// validate integer values
			case 'current_page':
			case 'per_page':
			case 'limit':
			case 'total_pages':
			case 'num_links':
				// 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 'show_first':
			case 'show_last':
				if ( ! is_bool($value))
				{
					$value = (bool) $value;
				}
			break;

			// validate the link offset, and adjust if needed
			case 'link_offset':
				// 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;
	}
722884
private function IsValidFormat($Name, $Pattern, $Value)
        {
            if (! empty($Value)) {
                if (! preg_match($Pattern, $Value)) {
                    throw new Exception('Invalid '.$Name.'.');
                }
            }
        }
492192
public function validateValue($value) {
        $validationResultSet = new ValidationResultSet();
        foreach($this->validators as $validator) {
            $validationResultSet->add($validator->validate($value));
        }
        return $validationResultSet;
    }
48835
public function validate (& $value, $name = '', $arguments = array())
		{
			$callbackArguments = array_merge(array(& $value), $arguments);

			$returnValue = call_user_func_array($this->callback, $callbackArguments);

			if ($returnValue) {
				return true;
			} else {
				throw new ValidationException($this->getMessage($name));
			}
		}
266463
protected function validate($value){
        if( parent::validate($value) ){
            $length = mb_strlen($value, 'utf-8');
            if( $this->min && $this->min > $length ){
                throw new ValidateException(sprintf($this->__('Fields %s must be %d digits and more.'), $this->label, $this->min));
            }
            if( $this->max &&  $this->max < $length ){
                throw new ValidateException(sprintf($this->__('Fields %s must be %d digits and fewer.'), $this->label, $this->max));
            }
        }
        return true;
    }