updating bake plugin handling, fixes #3994, fixes #3904, fixes #3998, fixes #3995

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6526 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
gwoo 2008-03-09 01:05:27 +00:00
parent da19393614
commit 3404ccc668
4 changed files with 98 additions and 45 deletions

View file

@ -33,6 +33,13 @@
* @subpackage cake.cake.console.libs.tasks
*/
class ControllerTask extends Shell {
/**
* Name of plugin
*
* @var string
* @access public
*/
var $plugin = null;
/**
* Tasks to be loaded by this Task
*
@ -97,7 +104,7 @@ class ControllerTask extends Shell {
*/
function __interactive($controllerName = false) {
if (!$controllerName) {
$this->interactive = false;
$this->interactive = true;
$this->hr();
$this->out(sprintf("Bake Controller\nPath: %s", $this->path));
$this->hr();
@ -114,7 +121,7 @@ class ControllerTask extends Shell {
$this->hr();
$this->out("Baking {$controllerName}Controller");
$this->hr();
$controllerFile = low(Inflector::underscore($controllerName));
$question[] = __("Would you like to build your controller interactively?", true);
@ -400,7 +407,7 @@ class ControllerTask extends Shell {
*/
function bake($controllerName, $actions = '', $helpers = null, $components = null, $uses = null) {
$out = "<?php\n";
$out .= "class $controllerName" . "Controller extends AppController {\n\n";
$out .= "class $controllerName" . "Controller extends {$this->plugin}AppController {\n\n";
$out .= "\tvar \$name = '$controllerName';\n";
if (low($actions) == 'scaffold') {
@ -454,7 +461,11 @@ class ControllerTask extends Shell {
* @access private
*/
function bakeTest($className) {
$out = "App::import('Controller', '$className');\n\n";
$import = $className;
if ($this->plugin) {
$import = $this->plugin . '.' . $className;
}
$out = "App::import('Controller', '$import');\n\n";
$out .= "class Test{$className} extends {$className}Controller {\n";
$out .= "\tvar \$autoRender = false;\n}\n\n";
$out .= "class {$className}ControllerTest extends CakeTestCase {\n";
@ -465,6 +476,11 @@ class ControllerTask extends Shell {
$out .= "\tfunction tearDown() {\n\t\tunset(\$this->{$className});\n\t}\n}\n";
$path = CONTROLLER_TESTS;
if (isset($this->plugin)) {
$pluginPath = 'plugins' . DS . Inflector::underscore($this->plugin) . DS;
$path = APP . $pluginPath . 'tests' . DS . 'controllers' . DS;
}
$filename = Inflector::underscore($className).'_controller.test.php';
$this->out("\nBaking unit test for $className...");
@ -516,15 +532,15 @@ class ControllerTask extends Shell {
while ($enteredController == '') {
$enteredController = $this->in(__("Enter a number from the list above, type in the name of another controller, or 'q' to exit", true), null, 'q');
if ($enteredController === 'q') {
$this->out(__("Exit", true));
exit();
}
if ($enteredController == '' || intval($enteredController) > count($controllers)) {
$this->out('Error:');
$this->out("The Controller name you supplied was empty, or the number \nyou selected was not an option. Please try again.");
$this->out(__('Error:', true));
$this->out(__("The Controller name you supplied was empty, or the number \nyou selected was not an option. Please try again.", true));
$enteredController = '';
}
}

View file

@ -33,6 +33,13 @@
* @subpackage cake.cake.console.libs.tasks
*/
class ModelTask extends Shell {
/**
* Name of plugin
*
* @var string
* @access public
*/
var $plugin = null;
/**
* path to MODELS directory
*
@ -498,7 +505,7 @@ class ModelTask extends Shell {
}
$out = "<?php\n";
$out .= "class {$name} extends AppModel {\n\n";
$out .= "class {$name} extends {$this->plugin}AppModel {\n\n";
$out .= "\tvar \$name = '{$name}';\n";
if ($useDbConfig !== 'default') {
@ -666,7 +673,13 @@ class ModelTask extends Shell {
}
}
$fixture = join(", ", $fixture);
$out = "App::import('Model', '$className');\n\n";
$import = $className;
if (isset($this->plugin)) {
$import = $this->plugin . '.' . $className;
}
$out = "App::import('Model', '$import');\n\n";
$out .= "class Test{$className} extends {$className} {\n";
$out .= "\tvar \$cacheSources = false;\n}\n\n";
$out .= "class {$className}TestCase extends CakeTestCase {\n";
@ -682,6 +695,11 @@ class ModelTask extends Shell {
$out .= "\t\t\$this->assertEqual(\$results, \$expected);\n\t}\n}\n";
$path = MODEL_TESTS;
if (isset($this->plugin)) {
$pluginPath = 'plugins' . DS . Inflector::underscore($this->plugin) . DS;
$path = APP . $pluginPath . 'tests' . DS . 'models' . DS;
}
$filename = Inflector::underscore($className).'.test.php';
$this->out("\nBaking unit test for $className...");
@ -869,6 +887,10 @@ class ModelTask extends Shell {
$out .= "\tvar \$records = array(array(\n$records\n\t\t\t));\n";
$out .= "}\n";
$path = TESTS . DS . 'fixtures' . DS;
if (isset($this->plugin)) {
$pluginPath = 'plugins' . DS . Inflector::underscore($this->plugin) . DS;
$path = APP . $pluginPath . 'tests' . DS . 'fixtures' . DS;
}
$filename = Inflector::underscore($model).'_fixture.php';
$header = '$Id';
$content = "<?php \n/* SVN FILE: $header$ */\n/* ". $model ." Fixure generated on: " . date('Y-m-d H:m:s') . " : ". time() . "*/\n{$out}?>";

View file

@ -73,18 +73,25 @@ class PluginTask extends Shell {
if(isset($this->args[0])) {
$plugin = Inflector::camelize($this->args[0]);
$this->Dispatch->shiftArgs();
$this->out(sprintf('Plugin: %s', $plugin));
$pluginPath = Inflector::underscore($plugin) . DS;
$this->out(sprintf('Plugin: %s', $this->path . $pluginPath));
$this->Dispatch->shiftArgs();
if (is_dir($this->path . $pluginPath)) {
$this->out(sprintf('Plugin: %s', $plugin));
$this->out(sprintf('Path: %s', $this->path . $pluginPath));
$this->hr();
} elseif (isset($this->args[0])) {
$this->err(sprintf('%s in path %s not found.', $plugin, $this->path . $pluginPath));
exit();
} else {
$this->__interactive($plugin);
}
}
if (isset($this->args[0]) && isset($plugin)) {
if(isset($this->args[0])) {
$task = Inflector::classify($this->args[0]);
$this->Dispatch->shiftArgs();
if (in_array($task, $this->tasks)) {
$this->{$task}->plugin = $plugin;
$this->{$task}->path = $this->path . $pluginPath . Inflector::underscore(Inflector::pluralize($task)) . DS;
if (!is_dir($this->{$task}->path)) {
@ -93,11 +100,7 @@ class PluginTask extends Shell {
$this->{$task}->loadTasks();
$this->{$task}->execute();
}
exit();
}
$this->__interactive($plugin);
}
/**
@ -155,28 +158,28 @@ class PluginTask extends Shell {
if (!empty($errors)) {
return false;
}
$controllerFileName = $pluginPath . '_app_controller.php';
$out = "<?php\n\n";
$out .= "class {$plugin}AppController extends AppController {\n\n";
$out .= "}\n\n";
$out .= "?>\n";
$this->createFile($this->path . $pluginPath. DS . $controllerFileName, $out);
$modelFileName = $pluginPath . '_app_model.php';
$out = "<?php\n\n";
$out .= "class {$plugin}AppModel extends AppModel {\n\n";
$out .= "}\n\n";
$out .= "?>\n";
$this->createFile($this->path . $pluginPath . DS . $modelFileName, $out);
$this->hr();
$this->out(sprintf(__("Created: %s in %s", true), $plugin, $this->path . $pluginPath));
$this->hr();
}
$controllerFileName = $pluginPath . '_app_controller.php';
$out = "<?php\n\n";
$out .= "class {$plugin}AppController extends AppController {\n\n";
$out .= "}\n\n";
$out .= "?>\n";
$this->createFile($this->path . $pluginPath. DS . $controllerFileName, $out);
$modelFileName = $pluginPath . '_app_model.php';
$out = "<?php\n\n";
$out .= "class {$plugin}AppModel extends AppModel {\n\n";
$out .= "}\n\n";
$out .= "?>\n";
$this->createFile($this->path . $pluginPath . DS . $modelFileName, $out);
$this->hr();
$this->out(sprintf(__("Created: %s in %s", true), $plugin, $this->path . $pluginPath));
$this->hr();
return true;
}
/**

View file

@ -26,7 +26,7 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
uses('controller'.DS.'controller');
App::import('Core', 'Controller');
/**
* Task class for creating and updating view files.
*
@ -34,6 +34,13 @@ uses('controller'.DS.'controller');
* @subpackage cake.cake.console.libs.tasks
*/
class ViewTask extends Shell {
/**
* Name of plugin
*
* @var string
* @access public
*/
var $plugin = null;
/**
* Tasks to be loaded by this Task
*
@ -231,12 +238,17 @@ class ViewTask extends Shell {
$this->err(__('Controller not found', true));
}
$controllerClassName = $this->controllerName . 'Controller';
if (!class_exists($this->controllerName . 'Controller') && !App::import('Controller', $this->controllerName)) {
$import = $this->controllerName;
if ($this->plugin) {
$import = $this->plugin . '.' . $this->controllerName;
}
if (!App::import('Controller', $import)) {
$file = $this->controllerPath . '_controller.php';
$this->err(sprintf(__("The file '%s' could not be found.\nIn order to bake a view, you'll need to first create the controller.", true), $file));
exit();
}
$controllerClassName = $this->controllerName . 'Controller';
$controllerObj = & new $controllerClassName();
$controllerObj->constructClasses();
$modelClass = $controllerObj->modelClass;