Skip to content

Commit 9362d85

Browse files
committed
Presenter: returns VoidResponse when has no response
1 parent 94ec03c commit 9362d85

File tree

3 files changed

+53
-23
lines changed

3 files changed

+53
-23
lines changed

src/Application/MicroPresenter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function run(Application\Request $request)
100100
if ($response instanceof Application\UI\ITemplate) {
101101
return new Responses\TextResponse($response);
102102
} else {
103-
return $response;
103+
return $response ?: new Responses\VoidResponse;
104104
}
105105
}
106106

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the Nette Framework (https://nette.org)
5+
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
6+
*/
7+
8+
namespace Nette\Application\Responses;
9+
10+
use Nette;
11+
12+
13+
/**
14+
* No response.
15+
*/
16+
class VoidResponse implements Nette\Application\IResponse
17+
{
18+
use Nette\SmartObject;
19+
20+
/**
21+
* @return void
22+
*/
23+
public function send(Nette\Http\IRequest $httpRequest, Nette\Http\IResponse $httpResponse)
24+
{
25+
}
26+
27+
}

src/Application/UI/Presenter.php

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -222,33 +222,36 @@ public function run(Application\Request $request)
222222
}
223223

224224
} catch (Application\AbortException $e) {
225-
// continue with shutting down
226-
if ($this->isAjax()) {
227-
try {
228-
$hasPayload = (array) $this->payload;
229-
unset($hasPayload['state']);
230-
if ($this->response instanceof Responses\TextResponse && $this->isControlInvalid()) {
231-
$this->snippetMode = TRUE;
232-
$this->response->send($this->httpRequest, $this->httpResponse);
233-
$this->sendPayload();
234-
} elseif (!$this->response && $hasPayload) { // back compatibility for use terminate() instead of sendPayload()
235-
trigger_error('Use $presenter->sendPayload() instead of terminate() to send payload.');
236-
$this->sendPayload();
237-
}
238-
} catch (Application\AbortException $e) {
239-
}
240-
}
225+
}
241226

242-
if ($this->hasFlashSession()) {
243-
$this->getFlashSession()->setExpiration($this->response instanceof Responses\RedirectResponse ? '+ 30 seconds' : '+ 3 seconds');
227+
if ($this->isAjax()) {
228+
try {
229+
$hasPayload = (array) $this->payload;
230+
unset($hasPayload['state']);
231+
if ($this->response instanceof Responses\TextResponse && $this->isControlInvalid()) {
232+
$this->snippetMode = TRUE;
233+
$this->response->send($this->httpRequest, $this->httpResponse);
234+
$this->sendPayload();
235+
} elseif (!$this->response && $hasPayload) { // back compatibility for use terminate() instead of sendPayload()
236+
trigger_error('Use $presenter->sendPayload() instead of terminate() to send payload.');
237+
$this->sendPayload();
238+
}
239+
} catch (Application\AbortException $e) {
244240
}
241+
}
245242

246-
// SHUTDOWN
247-
$this->onShutdown($this, $this->response);
248-
$this->shutdown($this->response);
243+
if ($this->hasFlashSession()) {
244+
$this->getFlashSession()->setExpiration($this->response instanceof Responses\RedirectResponse ? '+ 30 seconds' : '+ 3 seconds');
245+
}
249246

250-
return $this->response;
247+
if (!$this->response) {
248+
$this->response = new Responses\VoidResponse;
251249
}
250+
251+
$this->onShutdown($this, $this->response);
252+
$this->shutdown($this->response);
253+
254+
return $this->response;
252255
}
253256

254257

0 commit comments

Comments
 (0)