PageRenderTime 47ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/cake/console/libs/tasks/controller.php

https://github.com/ata/internal
PHP | 585 lines | 432 code | 42 blank | 111 comment | 134 complexity | acfc673e3c2b38413cb8fd41544b6edb MD5 | raw file
  1. <?php
  2. /* SVN FILE: $Id$ */
  3. /**
  4. * The ControllerTask handles creating and updating controller files.
  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-2010, Cake Software Foundation, Inc.
  12. *
  13. * Licensed under The MIT License
  14. * Redistributions of files must retain the above copyright notice.
  15. *
  16. * @filesource
  17. * @copyright Copyright 2005-2010, 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$
  23. * @modifiedby $LastChangedBy$
  24. * @lastmodified $Date$
  25. * @license http://www.opensource.org/licenses/mit-license.php The MIT License
  26. */
  27. /**
  28. * Task class for creating and updating controller files.
  29. *
  30. * @package cake
  31. * @subpackage cake.cake.console.libs.tasks
  32. */
  33. class ControllerTask extends Shell {
  34. /**
  35. * Name of plugin
  36. *
  37. * @var string
  38. * @access public
  39. */
  40. var $plugin = null;
  41. /**
  42. * Tasks to be loaded by this Task
  43. *
  44. * @var array
  45. * @access public
  46. */
  47. var $tasks = array('Project');
  48. /**
  49. * path to CONTROLLERS directory
  50. *
  51. * @var array
  52. * @access public
  53. */
  54. var $path = CONTROLLERS;
  55. /**
  56. * Override initialize
  57. *
  58. * @access public
  59. */
  60. function initialize() {
  61. }
  62. /**
  63. * Execution method always used for tasks
  64. *
  65. * @access public
  66. */
  67. function execute() {
  68. if (empty($this->args)) {
  69. $this->__interactive();
  70. }
  71. if (isset($this->args[0])) {
  72. $controller = Inflector::camelize($this->args[0]);
  73. $actions = null;
  74. if (isset($this->args[1]) && $this->args[1] == 'scaffold') {
  75. $this->out('Baking scaffold for ' . $controller);
  76. $actions = $this->bakeActions($controller);
  77. } else {
  78. $actions = 'scaffold';
  79. }
  80. if ((isset($this->args[1]) && $this->args[1] == 'admin') || (isset($this->args[2]) && $this->args[2] == 'admin')) {
  81. if ($admin = $this->getAdmin()) {
  82. $this->out('Adding ' . Configure::read('Routing.admin') .' methods');
  83. if ($actions == 'scaffold') {
  84. $actions = $this->bakeActions($controller, $admin);
  85. } else {
  86. $actions .= $this->bakeActions($controller, $admin);
  87. }
  88. }
  89. }
  90. if ($this->bake($controller, $actions)) {
  91. if ($this->_checkUnitTest()) {
  92. $this->bakeTest($controller);
  93. }
  94. }
  95. }
  96. }
  97. /**
  98. * Interactive
  99. *
  100. * @access private
  101. */
  102. function __interactive($controllerName = false) {
  103. if (!$controllerName) {
  104. $this->interactive = true;
  105. $this->hr();
  106. $this->out(sprintf("Bake Controller\nPath: %s", $this->path));
  107. $this->hr();
  108. $actions = '';
  109. $uses = array();
  110. $helpers = array();
  111. $components = array();
  112. $wannaUseSession = 'y';
  113. $wannaDoAdmin = 'n';
  114. $wannaUseScaffold = 'n';
  115. $wannaDoScaffolding = 'y';
  116. $controllerName = $this->getName();
  117. }
  118. $this->hr();
  119. $this->out("Baking {$controllerName}Controller");
  120. $this->hr();
  121. $controllerFile = strtolower(Inflector::underscore($controllerName));
  122. $question[] = __("Would you like to build your controller interactively?", true);
  123. if (file_exists($this->path . $controllerFile .'_controller.php')) {
  124. $question[] = sprintf(__("Warning: Choosing no will overwrite the %sController.", true), $controllerName);
  125. }
  126. $doItInteractive = $this->in(implode("\n", $question), array('y','n'), 'y');
  127. if (strtolower($doItInteractive) == 'y' || strtolower($doItInteractive) == 'yes') {
  128. $this->interactive = true;
  129. $wannaUseScaffold = $this->in(__("Would you like to use scaffolding?", true), array('y','n'), 'n');
  130. if (strtolower($wannaUseScaffold) == 'n' || strtolower($wannaUseScaffold) == 'no') {
  131. $wannaDoScaffolding = $this->in(__("Would you like to include some basic class methods (index(), add(), view(), edit())?", true), array('y','n'), 'n');
  132. if (strtolower($wannaDoScaffolding) == 'y' || strtolower($wannaDoScaffolding) == 'yes') {
  133. $wannaDoAdmin = $this->in(__("Would you like to create the methods for admin routing?", true), array('y','n'), 'n');
  134. }
  135. $wannaDoHelpers = $this->in(__("Would you like this controller to use other helpers besides HtmlHelper and FormHelper?", true), array('y','n'), 'n');
  136. if (strtolower($wannaDoHelpers) == 'y' || strtolower($wannaDoHelpers) == 'yes') {
  137. $helpersList = $this->in(__("Please provide a comma separated list of the other helper names you'd like to use.\nExample: 'Ajax, Javascript, Time'", true));
  138. $helpersListTrimmed = str_replace(' ', '', $helpersList);
  139. $helpers = explode(',', $helpersListTrimmed);
  140. }
  141. $wannaDoComponents = $this->in(__("Would you like this controller to use any components?", true), array('y','n'), 'n');
  142. if (strtolower($wannaDoComponents) == 'y' || strtolower($wannaDoComponents) == 'yes') {
  143. $componentsList = $this->in(__("Please provide a comma separated list of the component names you'd like to use.\nExample: 'Acl, Security, RequestHandler'", true));
  144. $componentsListTrimmed = str_replace(' ', '', $componentsList);
  145. $components = explode(',', $componentsListTrimmed);
  146. }
  147. $wannaUseSession = $this->in(__("Would you like to use Sessions?", true), array('y','n'), 'y');
  148. } else {
  149. $wannaDoScaffolding = 'n';
  150. }
  151. } else {
  152. $wannaDoScaffolding = $this->in(__("Would you like to include some basic class methods (index(), add(), view(), edit())?", true), array('y','n'), 'y');
  153. if (strtolower($wannaDoScaffolding) == 'y' || strtolower($wannaDoScaffolding) == 'yes') {
  154. $wannaDoAdmin = $this->in(__("Would you like to create the methods for admin routing?", true), array('y','n'), 'y');
  155. }
  156. }
  157. $admin = false;
  158. if ((strtolower($wannaDoAdmin) == 'y' || strtolower($wannaDoAdmin) == 'yes')) {
  159. $admin = $this->getAdmin();
  160. }
  161. if (strtolower($wannaDoScaffolding) == 'y' || strtolower($wannaDoScaffolding) == 'yes') {
  162. $actions = $this->bakeActions($controllerName, null, in_array(strtolower($wannaUseSession), array('y', 'yes')));
  163. if ($admin) {
  164. $actions .= $this->bakeActions($controllerName, $admin, in_array(strtolower($wannaUseSession), array('y', 'yes')));
  165. }
  166. }
  167. if ($this->interactive === true) {
  168. $this->out('');
  169. $this->hr();
  170. $this->out('The following controller will be created:');
  171. $this->hr();
  172. $this->out("Controller Name: $controllerName");
  173. if (strtolower($wannaUseScaffold) == 'y' || strtolower($wannaUseScaffold) == 'yes') {
  174. $this->out(" var \$scaffold;");
  175. $actions = 'scaffold';
  176. }
  177. if (count($helpers)) {
  178. $this->out("Helpers: ", false);
  179. foreach ($helpers as $help) {
  180. if ($help != $helpers[count($helpers) - 1]) {
  181. $this->out(ucfirst($help) . ", ", false);
  182. } else {
  183. $this->out(ucfirst($help));
  184. }
  185. }
  186. }
  187. if (count($components)) {
  188. $this->out("Components: ", false);
  189. foreach ($components as $comp) {
  190. if ($comp != $components[count($components) - 1]) {
  191. $this->out(ucfirst($comp) . ", ", false);
  192. } else {
  193. $this->out(ucfirst($comp));
  194. }
  195. }
  196. }
  197. $this->hr();
  198. $looksGood = $this->in(__('Look okay?', true), array('y','n'), 'y');
  199. if (strtolower($looksGood) == 'y' || strtolower($looksGood) == 'yes') {
  200. $baked = $this->bake($controllerName, $actions, $helpers, $components, $uses);
  201. if ($baked && $this->_checkUnitTest()) {
  202. $this->bakeTest($controllerName);
  203. }
  204. } else {
  205. $this->__interactive($controllerName);
  206. }
  207. } else {
  208. $baked = $this->bake($controllerName, $actions, $helpers, $components, $uses);
  209. if ($baked && $this->_checkUnitTest()) {
  210. $this->bakeTest($controllerName);
  211. }
  212. }
  213. }
  214. /**
  215. * Bake scaffold actions
  216. *
  217. * @param string $controllerName Controller name
  218. * @param string $admin Admin route to use
  219. * @param boolean $wannaUseSession Set to true to use sessions, false otherwise
  220. * @return string Baked actions
  221. * @access private
  222. */
  223. function bakeActions($controllerName, $admin = null, $wannaUseSession = true) {
  224. $currentModelName = $modelImport = $this->_modelName($controllerName);
  225. if ($this->plugin) {
  226. $modelImport = $this->plugin . '.' . $modelImport;
  227. }
  228. if (!App::import('Model', $modelImport)) {
  229. $this->err(__('You must have a model for this class to build scaffold methods. Please try again.', true));
  230. exit;
  231. }
  232. $actions = null;
  233. $modelObj =& ClassRegistry::init($currentModelName);
  234. $controllerPath = $this->_controllerPath($controllerName);
  235. $pluralName = $this->_pluralName($currentModelName);
  236. $singularName = Inflector::variable($currentModelName);
  237. $singularHumanName = Inflector::humanize($currentModelName);
  238. $pluralHumanName = Inflector::humanize($controllerName);
  239. $actions .= "\n";
  240. $actions .= "\tfunction {$admin}index() {\n";
  241. $actions .= "\t\t\$this->{$currentModelName}->recursive = 0;\n";
  242. $actions .= "\t\t\$this->set('{$pluralName}', \$this->paginate());\n";
  243. $actions .= "\t}\n";
  244. $actions .= "\n";
  245. $actions .= "\tfunction {$admin}view(\$id = null) {\n";
  246. $actions .= "\t\tif (!\$id) {\n";
  247. if ($wannaUseSession) {
  248. $actions .= "\t\t\t\$this->Session->setFlash(__('Invalid {$singularHumanName}', true));\n";
  249. $actions .= "\t\t\t\$this->redirect(array('action' => 'index'));\n";
  250. } else {
  251. $actions .= "\t\t\t\$this->flash(__('Invalid {$singularHumanName}', true), array('action' => 'index'));\n";
  252. }
  253. $actions .= "\t\t}\n";
  254. $actions .= "\t\t\$this->set('" . $singularName . "', \$this->{$currentModelName}->read(null, \$id));\n";
  255. $actions .= "\t}\n";
  256. $actions .= "\n";
  257. /* ADD ACTION */
  258. $compact = array();
  259. $actions .= "\tfunction {$admin}add() {\n";
  260. $actions .= "\t\tif (!empty(\$this->data)) {\n";
  261. $actions .= "\t\t\t\$this->{$currentModelName}->create();\n";
  262. $actions .= "\t\t\tif (\$this->{$currentModelName}->save(\$this->data)) {\n";
  263. if ($wannaUseSession) {
  264. $actions .= "\t\t\t\t\$this->Session->setFlash(__('The " . $singularHumanName . " has been saved', true));\n";
  265. $actions .= "\t\t\t\t\$this->redirect(array('action' => 'index'));\n";
  266. } else {
  267. $actions .= "\t\t\t\t\$this->flash(__('{$currentModelName} saved.', true), array('action' => 'index'));\n";
  268. }
  269. $actions .= "\t\t\t} else {\n";
  270. if ($wannaUseSession) {
  271. $actions .= "\t\t\t\t\$this->Session->setFlash(__('The {$singularHumanName} could not be saved. Please, try again.', true));\n";
  272. }
  273. $actions .= "\t\t\t}\n";
  274. $actions .= "\t\t}\n";
  275. foreach ($modelObj->hasAndBelongsToMany as $associationName => $relation) {
  276. if (!empty($associationName)) {
  277. $habtmModelName = $this->_modelName($associationName);
  278. $habtmSingularName = $this->_singularName($associationName);
  279. $habtmPluralName = $this->_pluralName($associationName);
  280. $actions .= "\t\t\${$habtmPluralName} = \$this->{$currentModelName}->{$habtmModelName}->find('list');\n";
  281. $compact[] = "'{$habtmPluralName}'";
  282. }
  283. }
  284. foreach ($modelObj->belongsTo as $associationName => $relation) {
  285. if (!empty($associationName)) {
  286. $belongsToModelName = $this->_modelName($associationName);
  287. $belongsToPluralName = $this->_pluralName($associationName);
  288. $actions .= "\t\t\${$belongsToPluralName} = \$this->{$currentModelName}->{$belongsToModelName}->find('list');\n";
  289. $compact[] = "'{$belongsToPluralName}'";
  290. }
  291. }
  292. if (!empty($compact)) {
  293. $actions .= "\t\t\$this->set(compact(" . implode(', ', $compact) . "));\n";
  294. }
  295. $actions .= "\t}\n";
  296. $actions .= "\n";
  297. /* EDIT ACTION */
  298. $compact = array();
  299. $actions .= "\tfunction {$admin}edit(\$id = null) {\n";
  300. $actions .= "\t\tif (!\$id && empty(\$this->data)) {\n";
  301. if ($wannaUseSession) {
  302. $actions .= "\t\t\t\$this->Session->setFlash(__('Invalid {$singularHumanName}', true));\n";
  303. $actions .= "\t\t\t\$this->redirect(array('action' => 'index'));\n";
  304. } else {
  305. $actions .= "\t\t\t\$this->flash(__('Invalid {$singularHumanName}', true), array('action' => 'index'));\n";
  306. }
  307. $actions .= "\t\t}\n";
  308. $actions .= "\t\tif (!empty(\$this->data)) {\n";
  309. $actions .= "\t\t\tif (\$this->{$currentModelName}->save(\$this->data)) {\n";
  310. if ($wannaUseSession) {
  311. $actions .= "\t\t\t\t\$this->Session->setFlash(__('The " . $singularHumanName . " has been saved', true));\n";
  312. $actions .= "\t\t\t\t\$this->redirect(array('action' => 'index'));\n";
  313. } else {
  314. $actions .= "\t\t\t\t\$this->flash(__('The " . $singularHumanName . " has been saved.', true), array('action' => 'index'));\n";
  315. }
  316. $actions .= "\t\t\t} else {\n";
  317. if ($wannaUseSession) {
  318. $actions .= "\t\t\t\t\$this->Session->setFlash(__('The {$singularHumanName} could not be saved. Please, try again.', true));\n";
  319. }
  320. $actions .= "\t\t\t}\n";
  321. $actions .= "\t\t}\n";
  322. $actions .= "\t\tif (empty(\$this->data)) {\n";
  323. $actions .= "\t\t\t\$this->data = \$this->{$currentModelName}->read(null, \$id);\n";
  324. $actions .= "\t\t}\n";
  325. foreach ($modelObj->hasAndBelongsToMany as $associationName => $relation) {
  326. if (!empty($associationName)) {
  327. $habtmModelName = $this->_modelName($associationName);
  328. $habtmSingularName = $this->_singularName($associationName);
  329. $habtmPluralName = $this->_pluralName($associationName);
  330. $actions .= "\t\t\${$habtmPluralName} = \$this->{$currentModelName}->{$habtmModelName}->find('list');\n";
  331. $compact[] = "'{$habtmPluralName}'";
  332. }
  333. }
  334. foreach ($modelObj->belongsTo as $associationName => $relation) {
  335. if (!empty($associationName)) {
  336. $belongsToModelName = $this->_modelName($associationName);
  337. $belongsToPluralName = $this->_pluralName($associationName);
  338. $actions .= "\t\t\${$belongsToPluralName} = \$this->{$currentModelName}->{$belongsToModelName}->find('list');\n";
  339. $compact[] = "'{$belongsToPluralName}'";
  340. }
  341. }
  342. if (!empty($compact)) {
  343. $actions .= "\t\t\$this->set(compact(" . implode(',', $compact) . "));\n";
  344. }
  345. $actions .= "\t}\n";
  346. $actions .= "\n";
  347. $actions .= "\tfunction {$admin}delete(\$id = null) {\n";
  348. $actions .= "\t\tif (!\$id) {\n";
  349. if ($wannaUseSession) {
  350. $actions .= "\t\t\t\$this->Session->setFlash(__('Invalid id for {$singularHumanName}', true));\n";
  351. $actions .= "\t\t\t\$this->redirect(array('action' => 'index'));\n";
  352. } else {
  353. $actions .= "\t\t\t\$this->flash(__('Invalid {$singularHumanName}', true), array('action' => 'index'));\n";
  354. }
  355. $actions .= "\t\t}\n";
  356. $actions .= "\t\tif (\$this->{$currentModelName}->del(\$id)) {\n";
  357. if ($wannaUseSession) {
  358. $actions .= "\t\t\t\$this->Session->setFlash(__('{$singularHumanName} deleted', true));\n";
  359. $actions .= "\t\t\t\$this->redirect(array('action' => 'index'));\n";
  360. } else {
  361. $actions .= "\t\t\t\$this->flash(__('{$singularHumanName} deleted', true), array('action' => 'index'));\n";
  362. }
  363. $actions .= "\t\t}\n";
  364. if ($wannaUseSession) {
  365. $actions .= "\t\t\$this->Session->setFlash(__('The {$singularHumanName} could not be deleted. Please, try again.', true));\n";
  366. $actions .= "\t\t\$this->redirect(array('action' => 'index'));\n";
  367. } else {
  368. $actions .= "\t\t\$this->flash(__('The {$singularHumanName} could not be deleted. Please, try again.', true), array('action' => 'index'));\n";
  369. }
  370. $actions .= "\t}\n";
  371. $actions .= "\n";
  372. return $actions;
  373. }
  374. /**
  375. * Assembles and writes a Controller file
  376. *
  377. * @param string $controllerName Controller name
  378. * @param string $actions Actions to add, or set the whole controller to use $scaffold (set $actions to 'scaffold')
  379. * @param array $helpers Helpers to use in controller
  380. * @param array $components Components to use in controller
  381. * @param array $uses Models to use in controller
  382. * @return string Baked controller
  383. * @access private
  384. */
  385. function bake($controllerName, $actions = '', $helpers = null, $components = null, $uses = null) {
  386. $out = "<?php\n";
  387. $out .= "class $controllerName" . "Controller extends {$this->plugin}AppController {\n\n";
  388. $out .= "\tvar \$name = '$controllerName';\n";
  389. if (strtolower($actions) == 'scaffold') {
  390. $out .= "\tvar \$scaffold;\n";
  391. } else {
  392. if (count($uses)) {
  393. $out .= "\tvar \$uses = array('" . $this->_modelName($controllerName) . "', ";
  394. foreach ($uses as $use) {
  395. if ($use != $uses[count($uses) - 1]) {
  396. $out .= "'" . $this->_modelName($use) . "', ";
  397. } else {
  398. $out .= "'" . $this->_modelName($use) . "'";
  399. }
  400. }
  401. $out .= ");\n";
  402. }
  403. $out .= "\tvar \$helpers = array('Html', 'Form'";
  404. if (count($helpers)) {
  405. foreach ($helpers as $help) {
  406. $out .= ", '" . Inflector::camelize($help) . "'";
  407. }
  408. }
  409. $out .= ");\n";
  410. if (count($components)) {
  411. $out .= "\tvar \$components = array(";
  412. foreach ($components as $comp) {
  413. if ($comp != $components[count($components) - 1]) {
  414. $out .= "'" . Inflector::camelize($comp) . "', ";
  415. } else {
  416. $out .= "'" . Inflector::camelize($comp) . "'";
  417. }
  418. }
  419. $out .= ");\n";
  420. }
  421. $out .= $actions;
  422. }
  423. $out .= "}\n";
  424. $out .= "?>";
  425. $filename = $this->path . $this->_controllerPath($controllerName) . '_controller.php';
  426. return $this->createFile($filename, $out);
  427. }
  428. /**
  429. * Assembles and writes a unit test file
  430. *
  431. * @param string $className Controller class name
  432. * @return string Baked test
  433. * @access private
  434. */
  435. function bakeTest($className) {
  436. $import = $className;
  437. if ($this->plugin) {
  438. $import = $this->plugin . '.' . $className;
  439. }
  440. $out = "App::import('Controller', '$import');\n\n";
  441. $out .= "class Test{$className} extends {$className}Controller {\n";
  442. $out .= "\tvar \$autoRender = false;\n}\n\n";
  443. $out .= "class {$className}ControllerTest extends CakeTestCase {\n";
  444. $out .= "\tvar \${$className} = null;\n\n";
  445. $out .= "\tfunction startTest() {\n\t\t\$this->{$className} = new Test{$className}();";
  446. $out .= "\n\t\t\$this->{$className}->constructClasses();\n\t}\n\n";
  447. $out .= "\tfunction test{$className}ControllerInstance() {\n";
  448. $out .= "\t\t\$this->assertTrue(is_a(\$this->{$className}, '{$className}Controller'));\n\t}\n\n";
  449. $out .= "\tfunction endTest() {\n\t\tunset(\$this->{$className});\n\t}\n}\n";
  450. $path = CONTROLLER_TESTS;
  451. if (isset($this->plugin)) {
  452. $pluginPath = 'plugins' . DS . Inflector::underscore($this->plugin) . DS;
  453. $path = APP . $pluginPath . 'tests' . DS . 'cases' . DS . 'controllers' . DS;
  454. }
  455. $filename = Inflector::underscore($className).'_controller.test.php';
  456. $this->out("\nBaking unit test for $className...");
  457. $header = '$Id';
  458. $content = "<?php \n/* SVN FILE: $header$ */\n/* " . $className . "Controller Test cases generated on: " . date('Y-m-d H:i:s') . " : ". time() . "*/\n{$out}?>";
  459. return $this->createFile($path . $filename, $content);
  460. }
  461. /**
  462. * Outputs and gets the list of possible models or controllers from database
  463. *
  464. * @param string $useDbConfig Database configuration name
  465. * @return array Set of controllers
  466. * @access public
  467. */
  468. function listAll($useDbConfig = 'default') {
  469. $db =& ConnectionManager::getDataSource($useDbConfig);
  470. $usePrefix = empty($db->config['prefix']) ? '' : $db->config['prefix'];
  471. if ($usePrefix) {
  472. $tables = array();
  473. foreach ($db->listSources() as $table) {
  474. if (!strncmp($table, $usePrefix, strlen($usePrefix))) {
  475. $tables[] = substr($table, strlen($usePrefix));
  476. }
  477. }
  478. } else {
  479. $tables = $db->listSources();
  480. }
  481. if (empty($tables)) {
  482. $this->err(__('Your database does not have any tables.', true));
  483. $this->_stop();
  484. }
  485. $this->__tables = $tables;
  486. $this->out('Possible Controllers based on your current database:');
  487. $this->_controllerNames = array();
  488. $count = count($tables);
  489. for ($i = 0; $i < $count; $i++) {
  490. $this->_controllerNames[] = $this->_controllerName($this->_modelName($tables[$i]));
  491. $this->out($i + 1 . ". " . $this->_controllerNames[$i]);
  492. }
  493. return $this->_controllerNames;
  494. }
  495. /**
  496. * Forces the user to specify the controller he wants to bake, and returns the selected controller name.
  497. *
  498. * @return string Controller name
  499. * @access public
  500. */
  501. function getName() {
  502. $useDbConfig = 'default';
  503. $controllers = $this->listAll($useDbConfig, 'Controllers');
  504. $enteredController = '';
  505. while ($enteredController == '') {
  506. $enteredController = $this->in(__("Enter a number from the list above, type in the name of another controller, or 'q' to exit", true), null, 'q');
  507. if ($enteredController === 'q') {
  508. $this->out(__("Exit", true));
  509. $this->_stop();
  510. }
  511. if ($enteredController == '' || intval($enteredController) > count($controllers)) {
  512. $this->out(__('Error:', true));
  513. $this->out(__("The Controller name you supplied was empty, or the number \nyou selected was not an option. Please try again.", true));
  514. $enteredController = '';
  515. }
  516. }
  517. if (intval($enteredController) > 0 && intval($enteredController) <= count($controllers) ) {
  518. $controllerName = $controllers[intval($enteredController) - 1];
  519. } else {
  520. $controllerName = Inflector::camelize($enteredController);
  521. }
  522. return $controllerName;
  523. }
  524. /**
  525. * Displays help contents
  526. *
  527. * @access public
  528. */
  529. function help() {
  530. $this->hr();
  531. $this->out("Usage: cake bake controller <arg1> <arg2>...");
  532. $this->hr();
  533. $this->out('Commands:');
  534. $this->out("\n\tcontroller <name>\n\t\tbakes controller with var \$scaffold");
  535. $this->out("\n\tcontroller <name> scaffold\n\t\tbakes controller with scaffold actions.\n\t\t(index, view, add, edit, delete)");
  536. $this->out("\n\tcontroller <name> scaffold admin\n\t\tbakes a controller with scaffold actions for both public and Configure::read('Routing.admin')");
  537. $this->out("\n\tcontroller <name> admin\n\t\tbakes a controller with scaffold actions only for Configure::read('Routing.admin')");
  538. $this->out("");
  539. $this->_stop();
  540. }
  541. }
  542. ?>