]> git.mxchange.org Git - friendica.git/blob - src/Capabilities/ICanCreateResponses.php
Merge pull request #11005 from nupplaphil/feat/module_di
[friendica.git] / src / Capabilities / ICanCreateResponses.php
1 <?php
2
3 namespace Friendica\Capabilities;
4
5 use Friendica\Network\HTTPException\InternalServerErrorException;
6 use Psr\Http\Message\ResponseInterface;
7
8 interface ICanCreateResponses
9 {
10         /**
11          * This constant helps to find the specific return type of responses inside the headers array
12          */
13         const X_HEADER = 'X-RESPONSE-TYPE';
14
15         const TYPE_HTML = 'html';
16         const TYPE_XML  = 'xml';
17         const TYPE_JSON = 'json';
18         const TYPE_ATOM = 'atom';
19         const TYPE_RSS  = 'rss';
20
21         const ALLOWED_TYPES = [
22                 self::TYPE_HTML,
23                 self::TYPE_XML,
24                 self::TYPE_JSON,
25                 self::TYPE_ATOM,
26                 self::TYPE_RSS
27         ];
28
29         /**
30          * Adds a header entry to the module response
31          *
32          * @param string $header
33          * @param string|null $key
34          */
35         public function setHeader(string $header, ?string $key = null): void;
36
37         /**
38          * Adds output content to the module response
39          *
40          * @param mixed $content
41          */
42         public function addContent($content): void;
43
44         /**
45          * Sets the response type of the current request
46          *
47          * @param string $type
48          * @param string|null $content_type (optional) overrides the direct content_type, otherwise set the default one
49          *
50          * @throws InternalServerErrorException
51          */
52         public function setType(string $type, ?string $content_type = null): void;
53
54         /**
55          * Creates a PSR-7 compliant interface
56          * @see https://www.php-fig.org/psr/psr-7/
57          *
58          * @return ResponseInterface
59          */
60         public function generate(): ResponseInterface;
61 }