Repository navigation
Internals 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.
class XmlSender extends AbstractSenderNo own constants, enum cases, traits or property declarations. Inherited members are documented on the parent reference page.
| 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 |
public function supportedMimes(): arrayReturn expressions (including local callbacks): ['application/xml', 'text/xml'].
Implementation, validation guards and interaction order
public function supportedMimes(): array
{
return ['application/xml', 'text/xml'];
}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 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;
}
}private function arrayToXml(array $data, string $rootElement = 'response'): string| 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();
}private function buildXml(\SimpleXMLElement $xml, array $data): void| 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));
}
}
}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