Skip to content
Permalink
Browse files

Cleanup deprecated code.

  • Loading branch information...
ADmad committed Jul 10, 2014
1 parent 2ae1fd9 commit 5e4abbed62da28f2f481e41b1100780ab19d462a
Showing with 12 additions and 115 deletions.
  1. +9 −81 src/View/View.php
  2. +3 −34 tests/TestCase/View/ViewTest.php
@@ -40,12 +40,11 @@
* and then inserted into the selected layout. This also means you can pass data from the view to the
* layout using `$this->set()`
*
* Since 2.1, the base View class also includes support for themes by default. Theme views are regular
* view files that can provide unique HTML and static assets. If theme views are not found for the
* current view the default app view files will be used. You can set `$this->theme = 'Mytheme'`
* in your Controller to use the Themes.
*
* Example of theme path with `$this->theme = 'SuperHot';` Would be `Plugin/SuperHot/Template/Posts`
* View class supports using plugins as themes. You can set
* `$this->theme = 'SuperHot'` in your Controller to use plugin `SuperHot` as a
* theme. Eg. If current action is Posts::index() then View class will look for
* template file `plugins/SuperHot/Template/Posts/index.ctp`. If a theme template
* is not found for the current action the default app template file is used.
*
* @property \Cake\View\Helper\CacheHelper $Cache
* @property \Cake\View\Helper\FormHelper $Form
@@ -69,21 +68,20 @@ class View {
/**
* Helpers collection
*
* @var Cake\View\HelperRegistry
* @var \Cake\View\HelperRegistry
*/
protected $_helpers;
/**
* ViewBlock instance.
*
* @var ViewBlock
* @var \Cake\View\ViewBlock
*/
public $Blocks;
/**
* The name of the plugin.
*
* @link http://manual.cakephp.org/chapter/plugins
* @var string
*/
public $plugin = null;
@@ -251,13 +249,6 @@ class View {
'layoutPath', 'viewPath', 'plugin', 'passedArgs', 'cacheAction'
);
/**
* Scripts (and/or other <head /> tags) for the layout.
*
* @var array
*/
protected $_scripts = array();
/**
* Holds an array of paths.
*
@@ -465,21 +456,6 @@ public function render($view = null, $layout = null) {
* Renders a layout. Returns output from _render(). Returns false on error.
* Several variables are created for use in layout.
*
* - `title_for_layout` - A backwards compatible place holder, you should set this value if you want more control.
* - `content_for_layout` - contains rendered view file
* - `scripts_for_layout` - Contains content added with addScript() as well as any content in
* the 'meta', 'css', and 'script' blocks. They are appended in that order.
*
* Deprecated features:
*
* - `$scripts_for_layout` is deprecated and will be removed in CakePHP 3.0.
* Use the block features instead. `meta`, `css` and `script` will be populated
* by the matching methods on HtmlHelper.
* - `$title_for_layout` is deprecated and will be removed in CakePHP 3.0.
* Use the `title` block instead.
* - `$content_for_layout` is deprecated and will be removed in CakePHP 3.0.
* Use the `content` block instead.
*
* @param string $content Content to render in a view, wrapped by the surrounding layout.
* @param string $layout Layout name
* @return mixed Rendered output, or false on error
@@ -498,24 +474,11 @@ public function renderLayout($content, $layout = null) {
}
$this->eventManager()->dispatch(new Event('View.beforeLayout', $this, array($layoutFileName)));
$scripts = implode("\n\t", $this->_scripts);
$scripts .= $this->Blocks->get('meta') . $this->Blocks->get('css') . $this->Blocks->get('script');
$this->viewVars = array_merge($this->viewVars, array(
'content_for_layout' => $content,
'scripts_for_layout' => $scripts,
));
$title = $this->Blocks->get('title');
if ($title === '') {
if (isset($this->viewVars['title_for_layout'])) {
$title = $this->viewVars['title_for_layout'];
} else {
$title = Inflector::humanize($this->viewPath);
}
$title = Inflector::humanize($this->viewPath);
$this->Blocks->set('title', $title);
}
$this->viewVars['title_for_layout'] = $title;
$this->Blocks->set('title', $title);
$this->_currentType = static::TYPE_LAYOUT;
$this->Blocks->set('content', $this->_render($layoutFileName));
@@ -564,17 +527,6 @@ public function getVars() {
return array_keys($this->viewVars);
}
/**
* Returns the contents of the given View variable(s)
*
* @param string $var The view var you want the contents of.
* @return mixed The content of the named var if its set, otherwise null.
* @deprecated Will be removed in 3.0. Use View::get() instead.
*/
public function getVar($var) {
return $this->get($var);
}
/**
* Returns the contents of the given View variable.
*
@@ -765,30 +717,6 @@ public function __get($name) {
return $this->{$name};
}
/**
* Magic accessor for deprecated attributes.
*
* @param string $name Name of the attribute to set.
* @param mixed $value Value of the attribute to set.
* @return void
*/
public function __set($name, $value) {
$this->{$name} = $value;
}
/**
* Magic isset check for deprecated attributes.
*
* @param string $name Name of the attribute to check.
* @return bool
*/
public function __isset($name) {
if (isset($this->{$name})) {
return true;
}
return false;
}
/**
* Interact with the HelperRegistry to load all the helpers.
*
@@ -94,34 +94,6 @@ public function index() {
}
/**
* TestThemeView class
*
*/
class TestThemeView extends View {
/**
* getViewFileName method
*
* @param string $name Controller action to find template filename for
* @return string Template filename
*/
public function getViewFileName($name = null) {
return $this->_getViewFileName($name);
}
/**
* getLayoutFileName method
*
* @param string $name The name of the layout to find.
* @return string Filename for layout file (.ctp).
*/
public function getLayoutFileName($name = null) {
return $this->_getLayoutFileName($name);
}
}
/**
* TestView class
*
@@ -360,7 +332,7 @@ public function testGetTemplate() {
$request->action = 'display';
$request->params['pass'] = array('home');
$ThemeView = new TestThemeView(null, null, null, $viewOptions);
$ThemeView = new TestView(null, null, null, $viewOptions);
$ThemeView->theme = 'TestTheme';
$expected = TEST_APP . 'TestApp' . DS . 'Template' . DS . 'Pages' . DS . 'home.ctp';
$result = $ThemeView->getViewFileName('home');
@@ -384,7 +356,7 @@ public function testGetTemplate() {
$result = $ThemeView->getLayoutFileName();
$this->assertPathEquals($expected, $result);
$ThemeView = new TestThemeView(null, null, null, $viewOptions);
$ThemeView = new TestView(null, null, null, $viewOptions);
$ThemeView->theme = 'Company/TestPluginThree';
$expected = Plugin::path('Company/TestPluginThree') . 'src' . DS . 'Template' . DS . 'Layout' . DS . 'default.ctp';
@@ -428,7 +400,7 @@ public function testPluginThemedGetTemplate() {
'theme' => 'TestTheme'
];
$ThemeView = new TestThemeView(null, null, null, $viewOptions);
$ThemeView = new TestView(null, null, null, $viewOptions);
$themePath = Plugin::path('TestTheme') . 'src' . DS . 'Template' . DS;
$expected = $themePath . 'Plugin' . DS . 'TestPlugin' . DS . 'Tests' . DS . 'index.ctp';
@@ -1044,9 +1016,6 @@ public function testRender() {
$this->assertRegExp("/<div id=\"content\">\s*posts index\s*<\/div>/", $result);
$this->assertRegExp("/<div id=\"content\">\s*posts index\s*<\/div>/", $result);
$this->assertTrue(isset($View->viewVars['content_for_layout']), 'content_for_layout should be a view var');
$this->assertTrue(isset($View->viewVars['scripts_for_layout']), 'scripts_for_layout should be a view var');
$View = $this->PostsController->createView('Cake\Test\TestCase\View\TestView');
$result = $View->render(false, 'ajax2');

0 comments on commit 5e4abbe

Please sign in to comment.
You can’t perform that action at this time.