mirror of
https://github.com/friendica/friendica
synced 2025-04-29 10:24:23 +02:00
Introduce Response
for Modules to create a testable way for module responses
This commit is contained in:
parent
ad5b0762b0
commit
561aba18e3
37 changed files with 309 additions and 113 deletions
|
@ -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;
|
||||
}
|
||||
|
|
32
src/Capabilities/ICanReadAndWriteToResponds.php
Normal file
32
src/Capabilities/ICanReadAndWriteToResponds.php
Normal 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);
|
||||
}
|
43
src/Capabilities/IRespondToRequests.php
Normal file
43
src/Capabilities/IRespondToRequests.php
Normal 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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue