Skip to content

Internals Response Senders XmlSender

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

response\senders\XmlSender

Framework Internals · Subsystem overview · Developer guide

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

XmlSender

Declaration and architectural role

class XmlSender extends AbstractSender

Constants, enum cases, traits and properties

No own constants, enum cases, traits or property declarations. Inherited members are documented on the parent reference page.

Method index

Method Signature
supportedMimes public function supportedMimes(): array
send public function send(mixed $payload, int $status, array $headers): void
arrayToXml private function arrayToXml(array $data, string $rootElement = 'response'): string
buildXml private function buildXml(\SimpleXMLElement $xml, array $data): void

supportedMimes

Source line 7

public function supportedMimes(): array

Return expressions (including local callbacks): ['application/xml', 'text/xml'].

Implementation, validation guards and interaction order
public function supportedMimes(): array
    {
        return ['application/xml', 'text/xml'];
    }

send

Source line 18

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 may be:

  • string path to an .xml file
  • string raw XML
  • array → auto-converted to XML

Delegates to emitStatus(), emitContentType(), emitHeaders(), arrayToXml(), streamFile().

Implementation, validation guards and interaction order
/**
     * $payload may be:
     *  - string path to an .xml file
     *  - string raw XML
     *  - array  → auto-converted to XML
     */
    public function send(mixed $payload, int $status, array $headers): void
    {
        $this->emitStatus($status);
        $this->emitContentType('application/xml; charset=UTF-8');
        $this->emitHeaders($headers);

        if (is_array($payload)) {
            echo $this->arrayToXml($payload);
        } elseif (is_string($payload) && file_exists($payload)) {
            $this->streamFile($payload);
        } else {
            echo (string) $payload;
        }
    }

arrayToXml

Source line 33

private function arrayToXml(array $data, string $rootElement = 'response'): string

Parameters

Parameter Type, modifiers and default Purpose
$data array $data Input data array or payload; see allowed fields and validation guards below.
$rootElement string $rootElement = 'response' Operation input; the exact use, validation and propagation are shown in the implementation trace.

Return expressions (including local callbacks): $dom->saveXML().

Implementation, validation guards and interaction order
private function arrayToXml(array $data, string $rootElement = 'response'): string
    {
        $xml = new \SimpleXMLElement("<?xml version=\"1.0\" encoding=\"UTF-8\"?><$rootElement/>");
        $this->buildXml($xml, $data);
        $dom = dom_import_simplexml($xml)->ownerDocument;
        $dom->formatOutput = true;
        return $dom->saveXML();
    }

buildXml

Source line 42

private function buildXml(\SimpleXMLElement $xml, array $data): void

Parameters

Parameter Type, modifiers and default Purpose
$xml \SimpleXMLElement $xml Operation input; the exact use, validation and propagation are shown in the implementation trace.
$data array $data Input data array or payload; see allowed fields and validation guards below.

Delegates to buildXml().

Implementation, validation guards and interaction order
private function buildXml(\SimpleXMLElement $xml, array $data): void
    {
        foreach ($data as $key => $value) {
            $tag = is_numeric($key) ? 'item' : $key;
            if (is_array($value)) {
                $child = $xml->addChild($tag);
                $this->buildXml($child, $value);
            } else {
                $xml->addChild($tag, htmlspecialchars((string) $value, ENT_XML1));
            }
        }
    }

Related types

Clone this wiki locally