Skip to content

Commit

Permalink
Presenter::run() saves global state on sendRequest()
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Oct 6, 2021
1 parent 0bf1415 commit db6eedc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
29 changes: 14 additions & 15 deletions src/Application/UI/Presenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,17 +192,18 @@ public function isModuleCurrent(string $module): bool

public function run(Application\Request $request): Application\Response
{
try {
// STARTUP
$this->request = $request;
$this->payload = $this->payload ?: new \stdClass;
$this->setParent($this->getParent(), $request->getPresenterName());
$this->request = $request;
$this->payload = $this->payload ?: new \stdClass;
$this->setParent($this->getParent(), $request->getPresenterName());

if (!$this->httpResponse->isSent()) {
$this->httpResponse->addHeader('Vary', 'X-Requested-With');
}
if (!$this->httpResponse->isSent()) {
$this->httpResponse->addHeader('Vary', 'X-Requested-With');
}

$this->initGlobalParameters();

$this->initGlobalParameters();
try {
// STARTUP
$this->checkRequirements(static::getReflection());
Arrays::invoke($this->onStartup, $this);
$this->startup();
Expand Down Expand Up @@ -236,19 +237,17 @@ public function run(Application\Request $request): Application\Response
$this->tryCall(static::formatRenderMethod($this->view), $this->params);
$this->afterRender();

// save component tree persistent state
$this->saveGlobalState();
if ($this->isAjax()) {
$this->payload->state = $this->getGlobalState();
}

// finish template rendering
$this->sendTemplate();

} catch (Application\AbortException $e) {
}

// save component tree persistent state
$this->saveGlobalState();

if ($this->isAjax()) {
$this->payload->state = $this->getGlobalState();
try {
if ($this->response instanceof Responses\TextResponse && $this->isControlInvalid()) {
$this->snippetMode = true;
Expand Down
6 changes: 4 additions & 2 deletions tests/UI/Component.isLinkCurrent().asserts.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ function callIsComponentLinkCurrent(
new Http\Request($url),
new Http\Response
);
$presenter->onStartup[] = function () use (&$res, $component, $destination, $args) {
$res = $component->isLinkCurrent($destination, $args);
};
$presenter->run($request);

return $component->isLinkCurrent($destination, $args);
return $res;
}


Expand Down

0 comments on commit db6eedc

Please sign in to comment.