mirror of
https://github.com/friendica/friendica
synced 2025-04-19 07:10:11 +00: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
75
src/Module/Response.php
Normal file
75
src/Module/Response.php
Normal file
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Module;
|
||||
|
||||
use Friendica\Capabilities\ICanReadAndWriteToResponds;
|
||||
use Friendica\Capabilities\IRespondToRequests;
|
||||
use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||
|
||||
class Response implements ICanReadAndWriteToResponds
|
||||
{
|
||||
/**
|
||||
* @var string[][]
|
||||
*/
|
||||
protected $headers = [];
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $content = '';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $type = IRespondToRequests::TYPE_CONTENT;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function addHeader(string $key, string $value)
|
||||
{
|
||||
$this->headers[$key][] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function addContent(string $content)
|
||||
{
|
||||
$this->content .= $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getHeaders(): array
|
||||
{
|
||||
return $this->headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getContent(): string
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function setType(string $type)
|
||||
{
|
||||
if (!in_array($type, IRespondToRequests::ALLOWED_TYPES)) {
|
||||
throw new InternalServerErrorException('wrong type');
|
||||
}
|
||||
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getTyp(): string
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue