Skip to content

Commit cb6c914

Browse files
committed
Presenter::$layout can be either string or null
1 parent 67f45fb commit cb6c914

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/Application/UI/Presenter.php

+13-10
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* @property-read Nette\Application\Request $request
2323
* @property-read string $action
2424
* @property string $view
25-
* @property string|bool $layout
25+
* @property string|null $layout
2626
* @property-read \stdClass $payload
2727
* @property-read Nette\DI\Container $context
2828
* @property-read Nette\Http\Session $session
@@ -84,8 +84,8 @@ abstract class Presenter extends Control implements Application\IPresenter
8484
/** @var string */
8585
private $view;
8686

87-
/** @var string|bool */
88-
private $layout;
87+
/** @var string|null */
88+
private $layout = 'layout';
8989

9090
/** @var \stdClass */
9191
private $payload;
@@ -426,22 +426,25 @@ public function setView(string $view)
426426

427427
/**
428428
* Returns current layout name.
429-
* @return string|bool
430429
*/
431-
final public function getLayout()
430+
final public function getLayout(): ?string
432431
{
433432
return $this->layout;
434433
}
435434

436435

437436
/**
438437
* Changes or disables layout.
439-
* @param string|bool $layout
438+
* @param string|null $layout
440439
* @return static
441440
*/
442441
public function setLayout($layout)
443442
{
444-
$this->layout = $layout === false ? false : (string) $layout;
443+
if (!is_string($layout) && $layout !== null) {
444+
trigger_error(__METHOD__ . '() parameter $layout accepts only string|null, passing other values is deprecated.', E_USER_DEPRECATED);
445+
}
446+
447+
$this->layout = $layout === false || $layout === null ? null : (string) $layout;
445448
return $this;
446449
}
447450

@@ -478,7 +481,7 @@ public function sendTemplate(): void
478481
*/
479482
public function findLayoutTemplateFile(): ?string
480483
{
481-
if ($this->layout === false) {
484+
if ($this->layout === null) {
482485
return null;
483486
}
484487
$files = $this->formatLayoutTemplateFiles();
@@ -488,7 +491,7 @@ public function findLayoutTemplateFile(): ?string
488491
}
489492
}
490493

491-
if ($this->layout) {
494+
if ($this->layout !== null) {
492495
$file = strtr(reset($files), '/', DIRECTORY_SEPARATOR);
493496
throw new Nette\FileNotFoundException("Layout not found. Missing template '$file'.");
494497
}
@@ -501,7 +504,7 @@ public function findLayoutTemplateFile(): ?string
501504
*/
502505
public function formatLayoutTemplateFiles(): array
503506
{
504-
if (preg_match('#/|\\\\#', (string) $this->layout)) {
507+
if ($this->layout !== null && preg_match('#/|\\\\#', $this->layout)) {
505508
return [$this->layout];
506509
}
507510
[$module, $presenter] = Helpers::splitName($this->getName());

0 commit comments

Comments
 (0)