main/app/API/ValidatorProvider.php
public function validate($class, $data, $mode, $throwException = false, array $options = [])
    {
        $schema = $this->serializer->getSchema($class);

        //schema isn't always there yet
        if ($schema) {
            $validator = Validator::buildDefault();
            $errors = $validator->validate($this->toObject($data), $schema, '', [$mode]);

            if (!empty($errors) && $throwException) {
                throw new InvalidDataException(
                    sprintf('Invalid data for "%s".', $class),
                    $errors
                );
            }

            if (count($errors) > 0) {
                return $errors;
            }
        }

        //validate uniques
        try {
            $validator = $this->get($class);
        } catch (\Exception $e) {
            //no custom validator
            $uniqueFields = [];
            $identifiers = $this->serializer->getIdentifiers($class);

            foreach ($identifiers as $identifier) {
                $uniqueFields[$identifier] = $identifier;
            }

            return $this->validateUnique($uniqueFields, $data, $mode, $class);
        }

        //can be deduced from the mapping, but we won't know
        //wich field is related to wich data prop in that case
        $uniqueFields = $validator->getUniqueFields();
        $errors = $this->validateUnique($uniqueFields, $data, $mode, $class);

        //custom validation
        $errors = array_merge($errors, $validator->validate($data, $mode, $options));

        if (!empty($errors) && $throwException) {
            throw new InvalidDataException(
                sprintf('Invalid data for "%s".', $class),
                $errors
            );
        }

        return $errors;
    }
public function validate($class, $data, $mode, $throwException = false, array $options = [])
    {
        $schema = $this->serializer->getSchema($class);

        //schema isn't always there yet
        if ($schema) {
            $validator = Validator::buildDefault();
            $errors = $validator->validate($this->toObject($data), $schema, '', [$mode]);

            if (!empty($errors) && $throwException) {
                throw new InvalidDataException(
                    sprintf('Invalid data for "%s".', $class),
                    $errors
                );
            }

            if (count($errors) > 0) {
                return $errors;
            }
        }

        //validate uniques
        try {
            $validator = $this->get($class);
        } catch (\Exception $e) {
            //no custom validator
            $uniqueFields = [];
            $identifiers = $this->serializer->getIdentifiers($class);

            foreach ($identifiers as $identifier) {
                $uniqueFields[$identifier] = $identifier;
            }

            return $this->validateUnique($uniqueFields, $data, $mode, $class);
        }

        //can be deduced from the mapping, but we won't know
        //wich field is related to wich data prop in that case
        $uniqueFields = $validator->getUniqueFields();
        $errors = $this->validateUnique($uniqueFields, $data, $mode, $class);

        //custom validation
        $errors = array_merge($errors, $validator->validate($data, $mode, $options));

        if (!empty($errors) && $throwException) {
            throw new InvalidDataException(
                sprintf('Invalid data for "%s".', $class),
                $errors
            );
        }

        return $errors;
    }
public function validate ( $ class , $ data , $ mode , $ throwException = false , array $ options = [ ] ) { $ schema = $ this -> serializer -> getSchema ( $ class ) ; //schema isn't always there yet if ( $ schema ) { $ validator = Validator :: buildDefault ( ) ; $ errors = $ validator -> validate ( $ this -> toObject ( $ data ) , $ schema , '' , [ $ mode ] ) ; if ( ! empty ( $ errors ) && $ throwException ) { throw new InvalidDataException ( sprintf ( 'Invalid data for "%s".' , $ class ) , $ errors ) ; } if ( count ( $ errors ) > 0 ) { return $ errors ; } } //validate uniques try { $ validator = $ this -> get ( $ class ) ; } catch ( \ Exception $ e ) { //no custom validator $ uniqueFields = [ ] ; $ identifiers = $ this -> serializer -> getIdentifiers ( $ class ) ; foreach ( $ identifiers as $ identifier ) { $ uniqueFields [ $ identifier ] = $ identifier ; } return $ this -> validateUnique ( $ uniqueFields , $ data , $ mode , $ class ) ; } //can be deduced from the mapping, but we won't know //wich field is related to wich data prop in that case $ uniqueFields = $ validator -> getUniqueFields ( ) ; $ errors = $ this -> validateUnique ( $ uniqueFields , $ data , $ mode , $ class ) ; //custom validation $ errors = array_merge ( $ errors , $ validator -> validate ( $ data , $ mode , $ options ) ) ; if ( ! empty ( $ errors ) && $ throwException ) { throw new InvalidDataException ( sprintf ( 'Invalid data for "%s".' , $ class ) , $ errors ) ; } return $ errors ; }
Validates `data` using the `class` validator.

@param string $class          - the class of the validator to use
@param mixed  $data           - the data to validate
@param string $mode           - 'create', 'update'
@param bool   $throwException - if true an InvalidDataException is thrown instead of returning the errors

@return array - the list of validation errors

@throws InvalidDataException
Validates data using the class validator .