Skip to content

ProblemDetails

An RFC 9457 (Problem Details for HTTP APIs; obsoletes RFC 7807) document.

Reusable, response-agnostic value object: build one, then render it with toArray()/toJson() and serve it as application/problem+json (see self::MEDIA_TYPE). ProblemDetails::fromValidationManager() constructs the common “validation failed” shape, extracting a field => messages map from a validation report into the errors extension member.

final readonly class ProblemDetails

SourceHttp/ProblemDetails.php
ConstantValueDescription
MEDIA_TYPE'application/problem+json'
MethodDescription
create(int $status = 400, ?string $title = null, ?string $type = null, ?string $detail = null, ?string $instance = null, array<string, array<string>> $errors = [], array<string, mixed> $extensions = []): ProblemDetailsCreate a Problem Details document.
extractErrors(?object $validationManager): array<string, array<string>>Extract a field => messages map from a validation manager’s report.
fromValidationManager(?object $validationManager, int $status = 400, ?string $title = null, ?string $type = null, ?string $detail = null, ?string $instance = null, array<string, mixed> $extensions = []): ProblemDetailsBuild a validation Problem Details document from a validation manager, extracting its incidents into the errors map.
getErrors(): array<string, array<string>>
getStatus(): intReturns the HTTP status code this problem document describes, which the response should also carry.
toArray(): array<string, mixed>
toJson(): stringEncodes ProblemDetails::toArray() as the JSON body of an application/problem+json response, leaving slashes and unicode unescaped.

public static function create(int $status = 400, ?string $title = null, ?string $type = null, ?string $detail = null, ?string $instance = null, array<string, array<string>> $errors = [], array<string, mixed> $extensions = []): ProblemDetails

Create a Problem Details document.

ParameterTypeDescription
$statusint
$title?``string
$type?``string
$detail?``string
$instance?``string
$errorsarray``<``string``, ``array``<``string``>``>
$extensionsarray``<``string``, ``mixed``>

Returns ProblemDetails

public static function extractErrors(?object $validationManager): array<string, array<string>>

Extract a field => messages map from a validation manager’s report.

Non-field (model-level) messages are keyed under "".

ParameterTypeDescription
$validationManager?``object

Returns array``<``string``, ``array``<``string``>``>

public static function fromValidationManager(?object $validationManager, int $status = 400, ?string $title = null, ?string $type = null, ?string $detail = null, ?string $instance = null, array<string, mixed> $extensions = []): ProblemDetails

Build a validation Problem Details document from a validation manager, extracting its incidents into the errors map.

ParameterTypeDescription
$validationManager?``object
$statusint
$title?``string
$type?``string
$detail?``string
$instance?``string
$extensionsarray``<``string``, ``mixed``>

Returns ProblemDetails

public function getErrors(): array<string, array<string>>

Returns array``<``string``, ``array``<``string``>``>

public function getStatus(): int

Returns the HTTP status code this problem document describes, which the response should also carry.

Returns int

public function toArray(): array<string, mixed>

Returns array``<``string``, ``mixed``>

public function toJson(): string

Encodes ProblemDetails::toArray() as the JSON body of an application/problem+json response, leaving slashes and unicode unescaped.

Returns string