Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | n/a |
0 / 0 |
n/a |
0 / 0 |
CRAP | n/a |
0 / 0 |
|||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\ResourceLoader\Transport; |
| 6 | |
| 7 | use Phpdftk\ResourceLoader\Exception\FetchFailedException; |
| 8 | |
| 9 | /** |
| 10 | * One-shot HTTP transport — given a URL, headers, and a timeout, |
| 11 | * return one {@see RawResponse} or throw. |
| 12 | * |
| 13 | * The transport does NOT follow redirects, enforce content-length, |
| 14 | * or re-check SSRF against the resolved IP — those are the |
| 15 | * fetcher's job. Splitting the concerns lets the fetcher's |
| 16 | * orchestration be tested against a fake transport without needing |
| 17 | * a live HTTP server. |
| 18 | * |
| 19 | * Implementations: |
| 20 | * |
| 21 | * - {@see CurlTransport} — curl-based production transport. |
| 22 | * - tests/`FakeTransport` — in-test mock that returns canned |
| 23 | * responses; used by HttpFetcherTest |
| 24 | * so the redirect / cap / SSRF re-check |
| 25 | * logic can be exercised without |
| 26 | * network access. |
| 27 | */ |
| 28 | interface TransportInterface |
| 29 | { |
| 30 | /** |
| 31 | * Send a single HTTP request and return the response. |
| 32 | * |
| 33 | * @param string $url Absolute URL. |
| 34 | * @param array<string, string> $headers Header name (canonical case) → value. |
| 35 | * @param int $timeoutSeconds Total request budget. |
| 36 | * @param int $maxBodyBytes Abort if the |
| 37 | * response body |
| 38 | * exceeds this |
| 39 | * (transport-level |
| 40 | * defence; the |
| 41 | * fetcher also |
| 42 | * enforces). |
| 43 | * @throws FetchFailedException on connect / DNS / timeout / non- |
| 44 | * parseable-response failure. |
| 45 | */ |
| 46 | public function send( |
| 47 | string $url, |
| 48 | array $headers, |
| 49 | int $timeoutSeconds, |
| 50 | int $maxBodyBytes, |
| 51 | ): RawResponse; |
| 52 | } |