]> git.mxchange.org Git - friendica.git/blob - src/Capabilities/ICanCreateResponses.php
spelling: author
[friendica.git] / src / Capabilities / ICanCreateResponses.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2023, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Capabilities;
23
24 use Friendica\Network\HTTPException\InternalServerErrorException;
25 use Psr\Http\Message\ResponseInterface;
26
27 interface ICanCreateResponses
28 {
29         /**
30          * This constant helps to find the specific return type of responses inside the headers array
31          */
32         const X_HEADER = 'X-RESPONSE-TYPE';
33
34         const TYPE_HTML  = 'html';
35         const TYPE_XML   = 'xml';
36         const TYPE_JSON  = 'json';
37         const TYPE_ATOM  = 'atom';
38         const TYPE_RSS   = 'rss';
39         const TYPE_BLANK = 'blank';
40
41         const ALLOWED_TYPES = [
42                 self::TYPE_HTML,
43                 self::TYPE_XML,
44                 self::TYPE_JSON,
45                 self::TYPE_ATOM,
46                 self::TYPE_RSS,
47                 self::TYPE_BLANK,
48         ];
49
50         /**
51          * Adds a header entry to the module response
52          *
53          * @param string $header
54          * @param string|null $key
55          */
56         public function setHeader(string $header, ?string $key = null): void;
57
58         /**
59          * Adds output content to the module response
60          *
61          * @param mixed $content
62          */
63         public function addContent($content): void;
64
65         /**
66          * Sets the response type of the current request
67          *
68          * @param string $type
69          * @param string|null $content_type (optional) overrides the direct content_type, otherwise set the default one
70          *
71          * @throws InternalServerErrorException
72          */
73         public function setType(string $type, ?string $content_type = null): void;
74
75         /**
76          * Sets the status and the reason for the response
77          *
78          * @param int $status The HTTP status code
79          * @param null|string $reason Reason phrase (when empty a default will be used based on the status code)
80          *
81          * @return void
82          */
83         public function setStatus(int $status = 200, ?string $reason = null): void;
84
85         /**
86          * Creates a PSR-7 compliant interface
87          * @see https://www.php-fig.org/psr/psr-7/
88          *
89          * @return ResponseInterface
90          */
91         public function generate(): ResponseInterface;
92 }