API reference / Quittio \ Core \ Pdf
RemoteImageFetcher
final readonly class in quittio/core
Quittio\Core\Pdf\RemoteImageFetcher · Source
Downloads remote logos without server-side request forgery: only http and https, only hosts whose every resolved address (IPv4 and IPv6) is publicly routable, the connection pinned to the checked address (no second DNS lookup) and every redirect checked again.
Methods#
| Method | Description |
|---|---|
->__construct() | |
->fetch() | Content of the image, or null if it cannot be downloaded. |
::isPublicAddress() | Whether the address is publicly routable: no loopback, private, link-local, shared, reserved, documentation or multicast range, also not embedded in an IPv6 address. |
__construct()#
public function __construct(
int $maxBytes = 10 * 1024 * 1024,
int $timeout = 10,
int $maxRedirects = 3,
(Closure(string): list<string>)|null $resolver = null,
(Closure(string, string, string): (array{status: int, location: ?string, body: string}|null))|null $transport = null,
)| Parameter | Type | Description |
|---|---|---|
$maxBytes | int = 10 * 1024 * 1024 | |
$timeout | int = 10 | |
$maxRedirects | int = 3 | |
$resolver | (Closure(string): list<string>)|null = null | host name => IP addresses |
$transport | (Closure(string, string, string): (array{status: int, location: ?string, body: string}|null))|null = null | URL, host, pinned IP => response, null on failure |
fetch()#
public function fetch(string $url): ?stringContent of the image, or null if it cannot be downloaded.
| Parameter | Type | Description |
|---|---|---|
$url | string |
- Returns
?string- Throws
ConfigurationException– for URLs that are not allowed (scheme, non-public address)
isPublicAddress()#
public static function isPublicAddress(string $ip): boolWhether the address is publicly routable: no loopback, private, link-local, shared, reserved, documentation or multicast range, also not embedded in an IPv6 address.
| Parameter | Type | Description |
|---|---|---|
$ip | string |
- Returns
bool