Skip to content

Commit 3316126

Browse files
committed
Presenter: $payload access refactoring
1 parent d16847f commit 3316126

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/Application/UI/Presenter.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ abstract class Presenter extends Control implements Application\IPresenter
116116

117117
public function __construct()
118118
{
119-
$this->payload = new \stdClass;
120119
}
121120

122121

@@ -170,7 +169,6 @@ public function isModuleCurrent(string $module): bool
170169
public function run(Application\Request $request): Application\Response
171170
{
172171
$this->request = $request;
173-
$this->payload ??= new \stdClass;
174172
$this->setParent($this->getParent(), $request->getPresenterName());
175173

176174
if (!$this->httpResponse->isSent()) {
@@ -227,7 +225,7 @@ public function run(Application\Request $request): Application\Response
227225
$this->saveGlobalState();
228226

229227
if ($this->isAjax()) {
230-
$this->payload->state = $this->getGlobalState();
228+
$this->getPayload()->state = $this->getGlobalState();
231229
try {
232230
if ($this->response instanceof Responses\TextResponse && $this->isControlInvalid()) {
233231
$this->snippetMode = true;
@@ -570,7 +568,7 @@ public function formatTemplateClass(): ?string
570568

571569
final public function getPayload(): \stdClass
572570
{
573-
return $this->payload;
571+
return $this->payload ??= new \stdClass;
574572
}
575573

576574

@@ -594,7 +592,7 @@ public function isAjax(): bool
594592
*/
595593
public function sendPayload(): void
596594
{
597-
$this->sendResponse(new Responses\JsonResponse($this->payload));
595+
$this->sendResponse(new Responses\JsonResponse($this->getPayload()));
598596
}
599597

600598

@@ -663,7 +661,7 @@ public function forward(string|Nette\Application\Request $destination, $args = [
663661
public function redirectUrl(string $url, ?int $httpCode = null): void
664662
{
665663
if ($this->isAjax()) {
666-
$this->payload->redirect = $url;
664+
$this->getPayload()->redirect = $url;
667665
$this->sendPayload();
668666

669667
} elseif (!$httpCode) {

0 commit comments

Comments
 (0)