]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/Response.php
Standards
[friendica.git] / src / Module / Response.php
index 4cf9f9667e1aff4dd404c9302e3f4961ef7099f3..d24ebe954a8317aaa39a1fbf6a0cc1b8fb310a8f 100644 (file)
@@ -3,8 +3,8 @@
 namespace Friendica\Module;
 
 use Friendica\Capabilities\ICanCreateResponses;
-use Friendica\Capabilities\IRespondToRequests;
 use Friendica\Network\HTTPException\InternalServerErrorException;
+use Psr\Http\Message\ResponseInterface;
 
 class Response implements ICanCreateResponses
 {
@@ -19,7 +19,7 @@ class Response implements ICanCreateResponses
        /**
         * @var string
         */
-       protected $type = IRespondToRequests::TYPE_HTML;
+       protected $type = self::TYPE_HTML;
 
        /**
         * {@inheritDoc}
@@ -68,7 +68,7 @@ class Response implements ICanCreateResponses
         */
        public function setType(string $type, ?string $content_type = null): void
        {
-               if (!in_array($type, IRespondToRequests::ALLOWED_TYPES)) {
+               if (!in_array($type, static::ALLOWED_TYPES)) {
                        throw new InternalServerErrorException('wrong type');
                }
 
@@ -79,9 +79,14 @@ class Response implements ICanCreateResponses
                        case static::TYPE_XML:
                                $content_type = $content_type ?? 'text/xml';
                                break;
+                       case static::TYPE_RSS:
+                               $content_type = $content_type ?? 'application/rss+xml';
+                               break;
+                       case static::TYPE_ATOM:
+                               $content_type = $content_type ?? 'application/atom+xml';
+                               break;
                }
 
-
                $this->setHeader($content_type, 'Content-type');
 
                $this->type = $type;
@@ -94,4 +99,15 @@ class Response implements ICanCreateResponses
        {
                return $this->type;
        }
+
+       /**
+        * {@inheritDoc}
+        */
+       public function generate(): ResponseInterface
+       {
+               // Setting the response type as an X-header for direct usage
+               $this->headers[static::X_HEADER] = $this->type;
+
+               return new \GuzzleHttp\Psr7\Response(200, $this->headers, $this->content);
+       }
 }