mirror of
https://github.com/friendica/friendica
synced 2025-04-19 10:30:10 +00:00
Replace IRespondToRequests with PSR-7 ResponseInterface
This commit is contained in:
parent
ca5c40c97e
commit
7cd85873ee
17 changed files with 96 additions and 92 deletions
|
@ -22,9 +22,9 @@
|
|||
namespace Friendica\Module\HTTPException;
|
||||
|
||||
use Friendica\BaseModule;
|
||||
use Friendica\Capabilities\IRespondToRequests;
|
||||
use Friendica\DI;
|
||||
use Friendica\Network\HTTPException;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
class PageNotFound extends BaseModule
|
||||
{
|
||||
|
@ -33,7 +33,7 @@ class PageNotFound extends BaseModule
|
|||
throw new HTTPException\NotFoundException(DI::l10n()->t('Page not found.'));
|
||||
}
|
||||
|
||||
public function run(array $post = [], array $request = []): IRespondToRequests
|
||||
public function run(array $post = [], array $request = []): ResponseInterface
|
||||
{
|
||||
/* The URL provided does not resolve to a valid module.
|
||||
*
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace Friendica\Module;
|
|||
|
||||
use Friendica\App;
|
||||
use Friendica\BaseModule;
|
||||
use Friendica\Capabilities\IRespondToRequests;
|
||||
use Friendica\Capabilities\ICanCreateResponses;
|
||||
use Friendica\Core\Addon;
|
||||
use Friendica\Core\Config\Capability\IManageConfigValues;
|
||||
use Friendica\Core\L10n;
|
||||
|
@ -98,7 +98,7 @@ class NodeInfo110 extends BaseModule
|
|||
|
||||
$nodeinfo['metadata']['explicitContent'] = $this->config->get('system', 'explicit_content', false) == true;
|
||||
|
||||
$this->response->setType(IRespondToRequests::TYPE_JSON);
|
||||
$this->response->setType(ICanCreateResponses::TYPE_JSON);
|
||||
$this->response->addContent(json_encode($nodeinfo, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace Friendica\Module;
|
|||
|
||||
use Friendica\App;
|
||||
use Friendica\BaseModule;
|
||||
use Friendica\Capabilities\IRespondToRequests;
|
||||
use Friendica\Capabilities\ICanCreateResponses;
|
||||
use Friendica\Core\Addon;
|
||||
use Friendica\Core\Config\Capability\IManageConfigValues;
|
||||
use Friendica\Core\L10n;
|
||||
|
@ -90,7 +90,7 @@ class NodeInfo120 extends BaseModule
|
|||
|
||||
$nodeinfo['metadata']['explicitContent'] = $this->config->get('system', 'explicit_content', false) == true;
|
||||
|
||||
$this->response->setType(IRespondToRequests::TYPE_JSON, 'application/json; charset=utf-8');
|
||||
$this->response->setType(ICanCreateResponses::TYPE_JSON, 'application/json; charset=utf-8');
|
||||
$this->response->addContent(json_encode($nodeinfo, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,11 +23,10 @@ namespace Friendica\Module;
|
|||
|
||||
use Friendica\App;
|
||||
use Friendica\BaseModule;
|
||||
use Friendica\Capabilities\IRespondToRequests;
|
||||
use Friendica\Capabilities\ICanCreateResponses;
|
||||
use Friendica\Core\Addon;
|
||||
use Friendica\Core\Config\Capability\IManageConfigValues;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Model\Nodeinfo;
|
||||
use Friendica\Util\Profiler;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
@ -89,7 +88,7 @@ class NodeInfo210 extends BaseModule
|
|||
$nodeinfo['services']['inbound'][] = 'imap';
|
||||
}
|
||||
|
||||
$this->response->setType(IRespondToRequests::TYPE_JSON, 'application/json; charset=utf-8');
|
||||
$this->response->setType(ICanCreateResponses::TYPE_JSON, 'application/json; charset=utf-8');
|
||||
$this->response->addContent(json_encode($nodeinfo, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
namespace Friendica\Module;
|
||||
|
||||
use Friendica\Capabilities\ICanCreateResponses;
|
||||
use Friendica\Capabilities\IRespondToRequests;
|
||||
use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
class Response implements ICanCreateResponses
|
||||
{
|
||||
|
@ -19,7 +19,7 @@ class Response implements ICanCreateResponses
|
|||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $type = IRespondToRequests::TYPE_HTML;
|
||||
protected $type = ICanCreateResponses::TYPE_HTML;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
|
@ -68,7 +68,7 @@ class Response implements ICanCreateResponses
|
|||
*/
|
||||
public function setType(string $type, ?string $content_type = null): void
|
||||
{
|
||||
if (!in_array($type, IRespondToRequests::ALLOWED_TYPES)) {
|
||||
if (!in_array($type, ICanCreateResponses::ALLOWED_TYPES)) {
|
||||
throw new InternalServerErrorException('wrong type');
|
||||
}
|
||||
|
||||
|
@ -94,4 +94,25 @@ class Response implements ICanCreateResponses
|
|||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function generate(): ResponseInterface
|
||||
{
|
||||
$headers = [];
|
||||
|
||||
foreach ($this->headers as $key => $header) {
|
||||
if (empty($key)) {
|
||||
$headers[] = $header;
|
||||
} else {
|
||||
$headers[] = "$key: $header";
|
||||
}
|
||||
}
|
||||
|
||||
// Setting the response type as an X-header for direct usage
|
||||
$headers['X-RESPONSE-TYPE'] = $this->type;
|
||||
|
||||
return new \GuzzleHttp\Psr7\Response(200, $this->headers, $this->content);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue