From ef9fb32bbaa5384ca16f003d5cf21a46f55d8a1a Mon Sep 17 00:00:00 2001 From: Christian Wolf Date: Fri, 28 Feb 2025 16:01:27 +0100 Subject: [PATCH] Move section custom responses Signed-off-by: Christian Wolf --- developer_manual/basics/controllers.rst | 59 ++++++++++++------------- 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/developer_manual/basics/controllers.rst b/developer_manual/basics/controllers.rst index 9ae99dc52..77c89233b 100644 --- a/developer_manual/basics/controllers.rst +++ b/developer_manual/basics/controllers.rst @@ -686,6 +686,34 @@ A file download can be triggered by returning a DownloadResponse: Creating custom responses ^^^^^^^^^^^^^^^^^^^^^^^^^ +If no premade Response fits the needed use case, it is possible to extend the Response base class and custom Response. The only thing that needs to be implemented is the **render** method which returns the result as string. + +Creating a custom XMLResponse class could look like this: + +.. code-block:: php + + addHeader('Content-Type', 'application/xml'); + $this->xml = $xml; + } + + public function render(): string { + $root = new SimpleXMLElement(''); + array_walk_recursive($this->xml, array ($root, 'addChild')); + return $xml->asXML(); + } + + } + Streamed and lazily rendered responses ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -816,37 +844,6 @@ The following policy for instance allows images, audio and videos from other dom --- -Creating custom responses -^^^^^^^^^^^^^^^^^^^^^^^^^ - -If no premade Response fits the needed use case, it is possible to extend the Response base class and custom Response. The only thing that needs to be implemented is the **render** method which returns the result as string. - -Creating a custom XMLResponse class could look like this: - -.. code-block:: php - - addHeader('Content-Type', 'application/xml'); - $this->xml = $xml; - } - - public function render(): string { - $root = new SimpleXMLElement(''); - array_walk_recursive($this->xml, array ($root, 'addChild')); - return $xml->asXML(); - } - - } - Streamed and lazily rendered responses ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^