gilsegura/psr-validator

This is a project providing infrastructure for validating PSR HTTP messages.

Maintainers

Package info

github.com/gilsegura/psr-validator

pkg:composer/gilsegura/psr-validator

Statistics

Installs: 602

Dependents: 2

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.2 2026-06-13 12:10 UTC

This package is auto-updated.

Last update: 2026-06-18 17:43:17 UTC


README

tests codecov static analysis coding standards

Framework-agnostic validation of PSR-7 messages against JSON Schema. It validates requests, responses and server requests, composes validators into a chain, and loads schemas from files or raw strings. The gilsegura/psr-messages-bundle package uses it as the validation middleware in a controller pipeline.

Installation

composer require gilsegura/psr-validator

Message validators

Each validator is an invokable that takes a PSR-7 message, validates it and returns it (or throws a ValidationExceptionInterface on failure):

  • RequestValidator — validates an outgoing RequestInterface.
  • ResponseValidator — validates a ResponseInterface.
  • ServerRequestValidator — validates an incoming ServerRequestInterface.
  • ValidatorChain — a MessageValidatorInterface that runs several validators in sequence, so request and response checks compose into one.

MessageValidatorInterface is the common contract (__invoke(MessageInterface): MessageInterface).

Schema validation

  • SchemaValidatorInterface / Schema\SchemaValidator — validate decoded data against a schema object, returning the list of violations; ValidatorException surfaces a schema-level failure.
  • Exception\ValidationExceptionInterface — the marker validation failures implement, so callers catch a single type regardless of which part failed.

Schema factories

A schema factory builds the schema object the validators check against:

  • SchemaFactoryInterface — the contract; an invokable returning the schema.
  • SchemaFactory\FileFactory — loads a JSON Schema from a .json file.
  • SchemaFactory\RawFactory — builds a schema from a raw string.
  • SchemaFactory\SchemaFactoryException — raised when a schema cannot be built.

Middleware (PSR-15)

Middleware\ValidationMiddleware validates a message as part of a PSR-15 pipeline, so validation runs inline with the request flow rather than being called by hand.

License

MIT. See LICENSE.