Skip to content

Commit

Permalink
Presenter::$layout can be either string or null
Browse files Browse the repository at this point in the history
  • Loading branch information
mabar committed Sep 19, 2019
1 parent 67f45fb commit cb6c914
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/Application/UI/Presenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @property-read Nette\Application\Request $request
* @property-read string $action
* @property string $view
* @property string|bool $layout
* @property string|null $layout
* @property-read \stdClass $payload
* @property-read Nette\DI\Container $context
* @property-read Nette\Http\Session $session
Expand Down Expand Up @@ -84,8 +84,8 @@ abstract class Presenter extends Control implements Application\IPresenter
/** @var string */
private $view;

/** @var string|bool */
private $layout;
/** @var string|null */
private $layout = 'layout';

/** @var \stdClass */
private $payload;
Expand Down Expand Up @@ -426,22 +426,25 @@ public function setView(string $view)

/**
* Returns current layout name.
* @return string|bool
*/
final public function getLayout()
final public function getLayout(): ?string
{
return $this->layout;
}


/**
* Changes or disables layout.
* @param string|bool $layout
* @param string|null $layout
* @return static
*/
public function setLayout($layout)
{
$this->layout = $layout === false ? false : (string) $layout;
if (!is_string($layout) && $layout !== null) {
trigger_error(__METHOD__ . '() parameter $layout accepts only string|null, passing other values is deprecated.', E_USER_DEPRECATED);
}

$this->layout = $layout === false || $layout === null ? null : (string) $layout;
return $this;
}

Expand Down Expand Up @@ -478,7 +481,7 @@ public function sendTemplate(): void
*/
public function findLayoutTemplateFile(): ?string
{
if ($this->layout === false) {
if ($this->layout === null) {
return null;
}
$files = $this->formatLayoutTemplateFiles();
Expand All @@ -488,7 +491,7 @@ public function findLayoutTemplateFile(): ?string
}
}

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

0 comments on commit cb6c914

Please sign in to comment.