Skip to content

Internals Response Senders AudioSender

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

response\senders\AudioSender

Framework Internals · Subsystem overview · Developer guide

Source: awt_src/classes/response/senders/AudioSender.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.

AudioSender

Declaration and architectural role

class AudioSender 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 = [ 'audio/mpeg', 'audio/ogg', 'audio/wav', 'audio/webm', 'audio/aac', 'audio/flac', 'audio/x-m4a', ]; 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 17

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 26

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. Handles HTTP Range requests for audio seeking.

External effects include http_response_code, header.

Implementation, validation guards and interaction order
/**
     * $payload must be a file path.
     * Handles HTTP Range requests for audio seeking.
     */
    public function send(mixed $payload, int $status, array $headers): void
    {
        $path = (string) $payload;
        $this->requireReadable($path);

        $mime     = $this->mimeFromPath($path);
        $fileSize = $this->fileSize($path);
        $range    = $_SERVER['HTTP_RANGE'] ?? null;

        if ($range) {
            [$start, $end] = $this->parseRange($range, $fileSize);
            $length        = $end - $start + 1;

            http_response_code(206);
            $this->emitContentType($mime);
            header("Content-Length: $length");
            header("Content-Range: bytes $start-$end/$fileSize");
            header('Accept-Ranges: bytes');
            $this->emitHeaders($headers);

            $this->streamRange($path, $start, $length);
        } else {
            $this->emitStatus($status);
            $this->emitContentType($mime);
            header("Content-Length: $fileSize");
            header('Accept-Ranges: bytes');
            $this->emitHeaders($headers);

            $this->streamFile($path);
        }
    }

mimeFromPath

Source line 58

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) { 'mp3' => 'audio/mpeg', 'ogg', 'oga' => 'audio/ogg', 'wav' => 'audio/wav', 'weba' => 'audio/webm', 'aac' => 'audio/aac', 'flac' => 'audio/flac', 'm4a' => 'audio/x-m4a', default => throw new \RuntimeException("Unsupported audio 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) {
            'mp3'         => 'audio/mpeg',
            'ogg', 'oga'  => 'audio/ogg',
            'wav'         => 'audio/wav',
            'weba'        => 'audio/webm',
            'aac'         => 'audio/aac',
            'flac'        => 'audio/flac',
            'm4a'         => 'audio/x-m4a',
            default       => throw new \RuntimeException("Unsupported audio extension: '.$ext'."),
        };
    }

Related types

Clone this wiki locally