Refactoring tasks

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5196 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
dho 2007-05-26 09:00:54 +00:00
parent a357f30cda
commit 83f0635b3b
3 changed files with 94 additions and 65 deletions

View file

@ -53,27 +53,7 @@ class ControllerTask extends Shell {
$wannaUseScaffold = 'n';
$wannaDoScaffolding = 'y';
$useDbConfig = 'default';
$this->__doList($useDbConfig, 'Controllers');
$enteredController = '';
while ($enteredController == '') {
$enteredController = $this->in('Enter a number from the list above, or type in the name of another controller.');
if ($enteredController == '' || intval($enteredController) > count($this->_controllerNames)) {
$this->out('Error:');
$this->out("The Controller name you supplied was empty, or the number \nyou selected was not an option. Please try again.");
$enteredController = '';
}
}
if (intval($enteredController) > 0 && intval($enteredController) <= count($this->_controllerNames) ) {
$controllerName = $this->_controllerNames[intval($enteredController) - 1];
} else {
$controllerName = Inflector::camelize($enteredController);
}
$controllerName = $this->__getControllerName();
$controllerPath = low(Inflector::underscore($controllerName));
$doItInteractive = $this->in("Would you like bake to build your controller interactively?\nWarning: Choosing no will overwrite {$controllerName} controller if it exist.", array('y','n'), 'y');
@ -493,5 +473,35 @@ class ControllerTask extends Shell {
$this->_controllerNames[] = $this->_controllerName($this->_modelName($tables[$i]));
$this->out($i + 1 . ". " . $this->_controllerNames[$i]);
}
}
}
/**
* Forces the user to specify the controller he wants to bake, and returns the selected controller name.
*
* @return the controller name
*/
function __getControllerName() {
$useDbConfig = 'default';
$this->__doList($useDbConfig, 'Controllers');
$enteredController = '';
while ($enteredController == '') {
$enteredController = $this->in('Enter a number from the list above, or type in the name of another controller.');
if ($enteredController == '' || intval($enteredController) > count($this->_controllerNames)) {
$this->out('Error:');
$this->out("The Controller name you supplied was empty, or the number \nyou selected was not an option. Please try again.");
$enteredController = '';
}
}
if (intval($enteredController) > 0 && intval($enteredController) <= count($this->_controllerNames) ) {
$controllerName = $this->_controllerNames[intval($enteredController) - 1];
} else {
$controllerName = Inflector::camelize($enteredController);
}
return $controllerName;
}
}

View file

@ -57,27 +57,8 @@ class ModelTask extends Shell {
$useDbConfig = $this->in('Please provide the name of the connection you wish to use.');
}*/
$useDbConfig = 'default';
$this->__doList($useDbConfig);
$enteredModel = '';
while ($enteredModel == '') {
$enteredModel = $this->in('Enter a number from the list above, or type in the name of another model.');
if ($enteredModel == '' || intval($enteredModel) > count($this->_modelNames)) {
$this->out('Error:');
$this->out("The model name you supplied was empty, or the number \nyou selected was not an option. Please try again.");
$enteredModel = '';
}
}
if (intval($enteredModel) > 0 && intval($enteredModel) <= count($this->_modelNames)) {
$currentModelName = $this->_modelNames[intval($enteredModel) - 1];
} else {
$currentModelName = $enteredModel;
}
$currentModelName = $this->__getModelName($useDbConfig);
$db =& ConnectionManager::getDataSource($useDbConfig);
$tableIsGood = false;
$useTable = Inflector::tableize($currentModelName);
@ -628,5 +609,34 @@ class ModelTask extends Shell {
$this->out($i + 1 . ". " . $this->_modelNames[$i]);
}
}
/**
* Forces the user to specify the model he wants to bake, and returns the selected model name.
*
* @return the model name
*/
function __getModelName($useDbConfig) {
$this->__doList($useDbConfig);
$enteredModel = '';
while ($enteredModel == '') {
$enteredModel = $this->in('Enter a number from the list above, or type in the name of another model.');
if ($enteredModel == '' || intval($enteredModel) > count($this->_modelNames)) {
$this->out('Error:');
$this->out("The model name you supplied was empty, or the number \nyou selected was not an option. Please try again.");
$enteredModel = '';
}
}
if (intval($enteredModel) > 0 && intval($enteredModel) <= count($this->_modelNames)) {
$currentModelName = $this->_modelNames[intval($enteredModel) - 1];
} else {
$currentModelName = $enteredModel;
}
return $currentModelName;
}
}
?>

View file

@ -49,28 +49,7 @@ class ViewTask extends BakeShell {
$wannaUseSession = 'y';
$wannaDoScaffold = 'y';
$useDbConfig = 'default';
$this->__doList($useDbConfig, 'Controllers');
$enteredController = '';
while ($enteredController == '') {
$enteredController = $this->in('Enter a number from the list above, or type in the name of another controller.');
if ($enteredController == '' || intval($enteredController) > count($this->_controllerNames)) {
$this->out('Error:');
$this->out("The Controller name you supplied was empty, or the number \nyou selected was not an option. Please try again.");
$enteredController = '';
}
}
if (intval($enteredController) > 0 && intval($enteredController) <= count($this->_controllerNames) ) {
$controllerName = $this->_controllerNames[intval($enteredController) - 1];
} else {
$controllerName = Inflector::camelize($enteredController);
}
$controllerName = $this->__getControllerName();
$controllerPath = low(Inflector::underscore($controllerName));
$doItInteractive = $this->in("Would you like bake to build your views interactively?\nWarning: Choosing no will overwrite {$controllerName} views if it exist.", array('y','n'), 'y');
@ -542,4 +521,34 @@ class ViewTask extends BakeShell {
$this->out($i + 1 . ". " . $this->_controllerNames[$i]);
}
}
/**
* Forces the user to specify the controller for which he wants to bake views, and returns the selected controller name.
*
* @return the controller name
*/
function __getControllerName() {
$useDbConfig = 'default';
$this->__doList($useDbConfig, 'Controllers');
$enteredController = '';
while ($enteredController == '') {
$enteredController = $this->in('Enter a number from the list above, or type in the name of another controller.');
if ($enteredController == '' || intval($enteredController) > count($this->_controllerNames)) {
$this->out('Error:');
$this->out("The Controller name you supplied was empty, or the number \nyou selected was not an option. Please try again.");
$enteredController = '';
}
}
if (intval($enteredController) > 0 && intval($enteredController) <= count($this->_controllerNames) ) {
$controllerName = $this->_controllerNames[intval($enteredController) - 1];
} else {
$controllerName = Inflector::camelize($enteredController);
}
return $controllerName;
}
}