Phred/src/Http/RequestContext.php
Funky Waddle fd1c9d23df refactor(core): enforce SOLID across HTTP pipeline; add small contracts and defaults; align tests
- 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.
2025-12-15 09:15:49 -06:00

32 lines
731 B
PHP

<?php
declare(strict_types=1);
namespace Phred\Http;
use Psr\Http\Message\ServerRequestInterface;
/**
* Minimal request context holder for the current request during dispatch.
* DispatchMiddleware sets/clears it around controller invocation so that
* other services (e.g., response factory selector) can inspect negotiation.
*/
final class RequestContext
{
private static ?ServerRequestInterface $current = null;
public static function set(ServerRequestInterface $request): void
{
self::$current = $request;
}
public static function get(): ?ServerRequestInterface
{
return self::$current;
}
public static function clear(): void
{
self::$current = null;
}
}