public function validateObject($object) {
        if (!$object instanceof SerialisableObject) {
            throw new ClassNotSerialisableException(get_class($object));
        }

        $classAnnotations = ClassAnnotationParser::instance()->parse($object);

        $validationFields = $classAnnotations->getFieldAnnotationsForMatchingTag("validation");

        $validationErrors = array();

        foreach ($validationFields as $field => $annotation) {

            $value = $object->__getSerialisablePropertyValue($field);

            foreach ($annotation[0]->getValues() as $validatorString) {

                $explodedValidator = explode("(", $validatorString);
                $validatorKey = trim($explodedValidator[0]);

                // Gather validator args if supplied.
                $validatorArgs = array();
                if (sizeof($explodedValidator) > 1) {
                    $argsCSV = explode(")", $explodedValidator[1]);
                    $args = explode("|", $argsCSV[0]);

                    foreach ($args as $arg) {
                        $validatorArgs[] = trim($arg);
                    }
                }

                $validator = isset($this->validators[$validatorKey]) ? $this->validators[$validatorKey] : null;
                if (isset($validator)) {
                    $valid = $validator->validateObjectFieldValue($value, $field, $object, $validatorArgs, $validatorKey);

                    if ($valid !== true) {
                        if (!isset($validationErrors[$field])) $validationErrors[$field] = array();
                        $message = preg_replace_callback("/\\$([0-9])/", function ($matches) use ($validatorArgs) {
                            return $validatorArgs[$matches[1] - 1];
                        }, $validator->getValidationMessage());
                        $validationErrors[$field][$validatorKey] = new FieldValidationError($field, $validatorKey, $message);
                    }

                } else {
                    throw new InvalidValidatorException($validatorKey, $field, $object);
                }


            }

        }

        return $validationErrors;


    }
public function validateObject($object) {
        if (!$object instanceof SerialisableObject) {
            throw new ClassNotSerialisableException(get_class($object));
        }

        $classAnnotations = ClassAnnotationParser::instance()->parse($object);

        $validationFields = $classAnnotations->getFieldAnnotationsForMatchingTag("validation");

        $validationErrors = array();

        foreach ($validationFields as $field => $annotation) {

            $value = $object->__getSerialisablePropertyValue($field);

            foreach ($annotation[0]->getValues() as $validatorString) {

                $explodedValidator = explode("(", $validatorString);
                $validatorKey = trim($explodedValidator[0]);

                // Gather validator args if supplied.
                $validatorArgs = array();
                if (sizeof($explodedValidator) > 1) {
                    $argsCSV = explode(")", $explodedValidator[1]);
                    $args = explode("|", $argsCSV[0]);

                    foreach ($args as $arg) {
                        $validatorArgs[] = trim($arg);
                    }
                }

                $validator = isset($this->validators[$validatorKey]) ? $this->validators[$validatorKey] : null;
                if (isset($validator)) {
                    $valid = $validator->validateObjectFieldValue($value, $field, $object, $validatorArgs, $validatorKey);

                    if ($valid !== true) {
                        if (!isset($validationErrors[$field])) $validationErrors[$field] = array();
                        $message = preg_replace_callback("/\\$([0-9])/", function ($matches) use ($validatorArgs) {
                            return $validatorArgs[$matches[1] - 1];
                        }, $validator->getValidationMessage());
                        $validationErrors[$field][$validatorKey] = new FieldValidationError($field, $validatorKey, $message);
                    }

                } else {
                    throw new InvalidValidatorException($validatorKey, $field, $object);
                }


            }

        }

        return $validationErrors;


    }
public function validateObject ( $ object ) { if ( ! $ object instanceof SerialisableObject ) { throw new ClassNotSerialisableException ( get_class ( $ object ) ) ; } $ classAnnotations = ClassAnnotationParser :: instance ( ) -> parse ( $ object ) ; $ validationFields = $ classAnnotations -> getFieldAnnotationsForMatchingTag ( "validation" ) ; $ validationErrors = array ( ) ; foreach ( $ validationFields as $ field => $ annotation ) { $ value = $ object -> __getSerialisablePropertyValue ( $ field ) ; foreach ( $ annotation [ 0 ] -> getValues ( ) as $ validatorString ) { $ explodedValidator = explode ( "(" , $ validatorString ) ; $ validatorKey = trim ( $ explodedValidator [ 0 ] ) ; // Gather validator args if supplied. $ validatorArgs = array ( ) ; if ( sizeof ( $ explodedValidator ) > 1 ) { $ argsCSV = explode ( ")" , $ explodedValidator [ 1 ] ) ; $ args = explode ( "|" , $ argsCSV [ 0 ] ) ; foreach ( $ args as $ arg ) { $ validatorArgs [ ] = trim ( $ arg ) ; } } $ validator = isset ( $ this -> validators [ $ validatorKey ] ) ? $ this -> validators [ $ validatorKey ] : null ; if ( isset ( $ validator ) ) { $ valid = $ validator -> validateObjectFieldValue ( $ value , $ field , $ object , $ validatorArgs , $ validatorKey ) ; if ( $ valid !== true ) { if ( ! isset ( $ validationErrors [ $ field ] ) ) $ validationErrors [ $ field ] = array ( ) ; $ message = preg_replace_callback ( "/\\$([0-9])/" , function ( $ matches ) use ( $ validatorArgs ) { return $ validatorArgs [ $ matches [ 1 ] - 1 ] ; } , $ validator -> getValidationMessage ( ) ) ; $ validationErrors [ $ field ] [ $ validatorKey ] = new FieldValidationError ( $ field , $ validatorKey , $ message ) ; } } else { throw new InvalidValidatorException ( $ validatorKey , $ field , $ object ) ; } } } return $ validationErrors ; }
Validate a serialisable object

@param SerialisableObject $object
Validate a serialisable object