Browse Source

Use anevent when creating the view

so that users can modify or replace the view class being used.

Also remove leftover templatePath references, and remove the default
theme BC hack
AD7six 11 years ago
parent
commit
74f1784564

+ 14 - 46
src/Shell/Task/TemplateTask.php

@@ -18,6 +18,8 @@ use Cake\Console\Shell;
 use Cake\Core\App;
 use Cake\Core\ConventionsTrait;
 use Cake\Core\Plugin;
+use Cake\Event\Event;
+use Cake\Event\EventManager;
 use Cake\Filesystem\Folder;
 use Cake\Network\Request;
 use Cake\Network\Response;
@@ -33,9 +35,7 @@ class TemplateTask extends Shell {
 
 	use ConventionsTrait;
 
-	use ViewVarsTrait {
-		getView as _getView;
-	}
+	use ViewVarsTrait;
 
 /**
  * BakeView instance
@@ -45,39 +45,6 @@ class TemplateTask extends Shell {
 	public $View;
 
 /**
- * Which view class to use for baking
- *
- * @var string
- */
-	public $viewClass = 'Cake\View\BakeView';
-
-/**
- * An array containing the names of helpers to use when baking
- *
- * Example: `public $helpers = ['Bake', 'BakePlusPlus'];`
- *
- * @var array
- */
-	public $helpers = [
-		'Bake',
-	];
-
-/**
- * The bake theme to use
- *
- * @var string
- */
-	public $theme = '';
-
-/**
- * These properties will be passed from the template task to the View as options.
- *
- * @var array
- * @see \Cake\View\View
- */
-	protected $_validViewOptions = ['helpers', 'theme'];
-
-/**
  * Get view instance
  *
  * @param string $viewClass View class name or null to use $viewClass
@@ -89,9 +56,18 @@ class TemplateTask extends Shell {
 			return $this->View;
 		}
 
-		$this->theme = isset($this->params['template']) ? $this->params['template'] : '';
+		$theme = isset($this->params['template']) ? $this->params['template'] : '';
+
+		$viewOptions = [
+			'helpers' => ['Bake'],
+			'theme' => $theme
+		];
+		$view = new BakeView(new Request(), new Response(), null, $viewOptions);
+		$event = new Event('Bake.initialize', $view);
+		EventManager::instance()->dispatch($event);
+		$this->View = $event->subject;
 
-		return $this->_getView();
+		return $this->View;
 	}
 
 /**
@@ -102,14 +78,6 @@ class TemplateTask extends Shell {
  * @throws \Cake\View\Exception\MissingViewException If view class was not found.
  */
 	public function createView($viewClass = null) {
-		if ($viewClass === null) {
-			$viewClass = $this->viewClass;
-		}
-		$className = App::className($viewClass, 'View');
-		if (!$className) {
-			throw new Exception\MissingViewException([$viewClass]);
-		}
-		return new $className(new Request(), new Response());
 	}
 
 /**

+ 0 - 1
tests/TestCase/Shell/Task/ControllerTaskTest.php

@@ -67,7 +67,6 @@ class ControllerTaskTest extends TestCase {
 		$this->Task->connection = 'test';
 
 		$this->Task->Template = new TemplateTask($io);
-		$this->Task->Template->params['theme'] = 'default';
 
 		$this->Task->Model = $this->getMock('Cake\Shell\Task\ModelTask',
 			array('in', 'out', 'err', 'createFile', '_stop'),

+ 0 - 3
tests/TestCase/Shell/Task/ViewTaskTest.php

@@ -123,9 +123,6 @@ class ViewTaskTest extends TestCase {
 		);
 		$this->Task->Template = new TemplateTask($io);
 		$this->Task->Model = $this->getMock('Cake\Shell\Task\ModelTask', [], [$io]);
-
-		$this->Task->Template->params['template'] = 'default';
-		$this->Task->Template->templatePaths = ['default' => CAKE . 'Template/Bake/default/'];
 	}
 
 /**