CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (GitHub)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • Slack
    • Paid Support
CakePHP

C CakePHP 2.2 API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 2.2
      • 4.2
      • 4.1
      • 4.0
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Packages

  • Cake
    • Cache
      • Engine
    • Configure
    • Console
      • Command
        • Task
    • Controller
      • Component
        • Acl
        • Auth
    • Core
    • Error
    • Event
    • I18n
    • Log
      • Engine
    • Model
      • Behavior
      • Datasource
        • Database
        • Session
      • Validator
    • Network
      • Email
      • Http
    • Routing
      • Filter
      • Route
    • TestSuite
      • Coverage
      • Fixture
      • Reporter
    • Utility
    • View
      • Helper

Classes

  • AclShell
  • ApiShell
  • BakeShell
  • CommandListShell
  • ConsoleShell
  • I18nShell
  • SchemaShell
  • TestShell
  • TestsuiteShell
  • UpgradeShell
  1: <?php
  2: /**
  3:  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4:  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
  5:  *
  6:  * Licensed under The MIT License
  7:  * Redistributions of files must retain the above copyright notice.
  8:  *
  9:  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 10:  * @link          http://cakephp.org CakePHP Project
 11:  * @package       Cake.Console.Command
 12:  * @since         CakePHP v 2.0
 13:  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 14:  */
 15: 
 16: App::uses('AppShell', 'Console/Command');
 17: App::uses('Inflector', 'Utility');
 18: 
 19: /**
 20:  * Shows a list of commands available from the console.
 21:  *
 22:  * @package       Cake.Console.Command
 23:  */
 24: class CommandListShell extends AppShell {
 25: 
 26: /**
 27:  * startup
 28:  *
 29:  * @return void
 30:  */
 31:     public function startup() {
 32:         if (empty($this->params['xml'])) {
 33:             parent::startup();
 34:         }
 35:     }
 36: 
 37: /**
 38:  * Main function Prints out the list of shells.
 39:  *
 40:  * @return void
 41:  */
 42:     public function main() {
 43:         if (empty($this->params['xml'])) {
 44:             $this->out(__d('cake_console', "<info>Current Paths:</info>"), 2);
 45:             $this->out(" -app: " . APP_DIR);
 46:             $this->out(" -working: " . rtrim(APP, DS));
 47:             $this->out(" -root: " . rtrim(ROOT, DS));
 48:             $this->out(" -core: " . rtrim(CORE_PATH, DS));
 49:             $this->out("");
 50:             $this->out(__d('cake_console', "<info>Changing Paths:</info>"), 2);
 51:             $this->out(__d('cake_console', "Your working path should be the same as your application path to change your path use the '-app' param."));
 52:             $this->out(__d('cake_console', "Example: -app relative/path/to/myapp or -app /absolute/path/to/myapp"), 2);
 53: 
 54:             $this->out(__d('cake_console', "<info>Available Shells:</info>"), 2);
 55:         }
 56: 
 57:         $shellList = $this->_getShellList();
 58:         if (empty($shellList)) {
 59:             return;
 60:         }
 61: 
 62:         if (empty($this->params['xml'])) {
 63:             $this->_asText($shellList);
 64:         } else {
 65:             $this->_asXml($shellList);
 66:         }
 67:     }
 68: 
 69: /**
 70:  * Gets the shell command listing.
 71:  *
 72:  * @return array
 73:  */
 74:     protected function _getShellList() {
 75:         $skipFiles = array('AppShell');
 76: 
 77:         $plugins = CakePlugin::loaded();
 78:         $shellList = array_fill_keys($plugins, null) + array('CORE' => null, 'app' => null);
 79: 
 80:         $corePath = App::core('Console/Command');
 81:         $shells = App::objects('file', $corePath[0]);
 82:         $shells = array_diff($shells, $skipFiles);
 83:         $this->_appendShells('CORE', $shells, $shellList);
 84: 
 85:         $appShells = App::objects('Console/Command', null, false);
 86:         $appShells = array_diff($appShells, $shells, $skipFiles);
 87:         $this->_appendShells('app', $appShells, $shellList);
 88: 
 89:         foreach ($plugins as $plugin) {
 90:             $pluginShells = App::objects($plugin . '.Console/Command');
 91:             $this->_appendShells($plugin, $pluginShells, $shellList);
 92:         }
 93: 
 94:         return array_filter($shellList);
 95:     }
 96: 
 97: /**
 98:  * Scan the provided paths for shells, and append them into $shellList
 99:  *
100:  * @param string $type
101:  * @param array $shells
102:  * @param array $shellList
103:  * @return array
104:  */
105:     protected function _appendShells($type, $shells, &$shellList) {
106:         foreach ($shells as $shell) {
107:             $shellList[$type][] = Inflector::underscore(str_replace('Shell', '', $shell));
108:         }
109:     }
110: 
111: /**
112:  * Output text.
113:  *
114:  * @param array $shellList
115:  * @return void
116:  */
117:     protected function _asText($shellList) {
118:         foreach ($shellList as $plugin => $commands) {
119:             sort($commands);
120:             $this->out(sprintf('[<info>%s</info>] %s', $plugin, implode(', ', $commands)));
121:             $this->out();
122:         }
123: 
124:         $this->out(__d('cake_console', "To run an app or core command, type <info>cake shell_name [args]</info>"));
125:         $this->out(__d('cake_console', "To run a plugin command, type <info>cake Plugin.shell_name [args]</info>"));
126:         $this->out(__d('cake_console', "To get help on a specific command, type <info>cake shell_name --help</info>"), 2);
127:     }
128: 
129: /**
130:  * Output as XML
131:  *
132:  * @param array $shellList
133:  * @return void
134:  */
135:     protected function _asXml($shellList) {
136:         $plugins = CakePlugin::loaded();
137:         $shells = new SimpleXmlElement('<shells></shells>');
138:         foreach ($shellList as $plugin => $commands) {
139:             foreach ($commands as $command) {
140:                 $callable = $command;
141:                 if (in_array($plugin, $plugins)) {
142:                     $callable = Inflector::camelize($plugin) . '.' . $command;
143:                 }
144: 
145:                 $shell = $shells->addChild('shell');
146:                 $shell->addAttribute('name', $command);
147:                 $shell->addAttribute('call_as', $callable);
148:                 $shell->addAttribute('provider', $plugin);
149:                 $shell->addAttribute('help', $callable . ' -h');
150:             }
151:         }
152:         $this->stdout->outputAs(ConsoleOutput::RAW);
153:         $this->out($shells->saveXml());
154:     }
155: 
156: /**
157:  * get the option parser
158:  *
159:  * @return void
160:  */
161:     public function getOptionParser() {
162:         $parser = parent::getOptionParser();
163:         return $parser->description(__d('cake_console', 'Get the list of available shells for this CakePHP application.'))
164:             ->addOption('sort', array(
165:                 'help' => __d('cake_console', 'Does nothing (deprecated)'),
166:                 'boolean' => true
167:             ))
168:             ->addOption('xml', array(
169:                 'help' => __d('cake_console', 'Get the listing as XML.'),
170:                 'boolean' => true
171:             ));
172:     }
173: 
174: }
175: 
OpenHub
Rackspace
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (GitHub)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • Slack
  • Paid Support

Generated using CakePHP API Docs