src/JsonApiValidator.php
public function validator($type, $validator)
    {
        $this->validators[$type] = $validator;

        $this->resolver($type, function ($data, $resourceId) use ($type) {
            /** @var \Drp\JsonApiParser\Contracts\ValidatorExecutor[] $validators */
            $validators = Arr::wrap($this->validators[$type]);

            foreach ($validators as $validator) {
                $data['id'] = $resourceId;
                $validator->with($data);

                $result = $validator->passes();

                if (!$result) {
                    $errors = $validator->errors();

                    $types = explode('.', $type);
                    $key = end($types);

                    if ($resourceId !== null) {
                        $key .= '_' . $resourceId;
                    }

                    $this->errors[$key] = array_merge(Arr::get($this->errors, $key, []), $errors);
                }
            }
        });

        return $this;
    }
public function validator($type, $validator)
    {
        $this->validators[$type] = $validator;

        $this->resolver($type, function ($data, $resourceId) use ($type) {
            /** @var \Drp\JsonApiParser\Contracts\ValidatorExecutor[] $validators */
            $validators = Arr::wrap($this->validators[$type]);

            foreach ($validators as $validator) {
                $data['id'] = $resourceId;
                $validator->with($data);

                $result = $validator->passes();

                if (!$result) {
                    $errors = $validator->errors();

                    $types = explode('.', $type);
                    $key = end($types);

                    if ($resourceId !== null) {
                        $key .= '_' . $resourceId;
                    }

                    $this->errors[$key] = array_merge(Arr::get($this->errors, $key, []), $errors);
                }
            }
        });

        return $this;
    }
public function validator ( $ type , $ validator ) { $ this -> validators [ $ type ] = $ validator ; $ this -> resolver ( $ type , function ( $ data , $ resourceId ) use ( $ type ) { /** @var \Drp\JsonApiParser\Contracts\ValidatorExecutor[] $validators */ $ validators = Arr :: wrap ( $ this -> validators [ $ type ] ) ; foreach ( $ validators as $ validator ) { $ data [ 'id' ] = $ resourceId ; $ validator -> with ( $ data ) ; $ result = $ validator -> passes ( ) ; if ( ! $ result ) { $ errors = $ validator -> errors ( ) ; $ types = explode ( '.' , $ type ) ; $ key = end ( $ types ) ; if ( $ resourceId !== null ) { $ key .= '_' . $ resourceId ; } $ this -> errors [ $ key ] = array_merge ( Arr :: get ( $ this -> errors , $ key , [ ] ) , $ errors ) ; } } } ) ; return $ this ; }
Add a validator to be ran when the type is found.

@param string $type
@param \Drp\JsonApiParser\Contracts\ValidatorExecutor|array $validator
@return $this
@throws \Drp\JsonApiParser\Exceptions\FailedValidationException
Add a validator to be ran when the type is found .