use direct data access for response data

This commit is contained in:
Dennis Eichhorn 2023-05-30 03:42:53 +02:00
parent 06f1784418
commit 678f066a41
6 changed files with 49 additions and 51 deletions

View File

@ -65,7 +65,7 @@ final class CliResponse extends ResponseAbstract implements RenderableInterface
*/ */
public function setResponse(array $response) : void public function setResponse(array $response) : void
{ {
$this->response = $response; $this->data = $response;
} }
/** /**
@ -79,8 +79,8 @@ final class CliResponse extends ResponseAbstract implements RenderableInterface
*/ */
public function remove(string $id) : bool public function remove(string $id) : bool
{ {
if (isset($this->response[$id])) { if (isset($this->data[$id])) {
unset($this->response[$id]); unset($this->data[$id]);
return true; return true;
} }
@ -134,7 +134,7 @@ final class CliResponse extends ResponseAbstract implements RenderableInterface
{ {
$render = ''; $render = '';
foreach ($this->response as $response) { foreach ($this->data as $response) {
$render .= StringUtils::stringify($response); $render .= StringUtils::stringify($response);
} }
@ -148,7 +148,7 @@ final class CliResponse extends ResponseAbstract implements RenderableInterface
{ {
$result = []; $result = [];
foreach ($this->response as $response) { foreach ($this->data as $response) {
if ($response instanceof View) { if ($response instanceof View) {
$result[] = $response->toArray(); $result[] = $response->toArray();
} elseif (\is_array($response) || \is_scalar($response)) { } elseif (\is_array($response) || \is_scalar($response)) {

View File

@ -59,7 +59,7 @@ final class HttpResponse extends ResponseAbstract implements RenderableInterface
*/ */
public function setResponse(array $response) : void public function setResponse(array $response) : void
{ {
$this->response = $response; $this->data = $response;
} }
/** /**
@ -73,8 +73,8 @@ final class HttpResponse extends ResponseAbstract implements RenderableInterface
*/ */
public function remove(string $id) : bool public function remove(string $id) : bool
{ {
if (isset($this->response[$id])) { if (isset($this->data[$id])) {
unset($this->response[$id]); unset($this->data[$id]);
return true; return true;
} }
@ -143,7 +143,7 @@ final class HttpResponse extends ResponseAbstract implements RenderableInterface
private function getRaw(bool $optimize = false) : string private function getRaw(bool $optimize = false) : string
{ {
$render = ''; $render = '';
foreach ($this->response as $response) { foreach ($this->data as $response) {
// @note: Api functions return void -> null, this is where the null value is "ignored"/rendered as '' // @note: Api functions return void -> null, this is where the null value is "ignored"/rendered as ''
$render .= StringUtils::stringify($response); $render .= StringUtils::stringify($response);
} }
@ -183,7 +183,7 @@ final class HttpResponse extends ResponseAbstract implements RenderableInterface
{ {
$result = []; $result = [];
foreach ($this->response as $response) { foreach ($this->data as $response) {
if ($response instanceof View) { if ($response instanceof View) {
$result[] = $response->toArray(); $result[] = $response->toArray();
} elseif (\is_array($response) || \is_scalar($response)) { } elseif (\is_array($response) || \is_scalar($response)) {

View File

@ -40,7 +40,7 @@ abstract class RequestAbstract implements MessageInterface
* @var array<int|string, mixed> * @var array<int|string, mixed>
* @since 1.0.0 * @since 1.0.0
*/ */
protected array $data = []; public array $data = [];
/** /**
* Files data. * Files data.
@ -48,7 +48,7 @@ abstract class RequestAbstract implements MessageInterface
* @var array * @var array
* @since 1.0.0 * @since 1.0.0
*/ */
protected array $files = []; public array $files = [];
/** /**
* Request lock. * Request lock.

View File

@ -32,7 +32,7 @@ abstract class ResponseAbstract implements \JsonSerializable, MessageInterface
* @var array * @var array
* @since 1.0.0 * @since 1.0.0
*/ */
protected array $response = []; public array $data = [];
/** /**
* Header. * Header.
@ -53,7 +53,7 @@ abstract class ResponseAbstract implements \JsonSerializable, MessageInterface
*/ */
public function get(mixed $id) : mixed public function get(mixed $id) : mixed
{ {
return $this->response[$id] ?? null; return $this->data[$id] ?? null;
} }
/** /**
@ -69,9 +69,7 @@ abstract class ResponseAbstract implements \JsonSerializable, MessageInterface
*/ */
public function set(mixed $key, mixed $response, bool $overwrite = false) : void public function set(mixed $key, mixed $response, bool $overwrite = false) : void
{ {
// This is not working since the key contains :: from http:// $this->data[$key] = $response;
//$this->response = ArrayUtils::setArray((string) $key, $this->response, $response, ':', $overwrite);
$this->response[$key] = $response;
} }
/** /**

View File

@ -42,7 +42,7 @@ final class SocketResponse extends ResponseAbstract implements RenderableInterfa
*/ */
public function setResponse(array $response) : void public function setResponse(array $response) : void
{ {
$this->response = $response; $this->data = $response;
} }
/** /**
@ -56,8 +56,8 @@ final class SocketResponse extends ResponseAbstract implements RenderableInterfa
*/ */
public function remove($id) : bool public function remove($id) : bool
{ {
if (isset($this->response[$id])) { if (isset($this->data[$id])) {
unset($this->response[$id]); unset($this->data[$id]);
return true; return true;
} }
@ -118,7 +118,7 @@ final class SocketResponse extends ResponseAbstract implements RenderableInterfa
{ {
$render = ''; $render = '';
foreach ($this->response as $key => $response) { foreach ($this->data as $key => $response) {
$render .= StringUtils::stringify($response); $render .= StringUtils::stringify($response);
} }
@ -157,7 +157,7 @@ final class SocketResponse extends ResponseAbstract implements RenderableInterfa
{ {
$result = []; $result = [];
foreach ($this->response as $response) { foreach ($this->data as $response) {
if ($response instanceof View) { if ($response instanceof View) {
$result[] = $response->toArray(); $result[] = $response->toArray();
} elseif (\is_array($response) || \is_scalar($response)) { } elseif (\is_array($response) || \is_scalar($response)) {

View File

@ -220,12 +220,12 @@ abstract class ModuleAbstract
) : void ) : void
{ {
$response->header->set('Content-Type', MimeType::M_JSON . '; charset=utf-8', true); $response->header->set('Content-Type', MimeType::M_JSON . '; charset=utf-8', true);
$response->set($request->uri->__toString(), [ $response->data[$request->uri->__toString()] = [
'status' => $status, 'status' => $status,
'title' => $title, 'title' => $title,
'message' => $message, 'message' => $message,
'response' => $obj, 'response' => $obj,
]); ];
} }
/** /**
@ -246,12 +246,12 @@ abstract class ModuleAbstract
) : void ) : void
{ {
$response->header->set('Content-Type', MimeType::M_JSON . '; charset=utf-8', true); $response->header->set('Content-Type', MimeType::M_JSON . '; charset=utf-8', true);
$response->set($request->uri->__toString(), [ $response->data[$request->uri->__toString()] = [
'status' => NotificationLevel::OK, 'status' => NotificationLevel::OK,
'title' => '', 'title' => '',
'message' => $this->app->l11nManager->getText($response->getLanguage(), '0', '0', 'SuccessfulCreate'), 'message' => $this->app->l11nManager->getText($response->getLanguage(), '0', '0', 'SuccessfulCreate'),
'response' => $obj, 'response' => $obj,
]); ];
} }
/** /**
@ -272,12 +272,12 @@ abstract class ModuleAbstract
) : void ) : void
{ {
$response->header->set('Content-Type', MimeType::M_JSON . '; charset=utf-8', true); $response->header->set('Content-Type', MimeType::M_JSON . '; charset=utf-8', true);
$response->set($request->uri->__toString(), [ $response->data[$request->uri->__toString()] = [
'status' => NotificationLevel::OK, 'status' => NotificationLevel::OK,
'title' => '', 'title' => '',
'message' => $this->app->l11nManager->getText($response->getLanguage(), '0', '0', 'SuccessfulUpdate'), 'message' => $this->app->l11nManager->getText($response->getLanguage(), '0', '0', 'SuccessfulUpdate'),
'response' => $obj, 'response' => $obj,
]); ];
} }
/** /**
@ -298,12 +298,12 @@ abstract class ModuleAbstract
) : void ) : void
{ {
$response->header->set('Content-Type', MimeType::M_JSON . '; charset=utf-8', true); $response->header->set('Content-Type', MimeType::M_JSON . '; charset=utf-8', true);
$response->set($request->uri->__toString(), [ $response->data[$request->uri->__toString()] = [
'status' => NotificationLevel::OK, 'status' => NotificationLevel::OK,
'title' => '', 'title' => '',
'message' => $this->app->l11nManager->getText($response->getLanguage(), '0', '0', 'SuccessfulDelete'), 'message' => $this->app->l11nManager->getText($response->getLanguage(), '0', '0', 'SuccessfulDelete'),
'response' => $obj, 'response' => $obj,
]); ];
} }
/** /**
@ -324,12 +324,12 @@ abstract class ModuleAbstract
) : void ) : void
{ {
$response->header->set('Content-Type', MimeType::M_JSON . '; charset=utf-8', true); $response->header->set('Content-Type', MimeType::M_JSON . '; charset=utf-8', true);
$response->set($request->uri->__toString(), [ $response->data[$request->uri->__toString()] = [
'status' => NotificationLevel::OK, 'status' => NotificationLevel::OK,
'title' => '', 'title' => '',
'message' => $this->app->l11nManager->getText($response->getLanguage(), '0', '0', 'SuccessfulRemove'), 'message' => $this->app->l11nManager->getText($response->getLanguage(), '0', '0', 'SuccessfulRemove'),
'response' => $obj, 'response' => $obj,
]); ];
} }
/** /**
@ -350,12 +350,12 @@ abstract class ModuleAbstract
) : void ) : void
{ {
$response->header->set('Content-Type', MimeType::M_JSON . '; charset=utf-8', true); $response->header->set('Content-Type', MimeType::M_JSON . '; charset=utf-8', true);
$response->set($request->uri->__toString(), [ $response->data[$request->uri->__toString()] = [
'status' => NotificationLevel::OK, 'status' => NotificationLevel::OK,
'title' => '', 'title' => '',
'message' => $this->app->l11nManager->getText($response->getLanguage(), '0', '0', 'SuccessfulReturn'), 'message' => $this->app->l11nManager->getText($response->getLanguage(), '0', '0', 'SuccessfulReturn'),
'response' => $obj, 'response' => $obj,
]); ];
} }
/** /**
@ -376,12 +376,12 @@ abstract class ModuleAbstract
) : void ) : void
{ {
$response->header->set('Content-Type', MimeType::M_JSON . '; charset=utf-8', true); $response->header->set('Content-Type', MimeType::M_JSON . '; charset=utf-8', true);
$response->set($request->uri->__toString(), [ $response->data[$request->uri->__toString()] = [
'status' => NotificationLevel::OK, 'status' => NotificationLevel::OK,
'title' => '', 'title' => '',
'message' => $this->app->l11nManager->getText($response->getLanguage(), '0', '0', 'SuccessfulAdd'), 'message' => $this->app->l11nManager->getText($response->getLanguage(), '0', '0', 'SuccessfulAdd'),
'response' => $obj, 'response' => $obj,
]); ];
} }
/** /**
@ -402,12 +402,12 @@ abstract class ModuleAbstract
) : void ) : void
{ {
$response->header->set('Content-Type', MimeType::M_JSON . '; charset=utf-8', true); $response->header->set('Content-Type', MimeType::M_JSON . '; charset=utf-8', true);
$response->set($request->uri->__toString(), [ $response->data[$request->uri->__toString()] = [
'status' => NotificationLevel::WARNING, 'status' => NotificationLevel::WARNING,
'title' => '', 'title' => '',
'message' => $this->app->l11nManager->getText($response->getLanguage(), '0', '0', 'InvalidCreate'), 'message' => $this->app->l11nManager->getText($response->getLanguage(), '0', '0', 'InvalidCreate'),
'response' => $obj, 'response' => $obj,
]); ];
} }
/** /**
@ -428,12 +428,12 @@ abstract class ModuleAbstract
) : void ) : void
{ {
$response->header->set('Content-Type', MimeType::M_JSON . '; charset=utf-8', true); $response->header->set('Content-Type', MimeType::M_JSON . '; charset=utf-8', true);
$response->set($request->uri->__toString(), [ $response->data[$request->uri->__toString()] = [
'status' => NotificationLevel::WARNING, 'status' => NotificationLevel::WARNING,
'title' => '', 'title' => '',
'message' => $this->app->l11nManager->getText($response->getLanguage(), '0', '0', 'InvalidUpdate'), 'message' => $this->app->l11nManager->getText($response->getLanguage(), '0', '0', 'InvalidUpdate'),
'response' => $obj, 'response' => $obj,
]); ];
} }
/** /**
@ -454,12 +454,12 @@ abstract class ModuleAbstract
) : void ) : void
{ {
$response->header->set('Content-Type', MimeType::M_JSON . '; charset=utf-8', true); $response->header->set('Content-Type', MimeType::M_JSON . '; charset=utf-8', true);
$response->set($request->uri->__toString(), [ $response->data[$request->uri->__toString()] = [
'status' => NotificationLevel::WARNING, 'status' => NotificationLevel::WARNING,
'title' => '', 'title' => '',
'message' => $this->app->l11nManager->getText($response->getLanguage(), '0', '0', 'InvalidDelete'), 'message' => $this->app->l11nManager->getText($response->getLanguage(), '0', '0', 'InvalidDelete'),
'response' => $obj, 'response' => $obj,
]); ];
} }
/** /**
@ -480,12 +480,12 @@ abstract class ModuleAbstract
) : void ) : void
{ {
$response->header->set('Content-Type', MimeType::M_JSON . '; charset=utf-8', true); $response->header->set('Content-Type', MimeType::M_JSON . '; charset=utf-8', true);
$response->set($request->uri->__toString(), [ $response->data[$request->uri->__toString()] = [
'status' => NotificationLevel::WARNING, 'status' => NotificationLevel::WARNING,
'title' => '', 'title' => '',
'message' => $this->app->l11nManager->getText($response->getLanguage(), '0', '0', 'InvalidRemove'), 'message' => $this->app->l11nManager->getText($response->getLanguage(), '0', '0', 'InvalidRemove'),
'response' => $obj, 'response' => $obj,
]); ];
} }
/** /**
@ -506,12 +506,12 @@ abstract class ModuleAbstract
) : void ) : void
{ {
$response->header->set('Content-Type', MimeType::M_JSON . '; charset=utf-8', true); $response->header->set('Content-Type', MimeType::M_JSON . '; charset=utf-8', true);
$response->set($request->uri->__toString(), [ $response->data[$request->uri->__toString()] = [
'status' => NotificationLevel::WARNING, 'status' => NotificationLevel::WARNING,
'title' => '', 'title' => '',
'message' => $this->app->l11nManager->getText($response->getLanguage(), '0', '0', 'InvalidReturn'), 'message' => $this->app->l11nManager->getText($response->getLanguage(), '0', '0', 'InvalidReturn'),
'response' => $obj, 'response' => $obj,
]); ];
} }
/** /**
@ -532,12 +532,12 @@ abstract class ModuleAbstract
) : void ) : void
{ {
$response->header->set('Content-Type', MimeType::M_JSON . '; charset=utf-8', true); $response->header->set('Content-Type', MimeType::M_JSON . '; charset=utf-8', true);
$response->set($request->uri->__toString(), [ $response->data[$request->uri->__toString()] = [
'status' => NotificationLevel::WARNING, 'status' => NotificationLevel::WARNING,
'title' => '', 'title' => '',
'message' => $this->app->l11nManager->getText($response->getLanguage(), '0', '0', 'InvalidAdd'), 'message' => $this->app->l11nManager->getText($response->getLanguage(), '0', '0', 'InvalidAdd'),
'response' => $obj, 'response' => $obj,
]); ];
} }
/** /**
@ -558,12 +558,12 @@ abstract class ModuleAbstract
) : void ) : void
{ {
$response->header->set('Content-Type', MimeType::M_JSON . '; charset=utf-8', true); $response->header->set('Content-Type', MimeType::M_JSON . '; charset=utf-8', true);
$response->set($request->uri->__toString(), [ $response->data[$request->uri->__toString()] = [
'status' => NotificationLevel::WARNING, 'status' => NotificationLevel::WARNING,
'title' => '', 'title' => '',
'message' => $this->app->l11nManager->getText($response->getLanguage(), '0', '0', 'InvalidPermission'), 'message' => $this->app->l11nManager->getText($response->getLanguage(), '0', '0', 'InvalidPermission'),
'response' => $obj, 'response' => $obj,
]); ];
} }
/** /**
@ -580,7 +580,7 @@ abstract class ModuleAbstract
protected function fillJsonRawResponse(RequestAbstract $request, ResponseAbstract $response, mixed $obj) : void protected function fillJsonRawResponse(RequestAbstract $request, ResponseAbstract $response, mixed $obj) : void
{ {
$response->header->set('Content-Type', MimeType::M_JSON . '; charset=utf-8', true); $response->header->set('Content-Type', MimeType::M_JSON . '; charset=utf-8', true);
$response->set($request->uri->__toString(), $obj); $response->data[$request->uri->__toString()] = $obj);
} }
/** /**