| 1 |
lars |
1 |
<?php
|
|
|
2 |
/* SVN FILE: $Id: plugin.php 7945 2008-12-19 02:16:01Z gwoo $ */
|
|
|
3 |
/**
|
|
|
4 |
* The Plugin Task handles creating an empty plugin, ready to be used
|
|
|
5 |
*
|
|
|
6 |
* Long description for file
|
|
|
7 |
*
|
|
|
8 |
* PHP versions 4 and 5
|
|
|
9 |
*
|
|
|
10 |
* CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
|
|
|
11 |
* Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
|
|
12 |
*
|
|
|
13 |
* Licensed under The MIT License
|
|
|
14 |
* Redistributions of files must retain the above copyright notice.
|
|
|
15 |
*
|
|
|
16 |
* @filesource
|
|
|
17 |
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
|
|
18 |
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
|
|
|
19 |
* @package cake
|
|
|
20 |
* @subpackage cake.cake.console.libs.tasks
|
|
|
21 |
* @since CakePHP(tm) v 1.2
|
|
|
22 |
* @version $Revision: 7945 $
|
|
|
23 |
* @modifiedby $LastChangedBy: gwoo $
|
|
|
24 |
* @lastmodified $Date: 2008-12-18 18:16:01 -0800 (Thu, 18 Dec 2008) $
|
|
|
25 |
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
|
|
26 |
*/
|
|
|
27 |
if (!class_exists('File')) {
|
|
|
28 |
uses('file');
|
|
|
29 |
}
|
|
|
30 |
/**
|
|
|
31 |
* Task class for creating a plugin
|
|
|
32 |
*
|
|
|
33 |
* @package cake
|
|
|
34 |
* @subpackage cake.cake.console.libs.tasks
|
|
|
35 |
*/
|
|
|
36 |
class PluginTask extends Shell {
|
|
|
37 |
/**
|
|
|
38 |
* Tasks
|
|
|
39 |
*
|
|
|
40 |
*/
|
|
|
41 |
var $tasks = array('Model', 'Controller', 'View');
|
|
|
42 |
/**
|
|
|
43 |
* path to CONTROLLERS directory
|
|
|
44 |
*
|
|
|
45 |
* @var array
|
|
|
46 |
* @access public
|
|
|
47 |
*/
|
|
|
48 |
var $path = null;
|
|
|
49 |
/**
|
|
|
50 |
* initialize
|
|
|
51 |
*
|
|
|
52 |
* @return void
|
|
|
53 |
*/
|
|
|
54 |
function initialize() {
|
|
|
55 |
$this->path = APP . 'plugins' . DS;
|
|
|
56 |
}
|
|
|
57 |
/**
|
|
|
58 |
* Execution method always used for tasks
|
|
|
59 |
*
|
|
|
60 |
* @return void
|
|
|
61 |
*/
|
|
|
62 |
function execute() {
|
|
|
63 |
if (empty($this->params['skel'])) {
|
|
|
64 |
$this->params['skel'] = '';
|
|
|
65 |
if (is_dir(CAKE_CORE_INCLUDE_PATH.DS.'cake'.DS.'console'.DS.'libs'.DS.'templates'.DS.'skel') === true) {
|
|
|
66 |
$this->params['skel'] = CAKE_CORE_INCLUDE_PATH.DS.'cake'.DS.'console'.DS.'libs'.DS.'templates'.DS.'skel';
|
|
|
67 |
}
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
$plugin = null;
|
|
|
71 |
|
|
|
72 |
if (isset($this->args[0])) {
|
|
|
73 |
$plugin = Inflector::camelize($this->args[0]);
|
|
|
74 |
$pluginPath = Inflector::underscore($plugin) . DS;
|
|
|
75 |
$this->Dispatch->shiftArgs();
|
|
|
76 |
if (is_dir($this->path . $pluginPath)) {
|
|
|
77 |
$this->out(sprintf('Plugin: %s', $plugin));
|
|
|
78 |
$this->out(sprintf('Path: %s', $this->path . $pluginPath));
|
|
|
79 |
$this->hr();
|
|
|
80 |
} elseif (isset($this->args[0])) {
|
|
|
81 |
$this->err(sprintf('%s in path %s not found.', $plugin, $this->path . $pluginPath));
|
|
|
82 |
$this->_stop();
|
|
|
83 |
} else {
|
|
|
84 |
$this->__interactive($plugin);
|
|
|
85 |
}
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
if (isset($this->args[0])) {
|
|
|
89 |
$task = Inflector::classify($this->args[0]);
|
|
|
90 |
$this->Dispatch->shiftArgs();
|
|
|
91 |
if (in_array($task, $this->tasks)) {
|
|
|
92 |
$this->{$task}->plugin = $plugin;
|
|
|
93 |
$this->{$task}->path = $this->path . $pluginPath . Inflector::underscore(Inflector::pluralize($task)) . DS;
|
|
|
94 |
|
|
|
95 |
if (!is_dir($this->{$task}->path)) {
|
|
|
96 |
$this->err(sprintf(__("%s directory could not be found.\nBe sure you have created %s", true), $task, $this->{$task}->path));
|
|
|
97 |
}
|
|
|
98 |
$this->{$task}->loadTasks();
|
|
|
99 |
$this->{$task}->execute();
|
|
|
100 |
}
|
|
|
101 |
}
|
|
|
102 |
}
|
|
|
103 |
|
|
|
104 |
/**
|
|
|
105 |
* Interactive interface
|
|
|
106 |
*
|
|
|
107 |
* @access private
|
|
|
108 |
* @return void
|
|
|
109 |
*/
|
|
|
110 |
function __interactive($plugin = null) {
|
|
|
111 |
while ($plugin === null) {
|
|
|
112 |
$plugin = $this->in(__('Enter the name of the plugin in CamelCase format', true));
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
if (!$this->bake($plugin)) {
|
|
|
116 |
$this->err(sprintf(__("An error occured trying to bake: %s in %s", true), $plugin, $this->path . $pluginPath));
|
|
|
117 |
}
|
|
|
118 |
}
|
|
|
119 |
|
|
|
120 |
/**
|
|
|
121 |
* Bake the plugin, create directories and files
|
|
|
122 |
*
|
|
|
123 |
* @params $plugin name of the plugin in CamelCased format
|
|
|
124 |
* @access public
|
|
|
125 |
* @return bool
|
|
|
126 |
*/
|
|
|
127 |
function bake($plugin) {
|
|
|
128 |
|
|
|
129 |
$pluginPath = Inflector::underscore($plugin);
|
|
|
130 |
|
|
|
131 |
$this->hr();
|
|
|
132 |
$this->out("Plugin Name: $plugin");
|
|
|
133 |
$this->out("Plugin Directory: {$this->path}{$pluginPath}");
|
|
|
134 |
$this->hr();
|
|
|
135 |
|
|
|
136 |
|
|
|
137 |
$looksGood = $this->in('Look okay?', array('y', 'n', 'q'), 'y');
|
|
|
138 |
|
|
|
139 |
if (low($looksGood) == 'y' || low($looksGood) == 'yes') {
|
|
|
140 |
$verbose = $this->in(__('Do you want verbose output?', true), array('y', 'n'), 'n');
|
|
|
141 |
|
|
|
142 |
$Folder = new Folder($this->path . $pluginPath);
|
|
|
143 |
$directories = array('models' . DS . 'behaviors', 'controllers' . DS . 'components', 'views' . DS . 'helpers');
|
|
|
144 |
|
|
|
145 |
foreach ($directories as $directory) {
|
|
|
146 |
$Folder->create($this->path . $pluginPath . DS . $directory);
|
|
|
147 |
}
|
|
|
148 |
|
|
|
149 |
if (low($verbose) == 'y' || low($verbose) == 'yes') {
|
|
|
150 |
foreach ($Folder->messages() as $message) {
|
|
|
151 |
$this->out($message);
|
|
|
152 |
}
|
|
|
153 |
}
|
|
|
154 |
|
|
|
155 |
$errors = $Folder->errors();
|
|
|
156 |
if (!empty($errors)) {
|
|
|
157 |
return false;
|
|
|
158 |
}
|
|
|
159 |
|
|
|
160 |
$controllerFileName = $pluginPath . '_app_controller.php';
|
|
|
161 |
|
|
|
162 |
$out = "<?php\n\n";
|
|
|
163 |
$out .= "class {$plugin}AppController extends AppController {\n\n";
|
|
|
164 |
$out .= "}\n\n";
|
|
|
165 |
$out .= "?>";
|
|
|
166 |
$this->createFile($this->path . $pluginPath. DS . $controllerFileName, $out);
|
|
|
167 |
|
|
|
168 |
$modelFileName = $pluginPath . '_app_model.php';
|
|
|
169 |
|
|
|
170 |
$out = "<?php\n\n";
|
|
|
171 |
$out .= "class {$plugin}AppModel extends AppModel {\n\n";
|
|
|
172 |
$out .= "}\n\n";
|
|
|
173 |
$out .= "?>";
|
|
|
174 |
$this->createFile($this->path . $pluginPath . DS . $modelFileName, $out);
|
|
|
175 |
|
|
|
176 |
$this->hr();
|
|
|
177 |
$this->out(sprintf(__("Created: %s in %s", true), $plugin, $this->path . $pluginPath));
|
|
|
178 |
$this->hr();
|
|
|
179 |
}
|
|
|
180 |
|
|
|
181 |
return true;
|
|
|
182 |
}
|
|
|
183 |
/**
|
|
|
184 |
* Help
|
|
|
185 |
*
|
|
|
186 |
* @return void
|
|
|
187 |
* @access public
|
|
|
188 |
*/
|
|
|
189 |
function help() {
|
|
|
190 |
$this->hr();
|
|
|
191 |
$this->out("Usage: cake bake plugin <arg1> <arg2>...");
|
|
|
192 |
$this->hr();
|
|
|
193 |
$this->out('Commands:');
|
|
|
194 |
$this->out("\n\tplugin <name>\n\t\tbakes plugin directory structure");
|
|
|
195 |
$this->out("\n\tplugin <name> model\n\t\tbakes model. Run 'cake bake model help' for more info.");
|
|
|
196 |
$this->out("\n\tplugin <name> controller\n\t\tbakes controller. Run 'cake bake controller help' for more info.");
|
|
|
197 |
$this->out("\n\tplugin <name> view\n\t\tbakes view. Run 'cake bake view help' for more info.");
|
|
|
198 |
$this->out("");
|
|
|
199 |
$this->_stop();
|
|
|
200 |
}
|
|
|
201 |
}
|
|
|
202 |
?>
|