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.3 API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 2.3
      • 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
  • ServerShell
  • TestShell
  • TestsuiteShell
  • UpgradeShell
  1: <?php
  2: /**
  3:  * built-in Server Shell
  4:  *
  5:  * PHP 5
  6:  *
  7:  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  8:  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  9:  *
 10:  * Licensed under The MIT License
 11:  * For full copyright and license information, please see the LICENSE.txt
 12:  * Redistributions of files must retain the above copyright notice.
 13:  *
 14:  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 15:  * @link          http://cakephp.org CakePHP(tm) Project
 16:  * @since         CakePHP(tm) v 2.3.0
 17:  * @license       http://www.opensource.org/licenses/mit-license.php MIT License
 18:  */
 19: 
 20: App::uses('AppShell', 'Console/Command');
 21: 
 22: /**
 23:  * built-in Server Shell
 24:  *
 25:  * @package       Cake.Console.Command
 26:  */
 27: class ServerShell extends AppShell {
 28: 
 29: /**
 30:  * Default ServerHost
 31:  */
 32:     const DEFAULT_HOST = 'localhost';
 33: 
 34: /**
 35:  * Default ListenPort
 36:  */
 37:     const DEFAULT_PORT = 80;
 38: 
 39: /**
 40:  * server host
 41:  *
 42:  * @var string
 43:  */
 44:     protected $_host = null;
 45: 
 46: /**
 47:  * listen port
 48:  *
 49:  * @var string
 50:  */
 51:     protected $_port = null;
 52: 
 53: /**
 54:  * document root
 55:  *
 56:  * @var string
 57:  */
 58:     protected $_documentRoot = null;
 59: 
 60: /**
 61:  * Override initialize of the Shell
 62:  *
 63:  * @return void
 64:  */
 65:     public function initialize() {
 66:         $this->_host = self::DEFAULT_HOST;
 67:         $this->_port = self::DEFAULT_PORT;
 68:         $this->_documentRoot = WWW_ROOT;
 69:     }
 70: 
 71: /**
 72:  * Starts up the Shell and displays the welcome message.
 73:  * Allows for checking and configuring prior to command or main execution
 74:  *
 75:  * Override this method if you want to remove the welcome information,
 76:  * or otherwise modify the pre-command flow.
 77:  *
 78:  * @return void
 79:  * @link http://book.cakephp.org/2.0/en/console-and-shells.html#Shell::startup
 80:  */
 81:     public function startup() {
 82:         if (!empty($this->params['host'])) {
 83:             $this->_host = $this->params['host'];
 84:         }
 85:         if (!empty($this->params['port'])) {
 86:             $this->_port = $this->params['port'];
 87:         }
 88:         if (!empty($this->params['document_root'])) {
 89:             $this->_documentRoot = $this->params['document_root'];
 90:         }
 91: 
 92:         // for windows
 93:         if (substr($this->_documentRoot, -1, 1) == DIRECTORY_SEPARATOR) {
 94:             $this->_documentRoot = substr($this->_documentRoot, 0, strlen($this->_documentRoot) - 1);
 95:         }
 96:         if (preg_match("/^([a-z]:)[\\\]+(.+)$/i", $this->_documentRoot, $m)) {
 97:             $this->_documentRoot = $m[1] . '\\' . $m[2];
 98:         }
 99: 
100:         parent::startup();
101:     }
102: 
103: /**
104:  * Displays a header for the shell
105:  *
106:  * @return void
107:  */
108:     protected function _welcome() {
109:         $this->out();
110:         $this->out(__d('cake_console', '<info>Welcome to CakePHP %s Console</info>', 'v' . Configure::version()));
111:         $this->hr();
112:         $this->out(__d('cake_console', 'App : %s', APP_DIR));
113:         $this->out(__d('cake_console', 'Path: %s', APP));
114:         $this->out(__d('cake_console', 'DocumentRoot: %s', $this->_documentRoot));
115:         $this->hr();
116:     }
117: 
118: /**
119:  * Override main() to handle action
120:  *
121:  * @return void
122:  */
123:     public function main() {
124:         if (version_compare(PHP_VERSION, '5.4.0') < 0) {
125:             $this->out(__d('cake_console', '<warning>This command is available on PHP5.4 or above</warning>'));
126:             return;
127:         }
128: 
129:         $command = sprintf("php -S %s:%d -t %s %s",
130:             $this->_host,
131:             $this->_port,
132:             escapeshellarg($this->_documentRoot),
133:             escapeshellarg($this->_documentRoot . '/index.php')
134:         );
135: 
136:         $port = ($this->_port == self::DEFAULT_PORT) ? '' : ':' . $this->_port;
137:         $this->out(__d('cake_console', 'built-in server is running in http://%s%s/', $this->_host, $port));
138:         system($command);
139:     }
140: 
141: /**
142:  * Get and configure the optionparser.
143:  *
144:  * @return ConsoleOptionParser
145:  */
146:     public function getOptionParser() {
147:         $parser = parent::getOptionParser();
148: 
149:         $parser->addOption('host', array(
150:             'short' => 'H',
151:             'help' => __d('cake_console', 'ServerHost')
152:         ));
153:         $parser->addOption('port', array(
154:             'short' => 'p',
155:             'help' => __d('cake_console', 'ListenPort')
156:         ));
157:         $parser->addOption('document_root', array(
158:             'short' => 'd',
159:             'help' => __d('cake_console', 'DocumentRoot')
160:         ));
161: 
162:         $parser->description(array(
163:             __d('cake_console', 'PHP Built-in Server for CakePHP'),
164:             __d('cake_console', '<warning>[WARN] Don\'t use this at the production environment</warning>'),
165:         ));
166: 
167:         return $parser;
168:     }
169: }
170: 
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