Skip to content

Commit

Permalink
Sync property and method names.
Browse files Browse the repository at this point in the history
Renamed View::$view and View::$viewPath to match the names used in ViewBuilder.
  • Loading branch information
ADmad committed Aug 16, 2015
1 parent 53e49e9 commit 64c471d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/View/Cell.php
Expand Up @@ -173,7 +173,7 @@ public function render($template = null)
$render = function () use ($template) {
$className = substr(strrchr(get_class($this), "\\"), 1);
$name = substr($className, 0, -4);
$this->View->viewPath('Cell' . DS . $name);
$this->View->templatePath('Cell' . DS . $name);

try {
return $this->View->render($template);
Expand Down
65 changes: 46 additions & 19 deletions src/View/View.php
Expand Up @@ -111,19 +111,19 @@ class View implements EventDispatcherInterface
public $helpers = [];

/**
* The name of the views subfolder containing views for this View.
* The name of the subfolder containing templates for this View.
*
* @var string
*/
public $viewPath = null;
public $templatePath = null;

/**
* The name of the view file to render. The name specified
* The name of the template file to render. The name specified
* is the filename in /app/Template/<SubFolder> without the .ctp extension.
*
* @var string
*/
public $view = null;
public $template = null;

/**
* The name of the layout file to render the view inside of. The name specified
Expand Down Expand Up @@ -339,18 +339,18 @@ public function initialize()
}

/**
* Get/set path for view files.
* Get/set path for templates files.
*
* @param string $path Path for view files. If null returns current path.
* @param string $path Path for template files. If null returns current path.
* @return string|void
*/
public function viewPath($path = null)
public function templatePath($path = null)
{
if ($path === null) {
return $this->viewPath;
return $this->templatePath;
}

$this->viewPath = $path;
$this->templatePath = $path;
}

/**
Expand Down Expand Up @@ -401,19 +401,19 @@ public function theme($theme = null)
}

/**
* Get/set the name of the view file to render. The name specified is the
* Get/set the name of the template file to render. The name specified is the
* filename in /app/Template/<SubFolder> without the .ctp extension.
*
* @param string $name View file name to set. If null returns current name.
* @param string $name Template file name to set. If null returns current name.
* @return string|void
*/
public function view($name = null)
public function template($name = null)
{
if ($name === null) {
return $this->view;
return $this->template;
}

$this->view = $name;
$this->template = $name;
}

/**
Expand Down Expand Up @@ -598,7 +598,7 @@ public function renderLayout($content, $layout = null)

$title = $this->Blocks->get('title');
if ($title === '') {
$title = Inflector::humanize($this->viewPath);
$title = Inflector::humanize($this->templatePath);
$this->Blocks->set('title', $title);
}

Expand Down Expand Up @@ -837,6 +837,13 @@ public function getCurrentType()
*/
public function __get($name)
{
if ($name === 'view') {
return $this->template;
}
if ($name === 'viewPath') {
return $this->templatePath;
}

$registry = $this->helpers();
if (isset($registry->{$name})) {
$this->{$name} = $registry->{$name};
Expand All @@ -845,6 +852,26 @@ public function __get($name)
return $this->{$name};
}

/**
* Magic setter for deprecated properties.
*
* @param string $name Name to property.
* @param mixed $value Value for property.
*/
public function __set($name, $value)
{
if ($name === 'view') {
$this->template = $value;
return;
}
if ($name === 'viewPath') {
$this->templatePath = $value;
return;
}

$this->{$name} = $value;
}

/**
* Interact with the HelperRegistry to load all the helpers.
*
Expand Down Expand Up @@ -971,12 +998,12 @@ protected function _getViewFileName($name = null)
if ($this->subDir !== null) {
$subDir = $this->subDir . DS;
}
if ($this->viewPath) {
$viewPath = $this->viewPath . DS;
if ($this->templatePath) {
$viewPath = $this->templatePath . DS;
}

if ($name === null) {
$name = $this->view;
$name = $this->template;
}

list($plugin, $name) = $this->pluginSplit($name);
Expand All @@ -990,7 +1017,7 @@ protected function _getViewFileName($name = null)
return $name;
}
$name = trim($name, DS);
} elseif (!$plugin || $this->viewPath !== $this->name) {
} elseif (!$plugin || $this->templatePath !== $this->name) {
$name = $viewPath . $subDir . $name;
} else {
$name = DS . $subDir . $name;
Expand Down

0 comments on commit 64c471d

Please sign in to comment.