2021-11-21 15:52:36 -05:00
|
|
|
<?php
|
2022-01-02 04:49:50 -05:00
|
|
|
/**
|
|
|
|
* @copyright Copyright (C) 2010-2022, the Friendica project
|
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
2021-11-21 15:52:36 -05:00
|
|
|
|
|
|
|
namespace Friendica\Capabilities;
|
|
|
|
|
|
|
|
use Friendica\Network\HTTPException\InternalServerErrorException;
|
2021-11-21 17:37:17 -05:00
|
|
|
use Psr\Http\Message\ResponseInterface;
|
2021-11-21 15:52:36 -05:00
|
|
|
|
2021-11-21 17:37:17 -05:00
|
|
|
interface ICanCreateResponses
|
2021-11-21 15:52:36 -05:00
|
|
|
{
|
2021-11-21 18:07:09 -05:00
|
|
|
/**
|
|
|
|
* This constant helps to find the specific return type of responses inside the headers array
|
|
|
|
*/
|
|
|
|
const X_HEADER = 'X-RESPONSE-TYPE';
|
|
|
|
|
2022-01-03 13:55:47 -05:00
|
|
|
const TYPE_HTML = 'html';
|
|
|
|
const TYPE_XML = 'xml';
|
|
|
|
const TYPE_JSON = 'json';
|
|
|
|
const TYPE_ATOM = 'atom';
|
|
|
|
const TYPE_RSS = 'rss';
|
|
|
|
const TYPE_BLANK = 'blank';
|
2021-11-21 17:37:17 -05:00
|
|
|
|
|
|
|
const ALLOWED_TYPES = [
|
|
|
|
self::TYPE_HTML,
|
|
|
|
self::TYPE_XML,
|
|
|
|
self::TYPE_JSON,
|
|
|
|
self::TYPE_ATOM,
|
2022-01-03 13:55:47 -05:00
|
|
|
self::TYPE_RSS,
|
|
|
|
self::TYPE_BLANK,
|
2021-11-21 17:37:17 -05:00
|
|
|
];
|
|
|
|
|
2021-11-21 15:52:36 -05:00
|
|
|
/**
|
|
|
|
* Adds a header entry to the module response
|
|
|
|
*
|
|
|
|
* @param string $header
|
|
|
|
* @param string|null $key
|
|
|
|
*/
|
|
|
|
public function setHeader(string $header, ?string $key = null): void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds output content to the module response
|
|
|
|
*
|
|
|
|
* @param mixed $content
|
|
|
|
*/
|
|
|
|
public function addContent($content): void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the response type of the current request
|
|
|
|
*
|
|
|
|
* @param string $type
|
|
|
|
* @param string|null $content_type (optional) overrides the direct content_type, otherwise set the default one
|
|
|
|
*
|
|
|
|
* @throws InternalServerErrorException
|
|
|
|
*/
|
|
|
|
public function setType(string $type, ?string $content_type = null): void;
|
2021-11-21 17:37:17 -05:00
|
|
|
|
2022-01-02 15:28:28 -05:00
|
|
|
/**
|
|
|
|
* Sets the status and the reason for the response
|
|
|
|
*
|
|
|
|
* @param int $status The HTTP status code
|
|
|
|
* @param null|string $reason Reason phrase (when empty a default will be used based on the status code)
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function setStatus(int $status = 200, ?string $reason = null): void;
|
|
|
|
|
2021-11-21 17:37:17 -05:00
|
|
|
/**
|
|
|
|
* Creates a PSR-7 compliant interface
|
|
|
|
* @see https://www.php-fig.org/psr/psr-7/
|
|
|
|
*
|
|
|
|
* @return ResponseInterface
|
|
|
|
*/
|
|
|
|
public function generate(): ResponseInterface;
|
2021-11-21 15:52:36 -05:00
|
|
|
}
|