Browse Source

Merge pull request #3936 from ADmad/3.0-view-cleanup

Cleanup deprecated code.
Mark Story 11 years ago
parent
commit
c2e2fa6176
3 changed files with 12 additions and 116 deletions
  1. 9 81
      src/View/View.php
  2. 0 1
      tests/TestCase/Utility/DebuggerTest.php
  3. 3 34
      tests/TestCase/View/ViewTest.php

+ 9 - 81
src/View/View.php

@@ -40,12 +40,11 @@ use Cake\View\ViewVarsTrait;
  * 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;
@@ -252,13 +250,6 @@ class View {
 	);
 
 /**
- * Scripts (and/or other <head /> tags) for the layout.
- *
- * @var array
- */
-	protected $_scripts = array();
-
-/**
  * Holds an array of paths.
  *
  * @var array
@@ -465,21 +456,6 @@ class View {
  * 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 @@ class View {
 		}
 		$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));
@@ -565,17 +528,6 @@ class View {
 	}
 
 /**
- * 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.
  *
  * @param string $var The view var you want the contents of.
@@ -766,30 +718,6 @@ class View {
 	}
 
 /**
- * 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.
  *
  * @return void

+ 0 - 1
tests/TestCase/Utility/DebuggerTest.php

@@ -362,7 +362,6 @@ object(Cake\View\View) {
 		(int) 10 => 'passedArgs',
 		(int) 11 => 'cacheAction'
 	]
-	[protected] _scripts => []
 	[protected] _paths => []
 	[protected] _pathsForPlugin => []
 	[protected] _parents => []

+ 3 - 34
tests/TestCase/View/ViewTest.php

@@ -95,34 +95,6 @@ class ThemePostsController extends Controller {
 }
 
 /**
- * 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 @@ class ViewTest extends TestCase {
 		$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 @@ class ViewTest extends TestCase {
 		$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 @@ class ViewTest extends TestCase {
 			'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 @@ class ViewTest extends TestCase {
 		$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');