Skip to content

Commit

Permalink
Presenter: $payload access refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Mar 6, 2024
1 parent a331edc commit 587f7a0
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/Application/UI/Presenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ abstract class Presenter extends Control implements Application\IPresenter

public function __construct()
{
$this->payload = new \stdClass;
}


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

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

if ($this->isAjax()) {
$this->payload->state = $this->getGlobalState();
$this->getPayload()->state = $this->getGlobalState();
try {
if ($this->response instanceof Responses\TextResponse && $this->isControlInvalid()) {
$this->snippetMode = true;
Expand Down Expand Up @@ -570,7 +568,7 @@ public function formatTemplateClass(): ?string

final public function getPayload(): \stdClass
{
return $this->payload;
return $this->payload ??= new \stdClass;
}


Expand All @@ -594,7 +592,7 @@ public function isAjax(): bool
*/
public function sendPayload(): void
{
$this->sendResponse(new Responses\JsonResponse($this->payload));
$this->sendResponse(new Responses\JsonResponse($this->getPayload()));
}


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

} elseif (!$httpCode) {
Expand Down

0 comments on commit 587f7a0

Please sign in to comment.