<?php
declare(strict_types=1);
namespace Phred\Http\Support;
use Phred\Http\Contracts\ErrorFormatNegotiatorInterface;
use Psr\Http\Message\ServerRequestInterface as ServerRequest;
final class DefaultErrorFormatNegotiator implements ErrorFormatNegotiatorInterface
{
public function apiFormat(ServerRequest $request): string
$accept = $request->getHeaderLine('Accept');
return str_contains($accept, 'application/vnd.api+json') ? 'jsonapi' : 'rest';
}
public function wantsHtml(ServerRequest $request): bool
// Only return true if text/html is explicitly mentioned and is likely the preferred format
return str_contains($accept, 'text/html');