src/Alg/Validation/DefinitionValidator.php
public function validate( $definition, $value )
	{
		if( !is_array( $definition ) )
			throw new InvalidArgumentException( 'Definition must be an array, '.gettype( $definition ).' given' );
		$errors		= array();
		if( !empty( $definition['syntax'] ) )
		{
			$syntax		= new ArrayObject( $definition['syntax'] );

			if( !strlen( $value ) )
			{
				if( $syntax['mandatory'] )
					$errors[]	= array( 'isMandatory', NULL );
				return $errors;
			}

			if( $syntax['class'] )
				if( !$this->validator->isClass( $value, $syntax['class'] ) )
					$errors[]	= array( 'isClass', $syntax['class'] );

			$predicates	= array(
				'maxlength'	=> 'hasMaxLength',
				'minlength'	=> 'hasMinLength',
			);
			foreach( $predicates as $key => $predicate )
				if( $syntax[$key] )
					if( !$this->validator->validate( $value, $predicate, $syntax[$key] ) )
						$errors[]	= array( $predicate, $syntax[$key] );
		}
	
		if( !empty( $definition['semantic'] ) )
		{
			foreach( $definition['semantic'] as $semantic )
			{
				$semantic	= new ArrayObject( $semantic );
				$param	= strlen( $semantic['edge'] ) ? $semantic['edge'] : NULL;
				if( !$this->validator->validate( $value, $semantic['predicate'], $param ) )
					$errors[]	= array( $semantic['predicate'], $param );
			}
		}
		return $errors;
	}
public function validate( $definition, $value )
	{
		if( !is_array( $definition ) )
			throw new InvalidArgumentException( 'Definition must be an array, '.gettype( $definition ).' given' );
		$errors		= array();
		if( !empty( $definition['syntax'] ) )
		{
			$syntax		= new ArrayObject( $definition['syntax'] );

			if( !strlen( $value ) )
			{
				if( $syntax['mandatory'] )
					$errors[]	= array( 'isMandatory', NULL );
				return $errors;
			}

			if( $syntax['class'] )
				if( !$this->validator->isClass( $value, $syntax['class'] ) )
					$errors[]	= array( 'isClass', $syntax['class'] );

			$predicates	= array(
				'maxlength'	=> 'hasMaxLength',
				'minlength'	=> 'hasMinLength',
			);
			foreach( $predicates as $key => $predicate )
				if( $syntax[$key] )
					if( !$this->validator->validate( $value, $predicate, $syntax[$key] ) )
						$errors[]	= array( $predicate, $syntax[$key] );
		}
	
		if( !empty( $definition['semantic'] ) )
		{
			foreach( $definition['semantic'] as $semantic )
			{
				$semantic	= new ArrayObject( $semantic );
				$param	= strlen( $semantic['edge'] ) ? $semantic['edge'] : NULL;
				if( !$this->validator->validate( $value, $semantic['predicate'], $param ) )
					$errors[]	= array( $semantic['predicate'], $param );
			}
		}
		return $errors;
	}
public function validate ( $ definition , $ value ) { if ( ! is_array ( $ definition ) ) throw new InvalidArgumentException ( 'Definition must be an array, ' . gettype ( $ definition ) . ' given' ) ; $ errors = array ( ) ; if ( ! empty ( $ definition [ 'syntax' ] ) ) { $ syntax = new ArrayObject ( $ definition [ 'syntax' ] ) ; if ( ! strlen ( $ value ) ) { if ( $ syntax [ 'mandatory' ] ) $ errors [ ] = array ( 'isMandatory' , NULL ) ; return $ errors ; } if ( $ syntax [ 'class' ] ) if ( ! $ this -> validator -> isClass ( $ value , $ syntax [ 'class' ] ) ) $ errors [ ] = array ( 'isClass' , $ syntax [ 'class' ] ) ; $ predicates = array ( 'maxlength' => 'hasMaxLength' , 'minlength' => 'hasMinLength' , ) ; foreach ( $ predicates as $ key => $ predicate ) if ( $ syntax [ $ key ] ) if ( ! $ this -> validator -> validate ( $ value , $ predicate , $ syntax [ $ key ] ) ) $ errors [ ] = array ( $ predicate , $ syntax [ $ key ] ) ; } if ( ! empty ( $ definition [ 'semantic' ] ) ) { foreach ( $ definition [ 'semantic' ] as $ semantic ) { $ semantic = new ArrayObject ( $ semantic ) ; $ param = strlen ( $ semantic [ 'edge' ] ) ? $ semantic [ 'edge' ] : NULL ; if ( ! $ this -> validator -> validate ( $ value , $ semantic [ 'predicate' ] , $ param ) ) $ errors [ ] = array ( $ semantic [ 'predicate' ] , $ param ) ; } } return $ errors ; }
Validates Syntax against Field Definition and generates Messages.
@access		public
@param		string		$fieldKey	Field Key in Definition
@param		string		$data		Field Definition
@param		string		$value		Value to validate
@param		string		$fieldName	Field Name in Form
@return		array
Validates Syntax against Field Definition and generates Messages .