3 * @copyright Copyright (C) 2010-2022, the Friendica project
5 * @license GNU AGPL version 3 or any later version
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.
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.
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/>.
22 namespace Friendica\Capabilities;
24 use Friendica\Network\HTTPException\InternalServerErrorException;
25 use Psr\Http\Message\ResponseInterface;
27 interface ICanCreateResponses
30 * This constant helps to find the specific return type of responses inside the headers array
32 const X_HEADER = 'X-RESPONSE-TYPE';
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';
41 const ALLOWED_TYPES = [
51 * Adds a header entry to the module response
53 * @param string $header
54 * @param string|null $key
56 public function setHeader(string $header, ?string $key = null): void;
59 * Adds output content to the module response
61 * @param mixed $content
63 public function addContent($content): void;
66 * Sets the response type of the current request
69 * @param string|null $content_type (optional) overrides the direct content_type, otherwise set the default one
71 * @throws InternalServerErrorException
73 public function setType(string $type, ?string $content_type = null): void;
76 * Sets the status and the reason for the response
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)
83 public function setStatus(int $status = 200, ?string $reason = null): void;
86 * Creates a PSR-7 compliant interface
87 * @see https://www.php-fig.org/psr/psr-7/
89 * @return ResponseInterface
91 public function generate(): ResponseInterface;