2005-07-04 01:07:14 +00:00
|
|
|
<?php
|
2005-08-21 06:49:02 +00:00
|
|
|
/* SVN FILE: $Id$ */
|
2005-05-22 23:24:09 +00:00
|
|
|
/**
|
2006-07-18 11:11:44 +00:00
|
|
|
* Command-line code generation utility to automate programmer chores.
|
2006-07-23 18:59:52 +00:00
|
|
|
*
|
2006-07-18 11:11:44 +00:00
|
|
|
* Bake is CakePHP's code generation script, which can help you kickstart
|
|
|
|
* application development by writing fully functional skeleton controllers,
|
|
|
|
* models, and views. Going further, Bake can also write Unit Tests for you.
|
2005-08-21 06:49:02 +00:00
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
2007-02-02 10:39:45 +00:00
|
|
|
* CakePHP(tm) : Rapid Development Framework <http://www.cakephp.org/>
|
2008-01-01 22:18:17 +00:00
|
|
|
* Copyright 2005-2008, Cake Software Foundation, Inc.
|
2006-05-26 05:29:17 +00:00
|
|
|
* 1785 E. Sahara Avenue, Suite 490-204
|
|
|
|
* Las Vegas, Nevada 89104
|
2005-08-21 06:49:02 +00:00
|
|
|
*
|
2005-12-23 21:57:26 +00:00
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
2005-08-21 06:49:02 +00:00
|
|
|
*
|
2006-01-13 23:53:23 +00:00
|
|
|
* @filesource
|
2008-01-01 22:18:17 +00:00
|
|
|
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc.
|
2007-02-02 10:39:45 +00:00
|
|
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
|
2006-05-26 05:29:17 +00:00
|
|
|
* @package cake
|
2007-05-14 01:14:41 +00:00
|
|
|
* @subpackage cake.cake.console.libs
|
|
|
|
* @since CakePHP(tm) v 1.2.0.5012
|
2006-05-26 05:29:17 +00:00
|
|
|
* @version $Revision$
|
|
|
|
* @modifiedby $LastChangedBy$
|
|
|
|
* @lastmodified $Date$
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
|
|
|
*/
|
|
|
|
/**
|
2006-07-18 11:11:44 +00:00
|
|
|
* Bake is a command-line code generation utility for automating programmer chores.
|
2006-05-26 05:29:17 +00:00
|
|
|
*
|
|
|
|
* @package cake
|
2007-05-13 20:18:57 +00:00
|
|
|
* @subpackage cake.cake.console.libs
|
2005-08-21 06:49:02 +00:00
|
|
|
*/
|
2007-05-12 21:18:07 +00:00
|
|
|
class BakeShell extends Shell {
|
2007-10-22 05:52:20 +00:00
|
|
|
/**
|
|
|
|
* Contains tasks to load and instantiate
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-03-15 05:45:43 +00:00
|
|
|
var $tasks = array('Project', 'DbConfig', 'Model', 'Controller', 'View', 'Plugin', 'Test');
|
2007-12-21 02:54:45 +00:00
|
|
|
/**
|
|
|
|
* Override loadTasks() to handle paths
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
function loadTasks() {
|
|
|
|
parent::loadTasks();
|
|
|
|
$task = Inflector::classify($this->command);
|
2007-12-27 07:41:56 +00:00
|
|
|
if (isset($this->{$task}) && !in_array($task, array('Project', 'DbConfig'))) {
|
2007-12-21 02:54:45 +00:00
|
|
|
$path = Inflector::underscore(Inflector::pluralize($this->command));
|
|
|
|
$this->{$task}->path = $this->params['working'] . DS . $path . DS;
|
2007-12-22 19:24:56 +00:00
|
|
|
if (!is_dir($this->{$task}->path)) {
|
2007-12-21 02:54:45 +00:00
|
|
|
$this->err(sprintf(__("%s directory could not be found.\nBe sure you have created %s", true), $task, $this->{$task}->path));
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-10-22 05:52:20 +00:00
|
|
|
/**
|
|
|
|
* Override main() to handle action
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function main() {
|
2008-05-05 15:42:02 +00:00
|
|
|
if (!is_dir($this->DbConfig->path)) {
|
|
|
|
if ($this->Project->execute()) {
|
|
|
|
$this->DbConfig->path = $this->params['working'] . DS . 'config' . DS;
|
|
|
|
}
|
2007-05-04 19:32:05 +00:00
|
|
|
}
|
2007-05-05 06:00:38 +00:00
|
|
|
|
2007-06-20 06:15:35 +00:00
|
|
|
if (!config('database')) {
|
2007-12-21 02:54:45 +00:00
|
|
|
$this->out(__("Your database configuration was not found. Take a moment to create one.", true));
|
2007-06-04 07:21:17 +00:00
|
|
|
$this->args = null;
|
|
|
|
return $this->DbConfig->execute();
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2007-06-03 23:56:04 +00:00
|
|
|
$this->out('Interactive Bake Shell');
|
|
|
|
$this->hr();
|
2007-09-15 20:23:30 +00:00
|
|
|
$this->out('[D]atabase Configuration');
|
2007-05-04 04:37:25 +00:00
|
|
|
$this->out('[M]odel');
|
|
|
|
$this->out('[V]iew');
|
2007-05-13 23:11:40 +00:00
|
|
|
$this->out('[C]ontroller');
|
2007-10-20 05:55:37 +00:00
|
|
|
$this->out('[P]roject');
|
2007-07-08 23:48:05 +00:00
|
|
|
$this->out('[Q]uit');
|
2007-05-14 01:14:41 +00:00
|
|
|
|
2007-12-21 02:54:45 +00:00
|
|
|
$classToBake = strtoupper($this->in(__('What would you like to Bake?', true), array('D', 'M', 'V', 'C', 'P', 'Q')));
|
2007-05-14 12:23:25 +00:00
|
|
|
switch($classToBake) {
|
2007-09-15 20:23:30 +00:00
|
|
|
case 'D':
|
|
|
|
$this->DbConfig->execute();
|
|
|
|
break;
|
2007-05-14 12:23:25 +00:00
|
|
|
case 'M':
|
2007-06-08 07:53:58 +00:00
|
|
|
$this->Model->execute();
|
2007-05-14 12:23:25 +00:00
|
|
|
break;
|
|
|
|
case 'V':
|
2007-06-08 07:53:58 +00:00
|
|
|
$this->View->execute();
|
2007-05-14 12:23:25 +00:00
|
|
|
break;
|
|
|
|
case 'C':
|
2007-06-08 07:53:58 +00:00
|
|
|
$this->Controller->execute();
|
2007-05-14 12:23:25 +00:00
|
|
|
break;
|
2007-10-20 05:55:37 +00:00
|
|
|
case 'P':
|
|
|
|
$this->Project->execute();
|
|
|
|
break;
|
2007-07-08 23:48:05 +00:00
|
|
|
case 'Q':
|
|
|
|
exit(0);
|
|
|
|
break;
|
2006-05-26 05:29:17 +00:00
|
|
|
default:
|
2008-03-15 05:45:43 +00:00
|
|
|
$this->out(__('You have made an invalid selection. Please choose a type of class to Bake by entering D, M, V, or C.', true));
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2007-06-03 23:56:04 +00:00
|
|
|
$this->hr();
|
|
|
|
$this->main();
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2007-12-22 19:24:56 +00:00
|
|
|
/**
|
|
|
|
* Quickly bake the MVC
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
function all() {
|
|
|
|
$ds = 'default';
|
|
|
|
$this->hr();
|
|
|
|
$this->out('Bake All');
|
|
|
|
$this->hr();
|
|
|
|
|
|
|
|
if (isset($this->params['connection'])) {
|
|
|
|
$ds = $this->params['connection'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($this->args)) {
|
|
|
|
$name = $this->Model->getName($ds);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($this->args[0])) {
|
|
|
|
$name = $this->args[0];
|
|
|
|
$this->Model->listAll($ds, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
$modelExists = false;
|
|
|
|
$model = $this->_modelName($name);
|
|
|
|
if (App::import('Model', $model)) {
|
|
|
|
$object = new $model();
|
|
|
|
$modelExists = true;
|
|
|
|
} else {
|
|
|
|
App::import('Model');
|
|
|
|
$object = new Model(array('name' => $name, 'ds' => $ds));
|
|
|
|
}
|
|
|
|
|
|
|
|
$modelBaked = $this->Model->bake($object, false);
|
|
|
|
|
|
|
|
if ($modelBaked && $modelExists === false) {
|
|
|
|
$this->out(sprintf(__('%s Model was baked.', true), $model));
|
|
|
|
if ($this->_checkUnitTest()) {
|
|
|
|
$this->Model->bakeTest($model);
|
|
|
|
}
|
|
|
|
$modelExists = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($modelExists === true) {
|
|
|
|
$controller = $this->_controllerName($name);
|
|
|
|
if ($this->Controller->bake($controller, $this->Controller->bakeActions($controller))) {
|
|
|
|
$this->out(sprintf(__('%s Controller was baked.', true), $name));
|
|
|
|
if ($this->_checkUnitTest()) {
|
|
|
|
$this->Controller->bakeTest($controller);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (App::import('Controller', $controller)) {
|
|
|
|
$this->View->args = array($controller);
|
|
|
|
$this->View->execute();
|
|
|
|
}
|
|
|
|
$this->out(__('Bake All complete'));
|
|
|
|
} else {
|
|
|
|
$this->err(__('Bake All could not continue without a valid model', true));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($this->args)) {
|
|
|
|
$this->all();
|
|
|
|
}
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
2007-06-08 08:44:34 +00:00
|
|
|
/**
|
|
|
|
* Displays help contents
|
|
|
|
*
|
2007-10-22 05:52:20 +00:00
|
|
|
* @access public
|
2007-06-21 14:38:46 +00:00
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function help() {
|
2007-05-04 04:37:25 +00:00
|
|
|
$this->out('CakePHP Bake:');
|
2006-05-26 05:29:17 +00:00
|
|
|
$this->hr();
|
2007-05-04 04:37:25 +00:00
|
|
|
$this->out('The Bake script generates controllers, views and models for your application.');
|
|
|
|
$this->out('If run with no command line arguments, Bake guides the user through the class');
|
|
|
|
$this->out('creation process. You can customize the generation process by telling Bake');
|
|
|
|
$this->out('where different parts of your application are using command line arguments.');
|
2007-06-08 08:44:34 +00:00
|
|
|
$this->hr();
|
|
|
|
$this->out("Usage: cake bake <command> <arg1> <arg2>...");
|
|
|
|
$this->hr();
|
|
|
|
$this->out('Params:');
|
|
|
|
$this->out("\t-app <path> Absolute/Relative path to your app folder.\n");
|
|
|
|
$this->out('Commands:');
|
|
|
|
$this->out("\n\tbake help\n\t\tshows this help message.");
|
2007-12-22 19:24:56 +00:00
|
|
|
$this->out("\n\tbake all <name>\n\t\tbakes complete MVC. optional <name> of a Model");
|
2007-06-08 08:44:34 +00:00
|
|
|
$this->out("\n\tbake project <path>\n\t\tbakes a new app folder in the path supplied\n\t\tor in current directory if no path is specified");
|
2008-03-15 05:45:43 +00:00
|
|
|
$this->out("\n\tbake plugin <name>\n\t\tbakes a new plugin folder in the path supplied\n\t\tor in current directory if no path is specified.");
|
2007-06-08 08:44:34 +00:00
|
|
|
$this->out("\n\tbake db_config\n\t\tbakes a database.php file in config directory.");
|
|
|
|
$this->out("\n\tbake model\n\t\tbakes a model. run 'bake model help' for more info");
|
|
|
|
$this->out("\n\tbake view\n\t\tbakes views. run 'bake view help' for more info");
|
|
|
|
$this->out("\n\tbake controller\n\t\tbakes a controller. run 'bake controller help' for more info");
|
|
|
|
$this->out("");
|
2007-06-21 14:38:46 +00:00
|
|
|
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2006-05-09 02:15:47 +00:00
|
|
|
}
|
2007-07-25 04:38:28 +00:00
|
|
|
?>
|