Repository navigation
Internals Response Senders AbstractSender
Framework Internals · Subsystem overview · Developer guide
Source: awt_src/classes/response/senders/AbstractSender.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.
use response\interface\SenderInterface;abstract class AbstractSender implements SenderInterfaceNo own constants, enum cases, traits or property declarations. Inherited members are documented on the parent reference page.
| Method | Signature |
|---|---|
| emitStatus | protected function emitStatus(int $status): void |
| emitHeaders | protected function emitHeaders(array $headers): void |
| emitContentType | protected function emitContentType(string $mime): void |
| requireReadable | protected function requireReadable(string $path): void |
| fileSize | protected function fileSize(string $path): int |
| streamFile | protected function streamFile(string $path): void |
| streamRange | protected function streamRange(string $path, int $start, int $length): void |
| parseRange | protected function parseRange(string $range, int $fileSize): array |
protected function emitStatus(int $status): void| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$status |
int $status |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
External effects include http_response_code.
Implementation, validation guards and interaction order
// ── Shared helpers ────────────────────────────────────────────────────────
protected function emitStatus(int $status): void
{
http_response_code($status);
}protected function emitHeaders(array $headers): void| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$headers |
array $headers |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
External effects include header.
Implementation, validation guards and interaction order
protected function emitHeaders(array $headers): void
{
foreach ($headers as $name => $value) {
header("$name: $value");
}
}protected function emitContentType(string $mime): void| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$mime |
string $mime |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
External effects include header.
Implementation, validation guards and interaction order
protected function emitContentType(string $mime): void
{
header("Content-Type: $mime");
}protected function requireReadable(string $path): void| 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. |
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
// ── File helpers ──────────────────────────────────────────────────────────
protected function requireReadable(string $path): void
{
if (!file_exists($path)) {
throw new \RuntimeException("File not found: '$path'.");
}
if (!is_readable($path)) {
throw new \RuntimeException("File not readable: '$path'.");
}
}protected function fileSize(string $path): int| 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): $size.
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
protected function fileSize(string $path): int
{
$size = filesize($path);
if ($size === false) {
throw new \RuntimeException("Cannot determine file size: '$path'.");
}
return $size;
}protected function streamFile(string $path): void| 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. |
Stream a whole file in 8 KB chunks.
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
/** Stream a whole file in 8 KB chunks. */
protected function streamFile(string $path): void
{
$this->requireReadable($path);
$handle = fopen($path, 'rb');
if ($handle === false) {
throw new \RuntimeException("Cannot open file: '$path'.");
}
while (!feof($handle)) {
echo fread($handle, 8192);
flush();
}
fclose($handle);
}protected function streamRange(string $path, int $start, int $length): void| 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. |
$start |
int $start |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
$length |
int $length |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
Stream a byte range from a file (for Range requests).
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
/** Stream a byte range from a file (for Range requests). */
protected function streamRange(string $path, int $start, int $length): void
{
$handle = fopen($path, 'rb');
if ($handle === false) {
throw new \RuntimeException("Cannot open file: '$path'.");
}
fseek($handle, $start);
$remaining = $length;
while ($remaining > 0 && !feof($handle)) {
$chunk = min(8192, $remaining);
$data = fread($handle, $chunk);
$remaining -= strlen($data);
echo $data;
flush();
}
fclose($handle);
}protected function parseRange(string $range, int $fileSize): array| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$range |
string $range |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
$fileSize |
int $fileSize |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
Parse an HTTP Range header → [start, end].
Return expressions (including local callbacks): [$start, $end].
Explicit exceptions: \RuntimeException. The guards in the implementation below show when each is raised; exceptions from collaborators also propagate unless caught.
External effects include header, http_response_code.
Implementation, validation guards and interaction order
/** Parse an HTTP Range header → [start, end]. */
protected function parseRange(string $range, int $fileSize): array
{
if (!preg_match('/bytes=(\d*)-(\d*)/', $range, $m)) {
throw new \RuntimeException("Malformed Range header: '$range'.");
}
$start = $m[1] !== '' ? (int) $m[1] : 0;
$end = $m[2] !== '' ? (int) $m[2] : $fileSize - 1;
if ($start > $end || $end >= $fileSize) {
http_response_code(416);
header("Content-Range: bytes */$fileSize");
throw new \RuntimeException("Range not satisfiable.");
}
return [$start, $end];
}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