Browse Source

Move View\Error to View\Exception.

ADmad 11 years ago
parent
commit
c1b5187c8b

+ 1 - 1
src/Error/ExceptionRenderer.php

@@ -25,7 +25,7 @@ use Cake\Network\Request;
 use Cake\Network\Response;
 use Cake\Routing\Router;
 use Cake\Utility\Inflector;
-use Cake\View\Error\MissingViewException;
+use Cake\View\Exception\MissingViewException;
 use Exception;
 
 /**

+ 3 - 3
src/View/Cell.php

@@ -20,8 +20,8 @@ use Cake\Model\ModelAwareTrait;
 use Cake\Network\Request;
 use Cake\Network\Response;
 use Cake\Utility\Inflector;
-use Cake\View\Error\MissingCellViewException;
-use Cake\View\Error\MissingViewException;
+use Cake\View\Exception\MissingCellViewException;
+use Cake\View\Exception\MissingViewException;
 use Cake\View\ViewVarsTrait;
 
 /**
@@ -143,7 +143,7 @@ abstract class Cell {
  * @param string $template Custom template name to render. If not provided (null), the last
  * value will be used. This value is automatically set by `CellTrait::cell()`.
  * @return void
- * @throws \Cake\View\Error\MissingCellViewException When a MissingViewException is raised during rendering.
+ * @throws \Cake\View\Exception\MissingCellViewException When a MissingViewException is raised during rendering.
  */
 	public function render($template = null) {
 		if ($template !== null && strpos($template, '/') === false) {

+ 2 - 2
src/View/CellTrait.php

@@ -52,7 +52,7 @@ trait CellTrait {
  *    `cell('TagCloud::smallList', ['a1' => 'v1', 'a2' => 'v2'])` maps to `View\Cell\TagCloud::smallList(v1, v2)`
  * @param array $options Options for Cell's constructor
  * @return \Cake\View\Cell The cell instance
- * @throws \Cake\View\Error\MissingCellException If Cell class was not found.
+ * @throws \Cake\View\Exception\MissingCellException If Cell class was not found.
  * @throws \BadMethodCallException If Cell class does not specified cell action.
  */
 	public function cell($cell, array $data = [], array $options = []) {
@@ -68,7 +68,7 @@ trait CellTrait {
 		$className = App::className($pluginAndCell, 'View/Cell', 'Cell');
 
 		if (!$className) {
-			throw new Error\MissingCellException(array('className' => $pluginAndCell . 'Cell'));
+			throw new Exception\MissingCellException(array('className' => $pluginAndCell . 'Cell'));
 		}
 
 		$cell = $this->_createCell($className, $action, $plugin, $options);

+ 1 - 1
src/View/Error/MissingCellException.php

@@ -12,7 +12,7 @@
  * @since         3.0.0
  * @license       http://www.opensource.org/licenses/mit-license.php MIT License
  */
-namespace Cake\View\Error;
+namespace Cake\View\Exception;
 
 use Cake\Core\Exception\Exception;
 

+ 1 - 1
src/View/Error/MissingCellViewException.php

@@ -11,7 +11,7 @@
  * @since         3.0.0
  * @license       http://www.opensource.org/licenses/mit-license.php MIT License
  */
-namespace Cake\View\Error;
+namespace Cake\View\Exception;
 
 use Cake\Core\Exception\Exception;
 

+ 1 - 1
src/View/Error/MissingElementException.php

@@ -11,7 +11,7 @@
  * @since         3.0.0
  * @license       http://www.opensource.org/licenses/mit-license.php MIT License
  */
-namespace Cake\View\Error;
+namespace Cake\View\Exception;
 
 use Cake\Core\Exception\Exception;
 

+ 1 - 1
src/View/Error/MissingHelperException.php

@@ -11,7 +11,7 @@
  * @since         3.0.0
  * @license       http://www.opensource.org/licenses/mit-license.php MIT License
  */
-namespace Cake\View\Error;
+namespace Cake\View\Exception;
 
 use Cake\Core\Exception\Exception;
 

+ 1 - 1
src/View/Error/MissingLayoutException.php

@@ -11,7 +11,7 @@
  * @since         3.0.0
  * @license       http://www.opensource.org/licenses/mit-license.php MIT License
  */
-namespace Cake\View\Error;
+namespace Cake\View\Exception;
 
 use Cake\Core\Exception\Exception;
 

+ 1 - 1
src/View/Error/MissingViewException.php

@@ -11,7 +11,7 @@
  * @since         3.0.0
  * @license       http://www.opensource.org/licenses/mit-license.php MIT License
  */
-namespace Cake\View\Error;
+namespace Cake\View\Exception;
 
 use Cake\Core\Exception\Exception;
 

+ 4 - 4
src/View/HelperRegistry.php

@@ -15,8 +15,8 @@
 namespace Cake\View;
 
 use Cake\Core\App;
-use Cake\Event\EventManagerTrait;
 use Cake\Core\ObjectRegistry;
+use Cake\Event\EventManagerTrait;
 use Cake\View\View;
 
 /**
@@ -51,7 +51,7 @@ class HelperRegistry extends ObjectRegistry {
  *
  * @param string $helper The helper name to be loaded
  * @return bool whether the helper could be loaded or not
- * @throws \Cake\View\Error\MissingHelperException When a helper could not be found.
+ * @throws \Cake\View\Exception\MissingHelperException When a helper could not be found.
  *    App helpers are searched, and then plugin helpers.
  */
 	public function __isset($helper) {
@@ -111,10 +111,10 @@ class HelperRegistry extends ObjectRegistry {
  * @param string $class The classname that is missing.
  * @param string $plugin The plugin the helper is missing in.
  * @return void
- * @throws \Cake\View\Error\MissingHelperException
+ * @throws \Cake\View\Exception\MissingHelperException
  */
 	protected function _throwMissingClassError($class, $plugin) {
-		throw new Error\MissingHelperException([
+		throw new Exception\MissingHelperException([
 			'class' => $class . 'Helper',
 			'plugin' => $plugin
 		]);

+ 17 - 13
src/View/View.php

@@ -18,7 +18,6 @@ use Cake\Cache\Cache;
 use Cake\Core\App;
 use Cake\Core\Configure;
 use Cake\Core\Plugin;
-use Cake\Core\Exception\Exception;
 use Cake\Event\Event;
 use Cake\Event\EventManager;
 use Cake\Event\EventManagerTrait;
@@ -30,6 +29,8 @@ use Cake\Routing\Router;
 use Cake\Utility\Inflector;
 use Cake\View\CellTrait;
 use Cake\View\ViewVarsTrait;
+use InvalidArgumentException;
+use LogicException;
 
 /**
  * View, the V in the MVC triad. View interacts with Helpers and view variables passed
@@ -344,7 +345,7 @@ class View {
  *   Defaults to false.
  * - `ignoreMissing` - Used to allow missing elements. Set to true to not throw exceptions.
  * @return string Rendered Element
- * @throws \Cake\View\Error\MissingElementException When an element is missing and `ignoreMissing`
+ * @throws \Cake\View\Exception\MissingElementException When an element is missing and `ignoreMissing`
  *   is false.
  */
 	public function element($name, array $data = array(), array $options = array()) {
@@ -370,7 +371,7 @@ class View {
 			list ($plugin, $name) = pluginSplit($name, true);
 			$name = str_replace('/', DS, $name);
 			$file = $plugin . 'Element' . DS . $name . $this->_ext;
-			throw new Error\MissingElementException($file);
+			throw new Exception\MissingElementException($file);
 		}
 	}
 
@@ -683,9 +684,10 @@ class View {
  * array of data. Handles parent/extended views.
  *
  * @param string $viewFile Filename of the view
- * @param array $data Data to include in rendered view. If empty the current View::$viewVars will be used.
+ * @param array $data Data to include in rendered view. If empty the current
+ *   View::$viewVars will be used.
  * @return string Rendered output
- * @throws \Cake\Core\Exception\Exception when a block is left open.
+ * @throws \LogicException When a block is left open.
  */
 	protected function _render($viewFile, $data = array()) {
 		if (empty($data)) {
@@ -717,7 +719,7 @@ class View {
 		$remainingBlocks = count($this->Blocks->unclosed());
 
 		if ($initialBlocks !== $remainingBlocks) {
-			throw new Exception(sprintf(
+			throw new LogicException(sprintf(
 				'The "%s" block was left open. Blocks are not allowed to cross files.',
 				$this->Blocks->active()
 			));
@@ -774,7 +776,7 @@ class View {
  *
  * @param string $name Controller action to find template filename for
  * @return string Template filename
- * @throws \Cake\View\Error\MissingViewException when a view file could not be found.
+ * @throws \Cake\View\Exception\MissingViewException when a view file could not be found.
  */
 	protected function _getViewFileName($name = null) {
 		$subDir = null;
@@ -809,7 +811,7 @@ class View {
 				return $this->_checkFilePath($path . $name . $this->_ext, $path);
 			}
 		}
-		throw new Error\MissingViewException(array('file' => $name . $this->_ext));
+		throw new Exception\MissingViewException(array('file' => $name . $this->_ext));
 	}
 
 /**
@@ -821,7 +823,7 @@ class View {
  * @param string $file The path to the template file.
  * @param string $path Base path that $file should be inside of.
  * @return string The file path
- * @throws \Cake\Core\Exception\Exception
+ * @throws \InvalidArgumentException
  */
 	protected function _checkFilePath($file, $path) {
 		if (strpos($file, '..') === false) {
@@ -829,8 +831,10 @@ class View {
 		}
 		$absolute = realpath($file);
 		if (strpos($absolute, $path) !== 0) {
-			$msg = sprintf('Cannot use "%s" as a template, it is not within any view template path.', $file);
-			throw new Exception($msg);
+			throw new InvalidArgumentException(sprintf(
+				'Cannot use "%s" as a template, it is not within any view template path.',
+				$file
+			));
 		}
 		return $absolute;
 	}
@@ -862,7 +866,7 @@ class View {
  *
  * @param string $name The name of the layout to find.
  * @return string Filename for layout file (.ctp).
- * @throws \Cake\View\Error\MissingLayoutException when a layout cannot be located
+ * @throws \Cake\View\Exception\MissingLayoutException when a layout cannot be located
  */
 	protected function _getLayoutFileName($name = null) {
 		if ($name === null) {
@@ -891,7 +895,7 @@ class View {
 				}
 			}
 		}
-		throw new Error\MissingLayoutException(array(
+		throw new Exception\MissingLayoutException(array(
 			'file' => $layoutPaths[0] . $name . $this->_ext
 		));
 	}

+ 2 - 2
tests/TestCase/Controller/PagesControllerTest.php

@@ -21,7 +21,7 @@ use Cake\Core\Configure;
 use Cake\Network\Request;
 use Cake\Network\Response;
 use Cake\TestSuite\TestCase;
-use Cake\View\Error\MissingViewException;
+use Cake\View\Exception\MissingViewException;
 use TestApp\Controller\PagesController;
 
 /**
@@ -60,7 +60,7 @@ class PagesControllerTest extends TestCase {
 /**
  * Test that missing view in debug mode renders missing_view error page
  *
- * @expectedException \Cake\View\Error\MissingViewException
+ * @expectedException \Cake\View\Exception\MissingViewException
  * @expectedExceptionCode 500
  * @return void
  */

+ 3 - 3
tests/TestCase/Error/ExceptionRendererTest.php

@@ -37,9 +37,9 @@ use Cake\Network\Request;
 use Cake\ORM\Error\MissingBehaviorException;
 use Cake\Routing\Router;
 use Cake\TestSuite\TestCase;
-use Cake\View\Error\MissingHelperException;
-use Cake\View\Error\MissingLayoutException;
-use Cake\View\Error\MissingViewException;
+use Cake\View\Exception\MissingHelperException;
+use Cake\View\Exception\MissingLayoutException;
+use Cake\View\Exception\MissingViewException;
 
 /**
  * BlueberryComponent class

+ 2 - 2
tests/TestCase/Network/Email/EmailTest.php

@@ -22,7 +22,7 @@ use Cake\Network\Email\DebugTransport;
 use Cake\Network\Email\Email;
 use Cake\TestSuite\TestCase;
 use Cake\Utility\File;
-use Cake\View\Error\MissingViewException;
+use Cake\View\Exception\MissingViewException;
 
 /**
  * Help to test Email
@@ -1631,7 +1631,7 @@ class EmailTest extends TestCase {
 		$this->assertContains('Here is your value: 12345', $result['message']);
 		$this->assertContains('This email was sent using the TestPlugin.', $result['message']);
 
-		$this->setExpectedException('Cake\View\Error\MissingViewException');
+		$this->setExpectedException('Cake\View\Exception\MissingViewException');
 		$this->CakeEmail->template('test_plugin_tpl', 'plug_default')->send();
 	}
 

+ 2 - 2
tests/TestCase/View/CellTest.php

@@ -136,7 +136,7 @@ class CellTest extends TestCase {
 /**
  * Tests manual render() invocation with error
  *
- * @expectedException \Cake\View\Error\MissingCellViewException
+ * @expectedException \Cake\View\Exception\MissingCellViewException
  * @return void
  */
 	public function testCellManualRenderError() {
@@ -193,7 +193,7 @@ class CellTest extends TestCase {
 /**
  * Tests that using an unexisting cell throws an exception.
  *
- * @expectedException \Cake\View\Error\MissingCellException
+ * @expectedException \Cake\View\Exception\MissingCellException
  * @return void
  */
 	public function testUnexistingCell() {

+ 2 - 2
tests/TestCase/View/HelperRegistryTest.php

@@ -95,7 +95,7 @@ class HelperRegistryTest extends TestCase {
 /**
  * test lazy loading of helpers
  *
- * @expectedException \Cake\View\Error\MissingHelperException
+ * @expectedException \Cake\View\Exception\MissingHelperException
  * @return void
  */
 	public function testLazyLoadException() {
@@ -161,7 +161,7 @@ class HelperRegistryTest extends TestCase {
 /**
  * test missinghelper exception
  *
- * @expectedException \Cake\View\Error\MissingHelperException
+ * @expectedException \Cake\View\Exception\MissingHelperException
  * @return void
  */
 	public function testLoadMissingHelper() {

+ 4 - 4
tests/TestCase/View/ViewTest.php

@@ -662,7 +662,7 @@ class ViewTest extends TestCase {
 /**
  * Test for missing views
  *
- * @expectedException \Cake\View\Error\MissingViewException
+ * @expectedException \Cake\View\Exception\MissingViewException
  * @return void
  */
 	public function testMissingView() {
@@ -680,7 +680,7 @@ class ViewTest extends TestCase {
 /**
  * Test for missing layouts
  *
- * @expectedException \Cake\View\Error\MissingLayoutException
+ * @expectedException \Cake\View\Exception\MissingLayoutException
  * @return void
  */
 	public function testMissingLayout() {
@@ -762,7 +762,7 @@ class ViewTest extends TestCase {
 /**
  * Test elementInexistent method
  *
- * @expectedException Cake\View\Error\MissingElementException
+ * @expectedException Cake\View\Exception\MissingElementException
  * @return void
  */
 	public function testElementInexistent() {
@@ -772,7 +772,7 @@ class ViewTest extends TestCase {
 /**
  * Test elementInexistent3 method
  *
- * @expectedException Cake\View\Error\MissingElementException
+ * @expectedException Cake\View\Exception\MissingElementException
  * @return void
  */
 	public function testElementInexistent3() {

+ 2 - 2
tests/test_app/TestApp/Controller/PagesController.php

@@ -21,7 +21,7 @@ namespace TestApp\Controller;
 use Cake\Core\Configure;
 use Cake\Network\Exception\NotFoundException;
 use Cake\Utility\Inflector;
-use Cake\View\Error\MissingViewException;
+use Cake\View\Exception\MissingViewException;
 
 /**
  * Static content controller
@@ -52,7 +52,7 @@ class PagesController extends AppController {
  * @param mixed What page to display
  * @return void
  * @throws Cake\Network\Exception\NotFoundException When the view file could not be found
- *	or Cake\View\Error\MissingViewException in debug mode.
+ *	or Cake\View\Exception\MissingViewException in debug mode.
  */
 	public function display() {
 		$path = func_get_args();