Skip to content

Internals Response Senders ImageSender

Stefan Crkvenjakov edited this page Oct 7, 2026 · 1 revision

response\senders\ImageSender

Framework Internals · Subsystem overview · Developer guide

Source: awt_src/classes/response/senders/ImageSender.php · Snapshot 8411f4287706.

Response builds status, headers and data/file payloads, chooses a MIME sender, and emits HTTP output. JSON arrays are wrapped in a status/message/data envelope.

ImageSender

Declaration and architectural role

class ImageSender extends AbstractSender

Constants, enum cases, traits and properties

Declarations below preserve visibility, type, default and modifiers exactly. A typed property without an initializer remains uninitialized until its constructor or another method assigns it. Mutable fields belong to this instance unless marked static; readonly fields can be initialized once. Constructor-promoted properties are also listed below.

Member Declaration Purpose or source contract
const MIMES private const MIMES = [ 'image/jpeg', 'image/png', 'image/gif', 'image/webp', 'image/svg+xml', 'image/x-icon', 'image/bmp', 'image/tiff', 'image/avif', ]; State or definition consumed by the methods below; reads and writes are preserved in their implementation traces.

Method index

Method Signature
supportedMimes public function supportedMimes(): array
send public function send(mixed $payload, int $status, array $headers): void
mimeFromPath private function mimeFromPath(string $path): string

supportedMimes

Source line 19

public function supportedMimes(): array

Return expressions (including local callbacks): self::MIMES.

Implementation, validation guards and interaction order
public function supportedMimes(): array
    {
        return self::MIMES;
    }

send

Source line 28

public function send(mixed $payload, int $status, array $headers): void

Parameters

Parameter Type, modifiers and default Purpose
$payload mixed $payload Operation input; the exact use, validation and propagation are shown in the implementation trace.
$status int $status Operation input; the exact use, validation and propagation are shown in the implementation trace.
$headers array $headers Operation input; the exact use, validation and propagation are shown in the implementation trace.

$payload must be a file path. MIME is resolved from the file's extension.

External effects include header.

Implementation, validation guards and interaction order
/**
     * $payload must be a file path.
     * MIME is resolved from the file's extension.
     */
    public function send(mixed $payload, int $status, array $headers): void
    {
        $path = (string) $payload;
        $this->requireReadable($path);

        $mime = $this->mimeFromPath($path);
        $size = $this->fileSize($path);

        $this->emitStatus($status);
        $this->emitContentType($mime);
        header("Content-Length: $size");
        $this->emitHeaders($headers);

        $this->streamFile($path);
    }

mimeFromPath

Source line 44

private function mimeFromPath(string $path): string

Parameters

Parameter Type, modifiers and default Purpose
$path string $path Filesystem or route path as defined by the owning component; no universal path normalization is implied.

Return expressions (including local callbacks): match ($ext) { 'jpg', 'jpeg' => 'image/jpeg', 'png' => 'image/png', 'gif' => 'image/gif', 'webp' => 'image/webp', 'svg' => 'image/svg+xml', 'ico' => 'image/x-icon', 'bmp' => 'image/bmp', 'tiff', 'tif' => 'image/tiff', 'avif' => 'image/avif', default => throw new \RuntimeException("Unsupported image extension: '.$ext'."), }.

Explicit exceptions: \RuntimeException. The guards in the implementation below show when each is raised; exceptions from collaborators also propagate unless caught.

Implementation, validation guards and interaction order
private function mimeFromPath(string $path): string
    {
        $ext = strtolower(pathinfo($path, PATHINFO_EXTENSION));
        return match ($ext) {
            'jpg', 'jpeg' => 'image/jpeg',
            'png'         => 'image/png',
            'gif'         => 'image/gif',
            'webp'        => 'image/webp',
            'svg'         => 'image/svg+xml',
            'ico'         => 'image/x-icon',
            'bmp'         => 'image/bmp',
            'tiff', 'tif' => 'image/tiff',
            'avif'        => 'image/avif',
            default       => throw new \RuntimeException("Unsupported image extension: '.$ext'."),
        };
    }

Related types

Clone this wiki locally