src/JsonApiValidator.php
public function validate(array $input)
    {
        $result = $this->parse($input);

        if ($result === null) {
            throw new InvalidJsonException(
                'Parser was unable to process the JSON due to there not being a data key.'
            );
        }

        if (count($this->seenTypes) > 0) {
            array_walk($this->presenceCheckers, function (callable $callback = null, $type) {
                if ($callback !== null) {
                    try {
                        $isRequired = $callback($this->seenTypes);
                    } catch (FailedValidationException $exception) {
                        $this->errors = array_merge($this->errors, [
                            $type => $exception->getMessages()
                        ]);

                        return;
                    }

                    if ($isRequired === false) {
                        return;
                    }
                } elseif ($this->seenTypes->has($type)) {
                    return;
                }

                $this->errors[$type] = 'Missing api resource from the request.';
            });
        }

        if (count($this->errors) > 0) {
            throw new FailedValidationException($this->errors);
        }

        return true;
    }
public function validate(array $input)
    {
        $result = $this->parse($input);

        if ($result === null) {
            throw new InvalidJsonException(
                'Parser was unable to process the JSON due to there not being a data key.'
            );
        }

        if (count($this->seenTypes) > 0) {
            array_walk($this->presenceCheckers, function (callable $callback = null, $type) {
                if ($callback !== null) {
                    try {
                        $isRequired = $callback($this->seenTypes);
                    } catch (FailedValidationException $exception) {
                        $this->errors = array_merge($this->errors, [
                            $type => $exception->getMessages()
                        ]);

                        return;
                    }

                    if ($isRequired === false) {
                        return;
                    }
                } elseif ($this->seenTypes->has($type)) {
                    return;
                }

                $this->errors[$type] = 'Missing api resource from the request.';
            });
        }

        if (count($this->errors) > 0) {
            throw new FailedValidationException($this->errors);
        }

        return true;
    }
public function validate ( array $ input ) { $ result = $ this -> parse ( $ input ) ; if ( $ result === null ) { throw new InvalidJsonException ( 'Parser was unable to process the JSON due to there not being a data key.' ) ; } if ( count ( $ this -> seenTypes ) > 0 ) { array_walk ( $ this -> presenceCheckers , function ( callable $ callback = null , $ type ) { if ( $ callback !== null ) { try { $ isRequired = $ callback ( $ this -> seenTypes ) ; } catch ( FailedValidationException $ exception ) { $ this -> errors = array_merge ( $ this -> errors , [ $ type => $ exception -> getMessages ( ) ] ) ; return ; } if ( $ isRequired === false ) { return ; } } elseif ( $ this -> seenTypes -> has ( $ type ) ) { return ; } $ this -> errors [ $ type ] = 'Missing api resource from the request.' ; } ) ; } if ( count ( $ this -> errors ) > 0 ) { throw new FailedValidationException ( $ this -> errors ) ; } return true ; }
Validate input.

@param array $input
@return bool
@throws \Drp\JsonApiParser\Exceptions\FailedValidationException
@throws \ReflectionException
@throws \Drp\JsonApiParser\Exceptions\MissingResolverException
@throws \Drp\JsonApiParser\Exceptions\InvalidJsonException
Validate input .