Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Presenter::$layout can be either string or null #233

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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