Skip to content

Internals Response Registry SenderRegistry

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

response\registry\SenderRegistry

Framework Internals · Subsystem overview · Developer guide

Source: awt_src/classes/response/registry/SenderRegistry.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.

Imports and dependencies

use response\interface\SenderInterface;

SenderRegistry

Declaration and architectural role

class SenderRegistry

Source description (behavioral corrections are recorded in Known discrepancies):

Open/Closed: add new types by registering a new SenderInterface. No existing class needs modification.

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
$map private array $map = []; @var array<string, SenderInterface> mime → sender

Method index

Method Signature
register public function register(SenderInterface $sender): void
resolve public function resolve(string $mime): SenderInterface
has public function has(string $mime): bool

register

Source line 16

public function register(SenderInterface $sender): void

Parameters

Parameter Type, modifiers and default Purpose
$sender SenderInterface $sender Operation input; the exact use, validation and propagation are shown in the implementation trace.

State writes: $this->map[strtolower($mime)].

Implementation, validation guards and interaction order
public function register(SenderInterface $sender): void
    {
        foreach ($sender->supportedMimes() as $mime) {
            $this->map[strtolower($mime)] = $sender;
        }
    }

resolve

Source line 26

public function resolve(string $mime): SenderInterface

Parameters

Parameter Type, modifiers and default Purpose
$mime string $mime Operation input; the exact use, validation and propagation are shown in the implementation trace.

@throws \RuntimeException when no sender handles the given MIME.

Return expressions (including local callbacks): $this->map[$key]; $sender.

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
/**
     * @throws \RuntimeException when no sender handles the given MIME.
     */
    public function resolve(string $mime): SenderInterface
    {
        $key = strtolower(strtok($mime, ';')); // strip parameters like "; charset=utf-8"

        if (isset($this->map[$key])) {
            return $this->map[$key];
        }

        // Partial match on type group (e.g. "image/*").
        [$group] = explode('/', $key);
        foreach ($this->map as $registeredMime => $sender) {
            if (str_starts_with($registeredMime, $group . '/')) {
                return $sender;
            }
        }

        throw new \RuntimeException("No sender registered for MIME type '$mime'.");
    }

has

Source line 45

public function has(string $mime): bool

Parameters

Parameter Type, modifiers and default Purpose
$mime string $mime Operation input; the exact use, validation and propagation are shown in the implementation trace.

Return expressions (including local callbacks): true; false.

Failure handling catches \RuntimeException.

Implementation, validation guards and interaction order
public function has(string $mime): bool
    {
        try {
            $this->resolve($mime);
            return true;
        } catch (\RuntimeException) {
            return false;
        }
    }

Related types

Clone this wiki locally