00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 class BakeShell extends Shell {
00037
00038
00039
00040
00041
00042
00043 var $tasks = array('Project', 'DbConfig', 'Model', 'Controller', 'View', 'Plugin', 'Test');
00044
00045
00046
00047
00048
00049 function loadTasks() {
00050 parent::loadTasks();
00051 $task = Inflector::classify($this->command);
00052 if (isset($this->{$task}) && !in_array($task, array('Project', 'DbConfig'))) {
00053 $path = Inflector::underscore(Inflector::pluralize($this->command));
00054 $this->{$task}->path = $this->params['working'] . DS . $path . DS;
00055 if (!is_dir($this->{$task}->path)) {
00056 $this->err(sprintf(__("%s directory could not be found.\nBe sure you have created %s", true), $task, $this->{$task}->path));
00057 $this->_stop();
00058 }
00059 }
00060 }
00061
00062
00063
00064
00065
00066 function main() {
00067 if (!is_dir($this->DbConfig->path)) {
00068 if ($this->Project->execute()) {
00069 $this->DbConfig->path = $this->params['working'] . DS . 'config' . DS;
00070 }
00071 }
00072
00073 if (!config('database')) {
00074 $this->out(__("Your database configuration was not found. Take a moment to create one.", true));
00075 $this->args = null;
00076 return $this->DbConfig->execute();
00077 }
00078 $this->out('Interactive Bake Shell');
00079 $this->hr();
00080 $this->out('[D]atabase Configuration');
00081 $this->out('[M]odel');
00082 $this->out('[V]iew');
00083 $this->out('[C]ontroller');
00084 $this->out('[P]roject');
00085 $this->out('[Q]uit');
00086
00087 $classToBake = strtoupper($this->in(__('What would you like to Bake?', true), array('D', 'M', 'V', 'C', 'P', 'Q')));
00088 switch ($classToBake) {
00089 case 'D':
00090 $this->DbConfig->execute();
00091 break;
00092 case 'M':
00093 $this->Model->execute();
00094 break;
00095 case 'V':
00096 $this->View->execute();
00097 break;
00098 case 'C':
00099 $this->Controller->execute();
00100 break;
00101 case 'P':
00102 $this->Project->execute();
00103 break;
00104 case 'Q':
00105 exit(0);
00106 break;
00107 default:
00108 $this->out(__('You have made an invalid selection. Please choose a type of class to Bake by entering D, M, V, or C.', true));
00109 }
00110 $this->hr();
00111 $this->main();
00112 }
00113
00114
00115
00116
00117
00118 function all() {
00119 $ds = 'default';
00120 $this->hr();
00121 $this->out('Bake All');
00122 $this->hr();
00123
00124 if (isset($this->params['connection'])) {
00125 $ds = $this->params['connection'];
00126 }
00127
00128 if (empty($this->args)) {
00129 $name = $this->Model->getName($ds);
00130 }
00131
00132 if (!empty($this->args[0])) {
00133 $name = $this->args[0];
00134 $this->Model->listAll($ds, false);
00135 }
00136
00137 $modelExists = false;
00138 $model = $this->_modelName($name);
00139 if (App::import('Model', $model)) {
00140 $object = new $model();
00141 $modelExists = true;
00142 } else {
00143 App::import('Model');
00144 $object = new Model(array('name' => $name, 'ds' => $ds));
00145 }
00146
00147 $modelBaked = $this->Model->bake($object, false);
00148
00149 if ($modelBaked && $modelExists === false) {
00150 $this->out(sprintf(__('%s Model was baked.', true), $model));
00151 if ($this->_checkUnitTest()) {
00152 $this->Model->bakeTest($model);
00153 }
00154 $modelExists = true;
00155 }
00156
00157 if ($modelExists === true) {
00158 $controller = $this->_controllerName($name);
00159 if ($this->Controller->bake($controller, $this->Controller->bakeActions($controller))) {
00160 $this->out(sprintf(__('%s Controller was baked.', true), $name));
00161 if ($this->_checkUnitTest()) {
00162 $this->Controller->bakeTest($controller);
00163 }
00164 }
00165 if (App::import('Controller', $controller)) {
00166 $this->View->args = array($controller);
00167 $this->View->execute();
00168 }
00169 $this->out(__('Bake All complete'));
00170 array_shift($this->args);
00171 } else {
00172 $this->err(__('Bake All could not continue without a valid model', true));
00173 }
00174
00175 if (empty($this->args)) {
00176 $this->all();
00177 }
00178 $this->_stop();
00179 }
00180
00181
00182
00183
00184
00185
00186 function help() {
00187 $this->out('CakePHP Bake:');
00188 $this->hr();
00189 $this->out('The Bake script generates controllers, views and models for your application.');
00190 $this->out('If run with no command line arguments, Bake guides the user through the class');
00191 $this->out('creation process. You can customize the generation process by telling Bake');
00192 $this->out('where different parts of your application are using command line arguments.');
00193 $this->hr();
00194 $this->out("Usage: cake bake <command> <arg1> <arg2>...");
00195 $this->hr();
00196 $this->out('Params:');
00197 $this->out("\t-app <path> Absolute/Relative path to your app folder.\n");
00198 $this->out('Commands:');
00199 $this->out("\n\tbake help\n\t\tshows this help message.");
00200 $this->out("\n\tbake all <name>\n\t\tbakes complete MVC. optional <name> of a Model");
00201 $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");
00202 $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.");
00203 $this->out("\n\tbake db_config\n\t\tbakes a database.php file in config directory.");
00204 $this->out("\n\tbake model\n\t\tbakes a model. run 'bake model help' for more info");
00205 $this->out("\n\tbake view\n\t\tbakes views. run 'bake view help' for more info");
00206 $this->out("\n\tbake controller\n\t\tbakes a controller. run 'bake controller help' for more info");
00207 $this->out("");
00208
00209 }
00210 }
00211 ?>