Repository navigation
Internals 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.
class AudioSender extends AbstractSenderDeclarations 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 | Signature |
|---|---|
| supportedMimes | public function supportedMimes(): array |
| send | public function send(mixed $payload, int $status, array $headers): void |
| mimeFromPath | private function mimeFromPath(string $path): string |
public function supportedMimes(): arrayReturn expressions (including local callbacks): self::MIMES.
Implementation, validation guards and interaction order
public function supportedMimes(): array
{
return self::MIMES;
}public function send(mixed $payload, int $status, array $headers): void| 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);
}
}private function mimeFromPath(string $path): string| 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'."),
};
}AWT Framework Wiki · Home · Installation Guide · Developer Guide · Framework Internals
Philosophy · Architecture · Known discrepancies · Verification
Installation Guide
Developer Guide
- Learning sequence
- First package
- Package structure
- Lifecycle
- Runtimes
- Events and objects
- Routing and controllers
- Views and resources
- Database and models
- Storage and caching
- Configuration and CLI
- Responses and errors
- Extension points
Framework Internals
- Architecture
- Bootstrap
- Packages
- Runtime
- Events and context
- Objects
- HTTP routing and controllers
- Rendering
- Blade integration
- Database
- Models
- Storage and caching
- Settings
- CLI
- Identity and sessions
- Responses
- Errors
- Complete source inventory
Documentation notes