final class ProblemDetailsFactory (View source)

Creates RFC 9457-style Problem Details responses without exposing exception internals.

Methods

__construct(Psr17Factory $responseFactory)

Uses one PSR-17 implementation for response and body stream creation.

ResponseInterface
create(int $status, string $title, string $detail, ServerRequestInterface $request, string $type = 'about:blank', array $extensions = [])

Creates a problem response whose instance identifies the current request path.

ResponseInterface
ResponseInterface
unauthenticated(ServerRequestInterface $request)

Returns a 401 bearer challenge for a request lacking a valid API identity.

ResponseInterface
ResponseInterface
forbidden(ServerRequestInterface $request)

Returns a 403 response without disclosing which authorization condition failed.

ResponseInterface
ResponseInterface
notFound(ServerRequestInterface $request)

Returns a 404 problem tied to the current request path.

ResponseInterface
ResponseInterface
internalServerError(ServerRequestInterface $request)

Returns a generic 500 problem that does not expose the captured exception.

ResponseInterface

Details

__construct

__construct(Psr17Factory $responseFactory)

Uses one PSR-17 implementation for response and body stream creation.

Parameters

Psr17Factory $responseFactory

create

ResponseInterface create(int $status, string $title, string $detail, ServerRequestInterface $request, string $type = 'about:blank', array $extensions = [])

Creates a problem response whose instance identifies the current request path.

Parameters

int $status
string $title
string $detail
ServerRequestInterface $request
string $type
array $extensions

Return Value

ResponseInterface

Exceptions

JsonException

unauthenticated

ResponseInterface unauthenticated(ServerRequestInterface $request)

Returns a 401 bearer challenge for a request lacking a valid API identity.

Parameters

ServerRequestInterface $request

Return Value

ResponseInterface

Exceptions

JsonException

forbidden

ResponseInterface forbidden(ServerRequestInterface $request)

Returns a 403 response without disclosing which authorization condition failed.

Parameters

ServerRequestInterface $request

Return Value

ResponseInterface

Exceptions

JsonException

notFound

ResponseInterface notFound(ServerRequestInterface $request)

Returns a 404 problem tied to the current request path.

Parameters

ServerRequestInterface $request

Return Value

ResponseInterface

Exceptions

JsonException

internalServerError

ResponseInterface internalServerError(ServerRequestInterface $request)

Returns a generic 500 problem that does not expose the captured exception.

Parameters

ServerRequestInterface $request

Return Value

ResponseInterface

Exceptions

JsonException