]> git.mxchange.org Git - friendica.git/blob - src/Capabilities/ICanCreateResponses.php
Merge pull request #11136 from urbalazs/error-message-translation
[friendica.git] / src / Capabilities / ICanCreateResponses.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2022, 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
40         const ALLOWED_TYPES = [
41                 self::TYPE_HTML,
42                 self::TYPE_XML,
43                 self::TYPE_JSON,
44                 self::TYPE_ATOM,
45                 self::TYPE_RSS
46         ];
47
48         /**
49          * Adds a header entry to the module response
50          *
51          * @param string $header
52          * @param string|null $key
53          */
54         public function setHeader(string $header, ?string $key = null): void;
55
56         /**
57          * Adds output content to the module response
58          *
59          * @param mixed $content
60          */
61         public function addContent($content): void;
62
63         /**
64          * Sets the response type of the current request
65          *
66          * @param string $type
67          * @param string|null $content_type (optional) overrides the direct content_type, otherwise set the default one
68          *
69          * @throws InternalServerErrorException
70          */
71         public function setType(string $type, ?string $content_type = null): void;
72
73         /**
74          * Creates a PSR-7 compliant interface
75          * @see https://www.php-fig.org/psr/psr-7/
76          *
77          * @return ResponseInterface
78          */
79         public function generate(): ResponseInterface;
80 }