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 if (!class_exists('File')) {
00028 uses('file');
00029 }
00030
00031
00032
00033
00034
00035
00036 class PluginTask extends Shell {
00037
00038
00039
00040
00041 var $tasks = array('Model', 'Controller', 'View');
00042
00043
00044
00045
00046
00047
00048 var $path = null;
00049
00050
00051
00052
00053
00054 function initialize() {
00055 $this->path = APP . 'plugins' . DS;
00056 }
00057
00058
00059
00060
00061
00062 function execute() {
00063 if (empty($this->params['skel'])) {
00064 $this->params['skel'] = '';
00065 if (is_dir(CAKE_CORE_INCLUDE_PATH.DS.'cake'.DS.'console'.DS.'libs'.DS.'templates'.DS.'skel') === true) {
00066 $this->params['skel'] = CAKE_CORE_INCLUDE_PATH.DS.'cake'.DS.'console'.DS.'libs'.DS.'templates'.DS.'skel';
00067 }
00068 }
00069
00070 $plugin = null;
00071
00072 if (isset($this->args[0])) {
00073 $plugin = Inflector::camelize($this->args[0]);
00074 $pluginPath = Inflector::underscore($plugin) . DS;
00075 $this->Dispatch->shiftArgs();
00076 if (is_dir($this->path . $pluginPath)) {
00077 $this->out(sprintf('Plugin: %s', $plugin));
00078 $this->out(sprintf('Path: %s', $this->path . $pluginPath));
00079 $this->hr();
00080 } elseif (isset($this->args[0])) {
00081 $this->err(sprintf('%s in path %s not found.', $plugin, $this->path . $pluginPath));
00082 $this->_stop();
00083 } else {
00084 $this->__interactive($plugin);
00085 }
00086 }
00087
00088 if (isset($this->args[0])) {
00089 $task = Inflector::classify($this->args[0]);
00090 $this->Dispatch->shiftArgs();
00091 if (in_array($task, $this->tasks)) {
00092 $this->{$task}->plugin = $plugin;
00093 $this->{$task}->path = $this->path . $pluginPath . Inflector::underscore(Inflector::pluralize($task)) . DS;
00094
00095 if (!is_dir($this->{$task}->path)) {
00096 $this->err(sprintf(__("%s directory could not be found.\nBe sure you have created %s", true), $task, $this->{$task}->path));
00097 }
00098 $this->{$task}->loadTasks();
00099 $this->{$task}->execute();
00100 }
00101 }
00102 }
00103
00104
00105
00106
00107
00108
00109
00110 function __interactive($plugin = null) {
00111 while ($plugin === null) {
00112 $plugin = $this->in(__('Enter the name of the plugin in CamelCase format', true));
00113 }
00114
00115 if (!$this->bake($plugin)) {
00116 $this->err(sprintf(__("An error occured trying to bake: %s in %s", true), $plugin, $this->path . $pluginPath));
00117 }
00118 }
00119
00120
00121
00122
00123
00124
00125
00126
00127 function bake($plugin) {
00128
00129 $pluginPath = Inflector::underscore($plugin);
00130
00131 $this->hr();
00132 $this->out("Plugin Name: $plugin");
00133 $this->out("Plugin Directory: {$this->path}{$pluginPath}");
00134 $this->hr();
00135
00136
00137 $looksGood = $this->in('Look okay?', array('y', 'n', 'q'), 'y');
00138
00139 if (strtolower($looksGood) == 'y' || strtolower($looksGood) == 'yes') {
00140 $verbose = $this->in(__('Do you want verbose output?', true), array('y', 'n'), 'n');
00141
00142 $Folder = new Folder($this->path . $pluginPath);
00143 $directories = array('models' . DS . 'behaviors', 'controllers' . DS . 'components', 'views' . DS . 'helpers');
00144
00145 foreach ($directories as $directory) {
00146 $Folder->create($this->path . $pluginPath . DS . $directory);
00147 }
00148
00149 if (strtolower($verbose) == 'y' || strtolower($verbose) == 'yes') {
00150 foreach ($Folder->messages() as $message) {
00151 $this->out($message);
00152 }
00153 }
00154
00155 $errors = $Folder->errors();
00156 if (!empty($errors)) {
00157 return false;
00158 }
00159
00160 $controllerFileName = $pluginPath . '_app_controller.php';
00161
00162 $out = "<?php\n\n";
00163 $out .= "class {$plugin}AppController extends AppController {\n\n";
00164 $out .= "}\n\n";
00165 $out .= "?>";
00166 $this->createFile($this->path . $pluginPath. DS . $controllerFileName, $out);
00167
00168 $modelFileName = $pluginPath . '_app_model.php';
00169
00170 $out = "<?php\n\n";
00171 $out .= "class {$plugin}AppModel extends AppModel {\n\n";
00172 $out .= "}\n\n";
00173 $out .= "?>";
00174 $this->createFile($this->path . $pluginPath . DS . $modelFileName, $out);
00175
00176 $this->hr();
00177 $this->out(sprintf(__("Created: %s in %s", true), $plugin, $this->path . $pluginPath));
00178 $this->hr();
00179 }
00180
00181 return true;
00182 }
00183
00184
00185
00186
00187
00188
00189 function help() {
00190 $this->hr();
00191 $this->out("Usage: cake bake plugin <arg1> <arg2>...");
00192 $this->hr();
00193 $this->out('Commands:');
00194 $this->out("\n\tplugin <name>\n\t\tbakes plugin directory structure");
00195 $this->out("\n\tplugin <name> model\n\t\tbakes model. Run 'cake bake model help' for more info.");
00196 $this->out("\n\tplugin <name> controller\n\t\tbakes controller. Run 'cake bake controller help' for more info.");
00197 $this->out("\n\tplugin <name> view\n\t\tbakes view. Run 'cake bake view help' for more info.");
00198 $this->out("");
00199 $this->_stop();
00200 }
00201 }
00202 ?>