mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-22 12:36:16 +00:00
91a1cf81f3
Conflicts: app/Config/acl.ini.php app/config/database.php.default app/webroot/css.php app/webroot/css/cake.generic.css cake/basics.php cake/bootstrap.php cake/config/paths.php cake/console/cake.php cake/console/error.php cake/console/libs/acl.php cake/console/libs/bake.php cake/console/libs/i18n.php cake/console/libs/shell.php cake/console/libs/tasks/extract.php cake/console/libs/tasks/plugin.php cake/console/libs/tasks/project.php cake/console/libs/testsuite.php cake/console/templates/default/classes/test.ctp cake/console/templates/default/views/home.ctp cake/console/templates/default/views/view.ctp cake/console/templates/skel/config/database.php.default cake/console/templates/skel/views/elements/email/text/default.ctp cake/console/templates/skel/webroot/css.php cake/dispatcher.php cake/libs/cache.php cake/libs/cake_session.php cake/libs/configure.php cake/libs/controller/component.php cake/libs/controller/components/auth.php cake/libs/controller/components/email.php cake/libs/controller/components/request_handler.php cake/libs/controller/components/security.php cake/libs/controller/controller.php cake/libs/controller/scaffold.php cake/libs/error.php cake/libs/magic_db.php cake/libs/model/behaviors/acl.php cake/libs/model/connection_manager.php cake/libs/model/datasources/dbo/dbo_mysqli.php cake/libs/model/model_behavior.php cake/libs/overloadable.php cake/libs/overloadable_php4.php cake/libs/overloadable_php5.php cake/libs/router.php cake/libs/view/errors/missing_action.ctp cake/libs/view/errors/missing_behavior_class.ctp cake/libs/view/errors/missing_behavior_file.ctp cake/libs/view/errors/missing_component_class.ctp cake/libs/view/errors/missing_component_file.ctp cake/libs/view/errors/missing_connection.ctp cake/libs/view/errors/missing_controller.ctp cake/libs/view/errors/missing_helper_class.ctp cake/libs/view/errors/missing_helper_file.ctp cake/libs/view/errors/missing_layout.ctp cake/libs/view/errors/missing_model.ctp cake/libs/view/errors/missing_scaffolddb.ctp cake/libs/view/errors/missing_table.ctp cake/libs/view/errors/missing_view.ctp cake/libs/view/errors/private_action.ctp cake/libs/view/errors/scaffold_error.ctp cake/libs/view/helpers/ajax.php cake/libs/view/helpers/javascript.php cake/libs/view/helpers/js.php cake/libs/view/helpers/session.php cake/libs/view/helpers/xml.php cake/libs/view/media.php cake/libs/view/pages/home.ctp cake/libs/view/scaffolds/edit.ctp cake/libs/view/scaffolds/index.ctp cake/libs/view/scaffolds/view.ctp cake/libs/view/view.php cake/libs/xml.php cake/tests/cases/console/cake.test.php cake/tests/cases/console/libs/acl.test.php cake/tests/cases/console/libs/api.test.php cake/tests/cases/console/libs/bake.test.php cake/tests/cases/console/libs/shell.test.php cake/tests/cases/console/libs/tasks/controller.test.php cake/tests/cases/console/libs/tasks/db_config.test.php cake/tests/cases/console/libs/tasks/fixture.test.php cake/tests/cases/console/libs/tasks/model.test.php cake/tests/cases/console/libs/tasks/plugin.test.php cake/tests/cases/console/libs/tasks/project.test.php cake/tests/cases/console/libs/tasks/test.test.php cake/tests/cases/console/libs/tasks/view.test.php cake/tests/cases/dispatcher.test.php cake/tests/cases/libs/cache/apc.test.php cake/tests/cases/libs/cake_session.test.php cake/tests/cases/libs/cake_test_case.test.php cake/tests/cases/libs/code_coverage_manager.test.php cake/tests/cases/libs/configure.test.php cake/tests/cases/libs/controller/component.test.php cake/tests/cases/libs/controller/components/auth.test.php cake/tests/cases/libs/controller/components/cookie.test.php cake/tests/cases/libs/controller/components/request_handler.test.php cake/tests/cases/libs/controller/components/session.test.php cake/tests/cases/libs/controller/controller.test.php cake/tests/cases/libs/controller/pages_controller.test.php cake/tests/cases/libs/error.test.php cake/tests/cases/libs/http_socket.test.php cake/tests/cases/libs/magic_db.test.php cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php cake/tests/cases/libs/model/datasources/dbo/dbo_mysqli.test.php cake/tests/cases/libs/model/datasources/dbo_source.test.php cake/tests/cases/libs/model/models.php cake/tests/cases/libs/overloadable.test.php cake/tests/cases/libs/test_manager.test.php cake/tests/cases/libs/view/helpers/ajax.test.php cake/tests/cases/libs/view/helpers/javascript.test.php cake/tests/cases/libs/view/helpers/session.test.php cake/tests/cases/libs/view/helpers/xml.test.php cake/tests/cases/libs/view/media.test.php cake/tests/cases/libs/view/theme.test.php cake/tests/cases/libs/xml.test.php cake/tests/fixtures/aco_fixture.php cake/tests/fixtures/translate_fixture.php cake/tests/groups/acl.group.php cake/tests/groups/bake.group.php cake/tests/groups/behaviors.group.php cake/tests/groups/cache.group.php cake/tests/groups/components.group.php cake/tests/groups/configure.group.php cake/tests/groups/console.group.php cake/tests/groups/controller.group.php cake/tests/groups/database.group.php cake/tests/groups/helpers.group.php cake/tests/groups/i18n.group.php cake/tests/groups/javascript.group.php cake/tests/groups/lib.group.php cake/tests/groups/model.group.php cake/tests/groups/no_cross_contamination.group.php cake/tests/groups/routing_system.group.php cake/tests/groups/socket.group.php cake/tests/groups/test_suite.group.php cake/tests/groups/view.group.php cake/tests/groups/xml.group.php cake/tests/lib/cake_test_case.php cake/tests/lib/cake_test_model.php cake/tests/lib/cake_test_suite_dispatcher.php cake/tests/lib/cake_web_test_case.php cake/tests/lib/code_coverage_manager.php cake/tests/lib/reporter/cake_base_reporter.php cake/tests/lib/reporter/cake_cli_reporter.php cake/tests/lib/reporter/cake_text_reporter.php cake/tests/lib/templates/menu.php cake/tests/lib/templates/simpletest.php cake/tests/lib/test_manager.php cake/tests/test_app/controllers/tests_apps_controller.php cake/tests/test_app/libs/cache/test_app_cache.php cake/tests/test_app/libs/library.php cake/tests/test_app/libs/log/test_app_log.php cake/tests/test_app/plugins/test_plugin/config/load.php cake/tests/test_app/plugins/test_plugin/config/more.load.php cake/tests/test_app/plugins/test_plugin/controllers/components/other_component.php cake/tests/test_app/plugins/test_plugin/controllers/components/plugins_component.php cake/tests/test_app/plugins/test_plugin/controllers/components/test_plugin_component.php cake/tests/test_app/plugins/test_plugin/controllers/components/test_plugin_other_component.php cake/tests/test_app/plugins/test_plugin/controllers/test_plugin_controller.php cake/tests/test_app/plugins/test_plugin/controllers/tests_controller.php cake/tests/test_app/plugins/test_plugin/libs/cache/test_plugin_cache.php cake/tests/test_app/plugins/test_plugin/libs/log/test_plugin_log.php cake/tests/test_app/plugins/test_plugin/libs/test_plugin_library.php cake/tests/test_app/plugins/test_plugin/test_plugin_app_controller.php cake/tests/test_app/plugins/test_plugin/test_plugin_app_model.php cake/tests/test_app/plugins/test_plugin/vendors/sample/sample_plugin.php cake/tests/test_app/plugins/test_plugin/vendors/welcome.php cake/tests/test_app/plugins/test_plugin/views/helpers/other_helper.php cake/tests/test_app/plugins/test_plugin/views/helpers/plugged_helper.php cake/tests/test_app/vendors/Test/MyTest.php cake/tests/test_app/vendors/Test/hello.php cake/tests/test_app/vendors/sample/configure_test_vendor_sample.php cake/tests/test_app/vendors/shells/sample.php cake/tests/test_app/vendors/somename/some.name.php cake/tests/test_app/vendors/welcome.php cake/tests/test_app/views/elements/email/text/default.ctp cake/tests/test_app/views/layouts/default.ctp cake/tests/test_app/views/posts/test_nocache_tags.ctp lib/Cake/Cache/Engine/MemcacheEngine.php lib/Cake/Config/config.php lib/Cake/Console/Command/Task/ModelTask.php lib/Cake/Console/Templates/skel/webroot/css/cake.generic.css lib/Cake/Console/Templates/skel/webroot/test.php lib/Cake/Console/cake.bat lib/Cake/Controller/Component/CookieComponent.php lib/Cake/Log/CakeLog.php lib/Cake/Model/CakeSchema.php lib/Cake/Test/Case/Log/Engine/FileLog.php lib/Cake/Test/Case/View/Helper/FormHelperTest.php lib/Cake/Test/test_app/View/Emails/html/custom.ctp lib/Cake/Test/test_app/View/Emails/text/custom.ctp lib/Cake/TestSuite/templates/header.php lib/Cake/Utility/Sanitize.php lib/Cake/Utility/Validation.php lib/Cake/VERSION.txt lib/Cake/View/Helper/FormHelper.php
509 lines
16 KiB
PHP
509 lines
16 KiB
PHP
<?php
|
|
/**
|
|
* The ControllerTask handles creating and updating controller files.
|
|
*
|
|
* PHP 5
|
|
*
|
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
|
* Copyright 2005-2011, Cake Software Foundation, Inc.
|
|
*
|
|
* Licensed under The MIT License
|
|
* Redistributions of files must retain the above copyright notice.
|
|
*
|
|
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
* @link http://cakephp.org CakePHP(tm) Project
|
|
* @package cake.console.shells.tasks
|
|
* @since CakePHP(tm) v 1.2
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
|
*/
|
|
|
|
App::uses('BakeTask', 'Console/Command/Task');
|
|
App::uses('AppModel', 'Model');
|
|
|
|
/**
|
|
* Task class for creating and updating controller files.
|
|
*
|
|
* @package cake.console.shells.tasks
|
|
*/
|
|
class ControllerTask extends BakeTask {
|
|
|
|
/**
|
|
* Tasks to be loaded by this Task
|
|
*
|
|
* @var array
|
|
* @access public
|
|
*/
|
|
public $tasks = array('Model', 'Test', 'Template', 'DbConfig', 'Project');
|
|
|
|
/**
|
|
* path to Controller directory
|
|
*
|
|
* @var array
|
|
* @access public
|
|
*/
|
|
public $path = null;
|
|
|
|
/**
|
|
* Override initialize
|
|
*
|
|
*/
|
|
public function initialize() {
|
|
$this->path = current(App::path('Controller'));
|
|
}
|
|
|
|
/**
|
|
* Execution method always used for tasks
|
|
*
|
|
*/
|
|
public function execute() {
|
|
parent::execute();
|
|
if (empty($this->args)) {
|
|
return $this->_interactive();
|
|
}
|
|
|
|
if (isset($this->args[0])) {
|
|
if (!isset($this->connection)) {
|
|
$this->connection = 'default';
|
|
}
|
|
if (strtolower($this->args[0]) == 'all') {
|
|
return $this->all();
|
|
}
|
|
|
|
$controller = $this->_controllerName($this->args[0]);
|
|
$actions = '';
|
|
|
|
if (!empty($this->params['public'])) {
|
|
$this->out(__d('cake_console', 'Baking basic crud methods for ') . $controller);
|
|
$actions .= $this->bakeActions($controller);
|
|
}
|
|
if (!empty($this->params['admin'])) {
|
|
$admin = $this->Project->getPrefix();
|
|
if ($admin) {
|
|
$this->out(__d('cake_console', 'Adding %s methods', $admin));
|
|
$actions .= "\n" . $this->bakeActions($controller, $admin);
|
|
}
|
|
}
|
|
if (empty($actions)) {
|
|
$actions = 'scaffold';
|
|
}
|
|
|
|
if ($this->bake($controller, $actions)) {
|
|
if ($this->_checkUnitTest()) {
|
|
$this->bakeTest($controller);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Bake All the controllers at once. Will only bake controllers for models that exist.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function all() {
|
|
$this->interactive = false;
|
|
$this->listAll($this->connection, false);
|
|
ClassRegistry::config('Model', array('ds' => $this->connection));
|
|
$unitTestExists = $this->_checkUnitTest();
|
|
foreach ($this->__tables as $table) {
|
|
$model = $this->_modelName($table);
|
|
$controller = $this->_controllerName($model);
|
|
App::uses($model, 'Model');
|
|
if (class_exists($model)) {
|
|
$actions = $this->bakeActions($controller);
|
|
if ($this->bake($controller, $actions) && $unitTestExists) {
|
|
$this->bakeTest($controller);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Interactive
|
|
*
|
|
* @return void
|
|
*/
|
|
protected function _interactive() {
|
|
$this->interactive = true;
|
|
$this->hr();
|
|
$this->out(__d('cake_console', "Bake Controller\nPath: %s", $this->path));
|
|
$this->hr();
|
|
|
|
if (empty($this->connection)) {
|
|
$this->connection = $this->DbConfig->getConfig();
|
|
}
|
|
|
|
$controllerName = $this->getName();
|
|
$this->hr();
|
|
$this->out(__d('cake_console', 'Baking %sController', $controllerName));
|
|
$this->hr();
|
|
|
|
$helpers = $components = array();
|
|
$actions = '';
|
|
$wannaUseSession = 'y';
|
|
$wannaBakeAdminCrud = 'n';
|
|
$useDynamicScaffold = 'n';
|
|
$wannaBakeCrud = 'y';
|
|
|
|
|
|
$question[] = __d('cake_console', "Would you like to build your controller interactively?");
|
|
if (file_exists($this->path . $controllerName .'Controller.php')) {
|
|
$question[] = __d('cake_console', "Warning: Choosing no will overwrite the %sController.", $controllerName);
|
|
}
|
|
$doItInteractive = $this->in(implode("\n", $question), array('y','n'), 'y');
|
|
|
|
if (strtolower($doItInteractive) == 'y') {
|
|
$this->interactive = true;
|
|
$useDynamicScaffold = $this->in(
|
|
__d('cake_console', "Would you like to use dynamic scaffolding?"), array('y','n'), 'n'
|
|
);
|
|
|
|
if (strtolower($useDynamicScaffold) == 'y') {
|
|
$wannaBakeCrud = 'n';
|
|
$actions = 'scaffold';
|
|
} else {
|
|
list($wannaBakeCrud, $wannaBakeAdminCrud) = $this->_askAboutMethods();
|
|
|
|
$helpers = $this->doHelpers();
|
|
$components = $this->doComponents();
|
|
|
|
$wannaUseSession = $this->in(
|
|
__d('cake_console', "Would you like to use Session flash messages?"), array('y','n'), 'y'
|
|
);
|
|
}
|
|
} else {
|
|
list($wannaBakeCrud, $wannaBakeAdminCrud) = $this->_askAboutMethods();
|
|
}
|
|
|
|
if (strtolower($wannaBakeCrud) == 'y') {
|
|
$actions = $this->bakeActions($controllerName, null, strtolower($wannaUseSession) == 'y');
|
|
}
|
|
if (strtolower($wannaBakeAdminCrud) == 'y') {
|
|
$admin = $this->Project->getPrefix();
|
|
$actions .= $this->bakeActions($controllerName, $admin, strtolower($wannaUseSession) == 'y');
|
|
}
|
|
|
|
$baked = false;
|
|
if ($this->interactive === true) {
|
|
$this->confirmController($controllerName, $useDynamicScaffold, $helpers, $components);
|
|
$looksGood = $this->in(__d('cake_console', 'Look okay?'), array('y','n'), 'y');
|
|
|
|
if (strtolower($looksGood) == 'y') {
|
|
$baked = $this->bake($controllerName, $actions, $helpers, $components);
|
|
if ($baked && $this->_checkUnitTest()) {
|
|
$this->bakeTest($controllerName);
|
|
}
|
|
}
|
|
} else {
|
|
$baked = $this->bake($controllerName, $actions, $helpers, $components);
|
|
if ($baked && $this->_checkUnitTest()) {
|
|
$this->bakeTest($controllerName);
|
|
}
|
|
}
|
|
return $baked;
|
|
}
|
|
|
|
/**
|
|
* Confirm a to be baked controller with the user
|
|
*
|
|
* @return void
|
|
*/
|
|
public function confirmController($controllerName, $useDynamicScaffold, $helpers, $components) {
|
|
$this->out();
|
|
$this->hr();
|
|
$this->out(__d('cake_console', 'The following controller will be created:'));
|
|
$this->hr();
|
|
$this->out(__d('cake_console', "Controller Name:\n\t%s", $controllerName));
|
|
|
|
if (strtolower($useDynamicScaffold) == 'y') {
|
|
$this->out("var \$scaffold;");
|
|
}
|
|
|
|
$properties = array(
|
|
'helpers' => __d('cake_console', 'Helpers:'),
|
|
'components' => __d('cake_console', 'Components:'),
|
|
);
|
|
|
|
foreach ($properties as $var => $title) {
|
|
if (count($$var)) {
|
|
$output = '';
|
|
$length = count($$var);
|
|
foreach ($$var as $i => $propElement) {
|
|
if ($i != $length -1) {
|
|
$output .= ucfirst($propElement) . ', ';
|
|
} else {
|
|
$output .= ucfirst($propElement);
|
|
}
|
|
}
|
|
$this->out($title . "\n\t" . $output);
|
|
}
|
|
}
|
|
$this->hr();
|
|
}
|
|
|
|
/**
|
|
* Interact with the user and ask about which methods (admin or regular they want to bake)
|
|
*
|
|
* @return array Array containing (bakeRegular, bakeAdmin) answers
|
|
*/
|
|
protected function _askAboutMethods() {
|
|
$wannaBakeCrud = $this->in(
|
|
__d('cake_console', "Would you like to create some basic class methods \n(index(), add(), view(), edit())?"),
|
|
array('y','n'), 'n'
|
|
);
|
|
$wannaBakeAdminCrud = $this->in(
|
|
__d('cake_console', "Would you like to create the basic class methods for admin routing?"),
|
|
array('y','n'), 'n'
|
|
);
|
|
return array($wannaBakeCrud, $wannaBakeAdminCrud);
|
|
}
|
|
|
|
/**
|
|
* Bake scaffold actions
|
|
*
|
|
* @param string $controllerName Controller name
|
|
* @param string $admin Admin route to use
|
|
* @param boolean $wannaUseSession Set to true to use sessions, false otherwise
|
|
* @return string Baked actions
|
|
* @access private
|
|
*/
|
|
public function bakeActions($controllerName, $admin = null, $wannaUseSession = true) {
|
|
$currentModelName = $modelImport = $this->_modelName($controllerName);
|
|
$plugin = $this->plugin;
|
|
if ($plugin) {
|
|
$plugin .= '.';
|
|
}
|
|
App::uses($modelImport, $plugin . 'Model');
|
|
if (!class_exists($modelImport)) {
|
|
$this->err(__d('cake_console', 'You must have a model for this class to build basic methods. Please try again.'));
|
|
$this->_stop();
|
|
}
|
|
|
|
$modelObj = ClassRegistry::init($currentModelName);
|
|
$controllerPath = $this->_controllerPath($controllerName);
|
|
$pluralName = $this->_pluralName($currentModelName);
|
|
$singularName = Inflector::variable($currentModelName);
|
|
$singularHumanName = $this->_singularHumanName($controllerName);
|
|
$pluralHumanName = $this->_pluralName($controllerName);
|
|
$displayField = $modelObj->displayField;
|
|
$primaryKey = $modelObj->primaryKey;
|
|
|
|
$this->Template->set(compact('plugin', 'admin', 'controllerPath', 'pluralName', 'singularName',
|
|
'singularHumanName', 'pluralHumanName', 'modelObj', 'wannaUseSession', 'currentModelName',
|
|
'displayField', 'primaryKey'
|
|
));
|
|
$actions = $this->Template->generate('actions', 'controller_actions');
|
|
return $actions;
|
|
}
|
|
|
|
/**
|
|
* Assembles and writes a Controller file
|
|
*
|
|
* @param string $controllerName Controller name
|
|
* @param string $actions Actions to add, or set the whole controller to use $scaffold (set $actions to 'scaffold')
|
|
* @param array $helpers Helpers to use in controller
|
|
* @param array $components Components to use in controller
|
|
* @param array $uses Models to use in controller
|
|
* @return string Baked controller
|
|
*/
|
|
public function bake($controllerName, $actions = '', $helpers = null, $components = null) {
|
|
$this->out("\n" . __d('cake_console', 'Baking controller class for %s...', $controllerName), 1, Shell::QUIET);
|
|
|
|
$isScaffold = ($actions === 'scaffold') ? true : false;
|
|
|
|
$this->Template->set('plugin', $this->plugin);
|
|
$this->Template->set(compact('controllerName', 'actions', 'helpers', 'components', 'isScaffold'));
|
|
$contents = $this->Template->generate('classes', 'controller');
|
|
|
|
$path = $this->getPath();
|
|
$filename = $path . $this->_controllerName($controllerName) . 'Controller.php';
|
|
if ($this->createFile($filename, $contents)) {
|
|
return $contents;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Assembles and writes a unit test file
|
|
*
|
|
* @param string $className Controller class name
|
|
* @return string Baked test
|
|
*/
|
|
public function bakeTest($className) {
|
|
$this->Test->plugin = $this->plugin;
|
|
$this->Test->connection = $this->connection;
|
|
$this->Test->interactive = $this->interactive;
|
|
return $this->Test->bake('Controller', $className);
|
|
}
|
|
|
|
/**
|
|
* Interact with the user and get a list of additional helpers
|
|
*
|
|
* @return array Helpers that the user wants to use.
|
|
*/
|
|
public function doHelpers() {
|
|
return $this->_doPropertyChoices(
|
|
__d('cake_console', "Would you like this controller to use other helpers\nbesides HtmlHelper and FormHelper?"),
|
|
__d('cake_console', "Please provide a comma separated list of the other\nhelper names you'd like to use.\nExample: 'Ajax, Javascript, Time'")
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Interact with the user and get a list of additional components
|
|
*
|
|
* @return array Components the user wants to use.
|
|
*/
|
|
public function doComponents() {
|
|
return $this->_doPropertyChoices(
|
|
__d('cake_console', "Would you like this controller to use any components?"),
|
|
__d('cake_console', "Please provide a comma separated list of the component names you'd like to use.\nExample: 'Acl, Security, RequestHandler'")
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Common code for property choice handling.
|
|
*
|
|
* @param string $prompt A yes/no question to precede the list
|
|
* @param sting $example A question for a comma separated list, with examples.
|
|
* @return array Array of values for property.
|
|
*/
|
|
protected function _doPropertyChoices($prompt, $example) {
|
|
$proceed = $this->in($prompt, array('y','n'), 'n');
|
|
$property = array();
|
|
if (strtolower($proceed) == 'y') {
|
|
$propertyList = $this->in($example);
|
|
$propertyListTrimmed = str_replace(' ', '', $propertyList);
|
|
$property = explode(',', $propertyListTrimmed);
|
|
}
|
|
return array_filter($property);
|
|
}
|
|
|
|
/**
|
|
* Outputs and gets the list of possible controllers from database
|
|
*
|
|
* @param string $useDbConfig Database configuration name
|
|
* @param boolean $interactive Whether you are using listAll interactively and want options output.
|
|
* @return array Set of controllers
|
|
*/
|
|
public function listAll($useDbConfig = null) {
|
|
if (is_null($useDbConfig)) {
|
|
$useDbConfig = $this->connection;
|
|
}
|
|
$this->__tables = $this->Model->getAllTables($useDbConfig);
|
|
|
|
if ($this->interactive == true) {
|
|
$this->out(__d('cake_console', 'Possible Controllers based on your current database:'));
|
|
$this->_controllerNames = array();
|
|
$count = count($this->__tables);
|
|
for ($i = 0; $i < $count; $i++) {
|
|
$this->_controllerNames[] = $this->_controllerName($this->_modelName($this->__tables[$i]));
|
|
$this->out($i + 1 . ". " . $this->_controllerNames[$i]);
|
|
}
|
|
return $this->_controllerNames;
|
|
}
|
|
return $this->__tables;
|
|
}
|
|
|
|
/**
|
|
* Forces the user to specify the controller he wants to bake, and returns the selected controller name.
|
|
*
|
|
* @param string $useDbConfig Connection name to get a controller name for.
|
|
* @return string Controller name
|
|
*/
|
|
public function getName($useDbConfig = null) {
|
|
$controllers = $this->listAll($useDbConfig);
|
|
$enteredController = '';
|
|
|
|
while ($enteredController == '') {
|
|
$enteredController = $this->in(__d('cake_console', "Enter a number from the list above,\ntype in the name of another controller, or 'q' to exit"), null, 'q');
|
|
if ($enteredController === 'q') {
|
|
$this->out(__d('cake_console', 'Exit'));
|
|
return $this->_stop();
|
|
}
|
|
|
|
if ($enteredController == '' || intval($enteredController) > count($controllers)) {
|
|
$this->err(__d('cake_console', "The Controller name you supplied was empty,\nor the number you selected was not an option. Please try again."));
|
|
$enteredController = '';
|
|
}
|
|
}
|
|
|
|
if (intval($enteredController) > 0 && intval($enteredController) <= count($controllers) ) {
|
|
$controllerName = $controllers[intval($enteredController) - 1];
|
|
} else {
|
|
$controllerName = Inflector::camelize($enteredController);
|
|
}
|
|
return $controllerName;
|
|
}
|
|
|
|
/**
|
|
* get the option parser.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function getOptionParser() {
|
|
$parser = parent::getOptionParser();
|
|
return $parser->description(
|
|
__d('cake_console', 'Bake a controller for a model. Using options you can bake public, admin or both.')
|
|
)->addArgument('name', array(
|
|
'help' => __d('cake_console', 'Name of the controller to bake. Can use Plugin.name to bake controllers into plugins.')
|
|
))->addOption('public', array(
|
|
'help' => __d('cake_console', 'Bake a controller with basic crud actions (index, view, add, edit, delete).'),
|
|
'boolean' => true
|
|
))->addOption('admin', array(
|
|
'help' => __d('cake_console', 'Bake a controller with crud actions for one of the Routing.prefixes.'),
|
|
'boolean' => true
|
|
))->addOption('plugin', array(
|
|
'short' => 'p',
|
|
'help' => __d('cake_console', 'Plugin to bake the controller into.')
|
|
))->addOption('connection', array(
|
|
'short' => 'c',
|
|
'help' => __d('cake_console', 'The connection the controller\'s model is on.')
|
|
))->addSubcommand('all', array(
|
|
'help' => __d('cake_console', 'Bake all controllers with CRUD methods.')
|
|
))->epilog(__d('cake_console', 'Omitting all arguments and options will enter into an interactive mode.'));
|
|
}
|
|
|
|
/**
|
|
* Displays help contents
|
|
*
|
|
*/
|
|
public function help() {
|
|
$this->hr();
|
|
$this->out("Usage: cake bake controller <arg1> <arg2>...");
|
|
$this->hr();
|
|
$this->out('Arguments:');
|
|
$this->out();
|
|
$this->out("<name>");
|
|
$this->out("\tName of the controller to bake. Can use Plugin.name");
|
|
$this->out("\tas a shortcut for plugin baking.");
|
|
$this->out();
|
|
$this->out('Params:');
|
|
$this->out();
|
|
$this->out('-connection <config>');
|
|
$this->out("\tset db config <config>. uses 'default' if none is specified");
|
|
$this->out();
|
|
$this->out('Commands:');
|
|
$this->out();
|
|
$this->out("controller <name>");
|
|
$this->out("\tbakes controller with var \$scaffold");
|
|
$this->out();
|
|
$this->out("controller <name> public");
|
|
$this->out("\tbakes controller with basic crud actions");
|
|
$this->out("\t(index, view, add, edit, delete)");
|
|
$this->out();
|
|
$this->out("controller <name> admin");
|
|
$this->out("\tbakes a controller with basic crud actions for one of the");
|
|
$this->out("\tConfigure::read('Routing.prefixes') methods.");
|
|
$this->out();
|
|
$this->out("controller <name> public admin");
|
|
$this->out("\tbakes a controller with basic crud actions for one");
|
|
$this->out("\tConfigure::read('Routing.prefixes') and non admin methods.");
|
|
$this->out("\t(index, view, add, edit, delete,");
|
|
$this->out("\tadmin_index, admin_view, admin_edit, admin_add, admin_delete)");
|
|
$this->out();
|
|
$this->out("controller all");
|
|
$this->out("\tbakes all controllers with CRUD methods.");
|
|
$this->out();
|
|
$this->_stop();
|
|
}
|
|
}
|