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