Skip to content

Commit

Permalink
Make View's setter methods return $this instead of void.
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Aug 31, 2017
1 parent 6cf6544 commit 05dfa2f
Showing 1 changed file with 42 additions and 14 deletions.
56 changes: 42 additions & 14 deletions src/View/View.php
Expand Up @@ -392,11 +392,13 @@ public function getTemplatePath()
* Set path for templates files.
*
* @param string $path Path for template files.
* @return void
* @return $this
*/
public function setTemplatePath($path)
{
$this->templatePath = $path;

return $this;
}

/**
Expand Down Expand Up @@ -429,11 +431,13 @@ public function getLayoutPath()
* Set path for layout files.
*
* @param string $path Path for layout files.
* @return void
* @return $this
*/
public function setLayoutPath($path)
{
$this->layoutPath = $path;

return $this;
}

/**
Expand Down Expand Up @@ -469,11 +473,13 @@ public function isAutoLayoutEnabled()
* automatically applied to rendered views.
*
* @param bool $enable Boolean to turn on/off.
* @return void
* @return $this
*/
public function enableAutoLayout($enable = true)
{
$this->autoLayout = (bool)$enable;

return $this;
}

/**
Expand Down Expand Up @@ -508,11 +514,13 @@ public function getTheme()
* Set the view theme to use.
*
* @param string|null $theme Theme name.
* @return void
* @return $this
*/
public function setTheme($theme)
{
$this->theme = $theme;

return $this;
}

/**
Expand Down Expand Up @@ -547,11 +555,13 @@ public function getTemplate()
* filename in /src/Template/<SubFolder> without the .ctp extension.
*
* @param string $name Template file name to set.
* @return void
* @return $this
*/
public function setTemplate($name)
{
$this->template = $name;

return $this;
}

/**
Expand Down Expand Up @@ -589,11 +599,13 @@ public function getLayout()
* without the .ctp extension.
*
* @param string $name Layout file name to set.
* @return void
* @return $this
*/
public function setLayout($name)
{
$this->layout = $name;

return $this;
}

/**
Expand Down Expand Up @@ -862,12 +874,14 @@ public function blocks()
* ```
*
* @param string $name The name of the block to capture for.
* @return void
* @return $this
* @see \Cake\View\ViewBlock::start()
*/
public function start($name)
{
$this->Blocks->start($name);

return $this;
}

/**
Expand All @@ -878,12 +892,14 @@ public function start($name)
* @param string $name Name of the block
* @param mixed $value The content for the block. Value will be type cast
* to string.
* @return void
* @return $this
* @see \Cake\View\ViewBlock::concat()
*/
public function append($name, $value = null)
{
$this->Blocks->concat($name, $value);

return $this;
}

/**
Expand All @@ -894,12 +910,14 @@ public function append($name, $value = null)
* @param string $name Name of the block
* @param mixed $value The content for the block. Value will be type cast
* to string.
* @return void
* @return $this
* @see \Cake\View\ViewBlock::concat()
*/
public function prepend($name, $value)
{
$this->Blocks->concat($name, $value, ViewBlock::PREPEND);

return $this;
}

/**
Expand All @@ -909,25 +927,29 @@ public function prepend($name, $value)
* @param string $name Name of the block
* @param mixed $value The content for the block. Value will be type cast
* to string.
* @return void
* @return $this
* @see \Cake\View\ViewBlock::set()
*/
public function assign($name, $value)
{
$this->Blocks->set($name, $value);

return $this;
}

/**
* Reset the content for a block. This will overwrite any
* existing content.
*
* @param string $name Name of the block
* @return void
* @return $this
* @see \Cake\View\ViewBlock::set()
*/
public function reset($name)
{
$this->assign($name, '');

return $this;
}

/**
Expand All @@ -947,12 +969,14 @@ public function fetch($name, $default = '')
/**
* End a capturing block. The compliment to View::start()
*
* @return void
* @return $this
* @see \Cake\View\ViewBlock::end()
*/
public function end()
{
$this->Blocks->end();

return $this;
}

/**
Expand All @@ -972,7 +996,7 @@ public function exists($name)
* parent view and populate blocks in the parent template.
*
* @param string $name The template or element to 'extend' the current one with.
* @return void
* @return $this
* @throws \LogicException when you extend a template with itself or make extend loops.
* @throws \LogicException when you extend an element which doesn't exist
*/
Expand Down Expand Up @@ -1009,6 +1033,8 @@ public function extend($name)
throw new LogicException('You cannot have views extend in a loop.');
}
$this->_parents[$this->_current] = $parent;

return $this;
}

/**
Expand Down Expand Up @@ -1093,7 +1119,7 @@ public function __set($name, $value)
/**
* Interact with the HelperRegistry to load all the helpers.
*
* @return void
* @return $this
*/
public function loadHelpers()
{
Expand All @@ -1102,6 +1128,8 @@ public function loadHelpers()
foreach ($helpers as $properties) {
$this->loadHelper($properties['class'], $properties['config']);
}

return $this;
}

/**
Expand Down

0 comments on commit 05dfa2f

Please sign in to comment.