neat-php / http-server

Neat HTTP Server components
MIT License
0 stars 0 forks source link

XML output support #11

Closed annavanbiemen closed 3 years ago

annavanbiemen commented 3 years ago

The Output class should be able to produce XML responses using either an

annavanbiemen commented 3 years ago

On second thought... automatically detecting the type of XML argument passed adds complexity while the caller can just simply use a single method call to the appropriate API to convert any SimpleXMLElement or DOMDocument instance into a string.

A string-only API should suffice:

public function xml(string $document): Response
baukevdw commented 3 years ago

Or register an xml handler like this:

$output->register(SimpleXMLElement::class, function (SimpleXMLElement $xml) use ($output): Response {
    return $output->text($xml->asXML())->withContentType('text/xml');
});

An XML handler that set's the header would be an useful addition though.

annavanbiemen commented 3 years ago

Added the xml handler with just a text/xml Content-Type.