CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Team
    • Issues (Github)
    • YouTube Channel
    • Get Involved
    • Bakery
    • Featured Resources
    • Newsletter
    • Certification
    • My CakePHP
    • CakeFest
    • Facebook
    • Twitter
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 3.8 Red Velvet API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 3.8
      • 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

Namespaces

  • Cake
    • Auth
      • Storage
    • Cache
      • Engine
    • Collection
      • Iterator
    • Command
    • Console
      • Exception
    • Controller
      • Component
      • Exception
    • Core
      • Configure
        • Engine
      • Exception
      • Retry
    • Database
      • Driver
      • Exception
      • Expression
      • Schema
      • Statement
      • Type
    • Datasource
      • Exception
    • Error
      • Middleware
    • Event
      • Decorator
    • Filesystem
    • Form
    • Http
      • Client
        • Adapter
        • Auth
      • Cookie
      • Exception
      • Middleware
      • Session
    • I18n
      • Formatter
      • Middleware
      • Parser
    • Log
      • Engine
    • Mailer
      • Exception
      • Transport
    • Network
      • Exception
    • ORM
      • Association
      • Behavior
        • Translate
      • Exception
      • Locator
      • Rule
    • Routing
      • Exception
      • Filter
      • Middleware
      • Route
    • Shell
      • Helper
      • Task
    • TestSuite
      • Fixture
      • Stub
    • Utility
      • Exception
    • Validation
    • View
      • Exception
      • Form
      • Helper
      • Widget
  • None

Classes

  • CacheShell
  • CommandListShell
  • CompletionShell
  • I18nShell
  • OrmCacheShell
  • PluginShell
  • RoutesShell
  • SchemaCacheShell
  • ServerShell
  1: <?php
  2: /**
  3:  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  4:  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  5:  *
  6:  * Licensed under The MIT License
  7:  * For full copyright and license information, please see the LICENSE.txt
  8:  * Redistributions of files must retain the above copyright notice.
  9:  *
 10:  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
 11:  * @link          https://cakephp.org CakePHP(tm) Project
 12:  * @since         2.3.0
 13:  * @license       https://opensource.org/licenses/mit-license.php MIT License
 14:  */
 15: 
 16: namespace Cake\Shell;
 17: 
 18: use Cake\Console\Shell;
 19: use Cake\Core\Configure;
 20: 
 21: /**
 22:  * built-in Server Shell
 23:  */
 24: class ServerShell extends Shell
 25: {
 26:     /**
 27:      * Default ServerHost
 28:      *
 29:      * @var string
 30:      */
 31:     const DEFAULT_HOST = 'localhost';
 32: 
 33:     /**
 34:      * Default ListenPort
 35:      *
 36:      * @var int
 37:      */
 38:     const DEFAULT_PORT = 8765;
 39: 
 40:     /**
 41:      * server host
 42:      *
 43:      * @var string
 44:      */
 45:     protected $_host = self::DEFAULT_HOST;
 46: 
 47:     /**
 48:      * listen port
 49:      *
 50:      * @var int
 51:      */
 52:     protected $_port = self::DEFAULT_PORT;
 53: 
 54:     /**
 55:      * document root
 56:      *
 57:      * @var string
 58:      */
 59:     protected $_documentRoot = WWW_ROOT;
 60: 
 61:     /**
 62:      * ini path
 63:      *
 64:      * @var string
 65:      */
 66:     protected $_iniPath = '';
 67: 
 68:     /**
 69:      * Starts up the Shell and displays the welcome message.
 70:      * Allows for checking and configuring prior to command or main execution
 71:      *
 72:      * Override this method if you want to remove the welcome information,
 73:      * or otherwise modify the pre-command flow.
 74:      *
 75:      * @return void
 76:      * @link https://book.cakephp.org/3.0/en/console-and-shells.html#hook-methods
 77:      */
 78:     public function startup()
 79:     {
 80:         if ($this->param('host')) {
 81:             $this->_host = $this->param('host');
 82:         }
 83:         if ($this->param('port')) {
 84:             $this->_port = (int)$this->param('port');
 85:         }
 86:         if ($this->param('document_root')) {
 87:             $this->_documentRoot = $this->param('document_root');
 88:         }
 89:         if ($this->param('ini_path')) {
 90:             $this->_iniPath = $this->param('ini_path');
 91:         }
 92: 
 93:         // For Windows
 94:         if (substr($this->_documentRoot, -1, 1) === DIRECTORY_SEPARATOR) {
 95:             $this->_documentRoot = substr($this->_documentRoot, 0, strlen($this->_documentRoot) - 1);
 96:         }
 97:         if (preg_match("/^([a-z]:)[\\\]+(.+)$/i", $this->_documentRoot, $m)) {
 98:             $this->_documentRoot = $m[1] . '\\' . $m[2];
 99:         }
100: 
101:         $this->_iniPath = rtrim($this->_iniPath, DIRECTORY_SEPARATOR);
102:         if (preg_match("/^([a-z]:)[\\\]+(.+)$/i", $this->_iniPath, $m)) {
103:             $this->_iniPath = $m[1] . '\\' . $m[2];
104:         }
105: 
106:         parent::startup();
107:     }
108: 
109:     /**
110:      * Displays a header for the shell
111:      *
112:      * @return void
113:      */
114:     protected function _welcome()
115:     {
116:         $this->out();
117:         $this->out(sprintf('<info>Welcome to CakePHP %s Console</info>', 'v' . Configure::version()));
118:         $this->hr();
119:         $this->out(sprintf('App : %s', APP_DIR));
120:         $this->out(sprintf('Path: %s', APP));
121:         $this->out(sprintf('DocumentRoot: %s', $this->_documentRoot));
122:         $this->out(sprintf('Ini Path: %s', $this->_iniPath));
123:         $this->hr();
124:     }
125: 
126:     /**
127:      * Override main() to handle action
128:      *
129:      * @return void
130:      */
131:     public function main()
132:     {
133:         $command = sprintf(
134:             'php -S %s:%d -t %s',
135:             $this->_host,
136:             $this->_port,
137:             escapeshellarg($this->_documentRoot)
138:         );
139: 
140:         if (!empty($this->_iniPath)) {
141:             $command = sprintf('%s -c %s', $command, $this->_iniPath);
142:         }
143: 
144:         $command = sprintf('%s %s', $command, escapeshellarg($this->_documentRoot . '/index.php'));
145: 
146:         $port = ':' . $this->_port;
147:         $this->out(sprintf('built-in server is running in http://%s%s/', $this->_host, $port));
148:         $this->out(sprintf('You can exit with <info>`CTRL-C`</info>'));
149:         system($command);
150:     }
151: 
152:     /**
153:      * Gets the option parser instance and configures it.
154:      *
155:      * @return \Cake\Console\ConsoleOptionParser
156:      */
157:     public function getOptionParser()
158:     {
159:         $parser = parent::getOptionParser();
160: 
161:         $parser->setDescription([
162:             'PHP Built-in Server for CakePHP',
163:             '<warning>[WARN] Don\'t use this in a production environment</warning>',
164:         ])->addOption('host', [
165:             'short' => 'H',
166:             'help' => 'ServerHost'
167:         ])->addOption('port', [
168:             'short' => 'p',
169:             'help' => 'ListenPort'
170:         ])->addOption('ini_path', [
171:             'short' => 'I',
172:             'help' => 'php.ini path'
173:         ])->addOption('document_root', [
174:             'short' => 'd',
175:             'help' => 'DocumentRoot'
176:         ]);
177: 
178:         return $parser;
179:     }
180: }
181: 
Follow @CakePHP
#IRC
OpenHub
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Logos & Trademarks
  • Community
  • Team
  • Issues (Github)
  • YouTube Channel
  • Get Involved
  • Bakery
  • Featured Resources
  • Newsletter
  • Certification
  • My CakePHP
  • CakeFest
  • Facebook
  • Twitter
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs