- Introduce small interfaces and default adapters (DIP): - Support\Contracts\ConfigInterface + Support\DefaultConfig - Http\Contracts\ErrorFormatNegotiatorInterface + Http\Support\DefaultErrorFormatNegotiator - Http\Contracts\RequestIdProviderInterface + Http\Support\DefaultRequestIdProvider - Http\Contracts\ExceptionToStatusMapperInterface + Http\Support\DefaultExceptionToStatusMapper - Kernel: bind new contracts in the container; keep DelegatingApiResponseFactory wiring - ContentNegotiationMiddleware: depend on ConfigInterface + negotiator; honor Accept for JSON:API - ProblemDetailsMiddleware: inject negotiator + config; split into small helpers; deterministic content negotiation; stable Whoops HTML; include X-Request-Id - DispatchMiddleware: SRP refactor into small methods; remove hidden coupling; normalize non-Response returns - Add/adjust tests: - tests/ErrorHandlingTest.php for problem details, JSON:API errors, and Whoops HTML - tests/ContentNegotiationTest.php for format selection - tests/MakeCommandTest.php aligned with create:command scaffolder - Docs/Meta: update README and MILESTONES; .gitignore to ignore .junie.json No runtime behavior changes intended beyond clearer DI boundaries and content-negotiation determinism. All tests green.
45 lines
1.3 KiB
PHP
45 lines
1.3 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Phred\Http\Contracts;
|
|
|
|
use Psr\Http\Message\ResponseInterface;
|
|
|
|
interface ApiResponseFactoryInterface
|
|
{
|
|
/**
|
|
* Generic 200 OK with array payload.
|
|
* Implementations must set appropriate Content-Type.
|
|
* @param array<string,mixed> $data
|
|
*/
|
|
public function ok(array $data = []): ResponseInterface;
|
|
|
|
/**
|
|
* 201 Created with array payload.
|
|
* @param array<string,mixed> $data
|
|
* @param string|null $location Optional Location header
|
|
*/
|
|
public function created(array $data = [], ?string $location = null): ResponseInterface;
|
|
|
|
/**
|
|
* 204 No Content
|
|
*/
|
|
public function noContent(): ResponseInterface;
|
|
|
|
/**
|
|
* Error response with status and details.
|
|
* @param int $status HTTP status code (4xx/5xx)
|
|
* @param string $title Short, human-readable summary
|
|
* @param string|null $detail Detailed description
|
|
* @param array<string,mixed> $extra Extra members dependent on format
|
|
*/
|
|
public function error(int $status, string $title, ?string $detail = null, array $extra = []): ResponseInterface;
|
|
|
|
/**
|
|
* Create a response from a raw associative array payload.
|
|
* @param array<string,mixed> $payload
|
|
* @param int $status
|
|
*/
|
|
public function fromArray(array $payload, int $status = 200): ResponseInterface;
|
|
}
|