Introduce Response for Modules to create a testable way for module responses

This commit is contained in:
Philipp 2021-11-21 20:06:36 +01:00
parent ad5b0762b0
commit 561aba18e3
No known key found for this signature in database
GPG key ID: 24A7501396EB5432
37 changed files with 309 additions and 113 deletions

View file

@ -13,9 +13,9 @@ interface ICanHandleRequests
* @param array $post The $_POST content (in case of POST)
* @param array $request The $_REQUEST content (in case of GET, POST)
*
* @return string Returns the content of the module as string
* @return IRespondToRequests responding to the request handling
*
* @throws HTTPException\InternalServerErrorException
*/
public function run(array $post = [], array $request = []): string;
public function run(array $post = [], array $request = []): IRespondToRequests;
}

View file

@ -0,0 +1,32 @@
<?php
namespace Friendica\Capabilities;
use Friendica\Network\HTTPException\InternalServerErrorException;
interface ICanReadAndWriteToResponds extends IRespondToRequests
{
/**
* Adds a header entry to the module response
*
* @param string $key
* @param string $value
*/
public function addHeader(string $key, string $value);
/**
* Adds output content to the module response
*
* @param string $content
*/
public function addContent(string $content);
/**
* Sets the response type of the current request
*
* @param string $type
*
* @throws InternalServerErrorException
*/
public function setType(string $type);
}

View file

@ -0,0 +1,43 @@
<?php
namespace Friendica\Capabilities;
interface IRespondToRequests
{
const TYPE_CONTENT = 'content';
const TYPE_RAW_CONTENT = 'rawContent';
const TYPE_POST = 'post';
const TYPE_PUT = 'put';
const TYPE_DELETE = 'delete';
const TYPE_PATCH = 'patch';
const ALLOWED_TYPES = [
self::TYPE_CONTENT,
self::TYPE_RAW_CONTENT,
self::TYPE_POST,
self::TYPE_PUT,
self::TYPE_DELETE,
self::TYPE_PATCH,
];
/**
* Returns all set headers during the module execution
*
* @return string[][]
*/
public function getHeaders(): array;
/**
* Returns the output of the module
*
* @return string
*/
public function getContent(): string;
/**
* Returns the response type of the current request
*
* @return string
*/
public function getTyp(): string;
}