Zum Inhalt springen

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#

MethodDescription
->__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,
)
ParameterTypeDescription
$maxBytesint = 10 * 1024 * 1024
$timeoutint = 10
$maxRedirectsint = 3
$resolver(Closure(string): list<string>)|null = nullhost name => IP addresses
$transport(Closure(string, string, string): (array{status: int, location: ?string, body: string}|null))|null = nullURL, host, pinned IP => response, null on failure

fetch()#

public function fetch(string $url): ?string

Content of the image, or null if it cannot be downloaded.

ParameterTypeDescription
$urlstring
Returns
?string
Throws
ConfigurationException – for URLs that are not allowed (scheme, non-public address)

isPublicAddress()#

public static function isPublicAddress(string $ip): bool

static

Whether the address is publicly routable: no loopback, private, link-local, shared, reserved, documentation or multicast range, also not embedded in an IPv6 address.

ParameterTypeDescription
$ipstring
Returns
bool

Die Open-Core-Pakete stehen unter der MIT-Lizenz. Die rechtlichen Formulierungen der Länderpakete sind mit einer Steuerberatung abzustimmen.