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.7 Red Velvet API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 3.7
      • 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:     /**
 28:      * Default ServerHost
 29:      *
 30:      * @var string
 31:      */
 32:     const DEFAULT_HOST = 'localhost';
 33: 
 34:     /**
 35:      * Default ListenPort
 36:      *
 37:      * @var int
 38:      */
 39:     const DEFAULT_PORT = 8765;
 40: 
 41:     /**
 42:      * server host
 43:      *
 44:      * @var string
 45:      */
 46:     protected $_host = self::DEFAULT_HOST;
 47: 
 48:     /**
 49:      * listen port
 50:      *
 51:      * @var int
 52:      */
 53:     protected $_port = self::DEFAULT_PORT;
 54: 
 55:     /**
 56:      * document root
 57:      *
 58:      * @var string
 59:      */
 60:     protected $_documentRoot = WWW_ROOT;
 61: 
 62:     /**
 63:      * ini path
 64:      *
 65:      * @var string
 66:      */
 67:     protected $_iniPath = '';
 68: 
 69:     /**
 70:      * Starts up the Shell and displays the welcome message.
 71:      * Allows for checking and configuring prior to command or main execution
 72:      *
 73:      * Override this method if you want to remove the welcome information,
 74:      * or otherwise modify the pre-command flow.
 75:      *
 76:      * @return void
 77:      * @link https://book.cakephp.org/3.0/en/console-and-shells.html#hook-methods
 78:      */
 79:     public function startup()
 80:     {
 81:         if ($this->param('host')) {
 82:             $this->_host = $this->param('host');
 83:         }
 84:         if ($this->param('port')) {
 85:             $this->_port = (int)$this->param('port');
 86:         }
 87:         if ($this->param('document_root')) {
 88:             $this->_documentRoot = $this->param('document_root');
 89:         }
 90:         if ($this->param('ini_path')) {
 91:             $this->_iniPath = $this->param('ini_path');
 92:         }
 93: 
 94:         // For Windows
 95:         if (substr($this->_documentRoot, -1, 1) === DIRECTORY_SEPARATOR) {
 96:             $this->_documentRoot = substr($this->_documentRoot, 0, strlen($this->_documentRoot) - 1);
 97:         }
 98:         if (preg_match("/^([a-z]:)[\\\]+(.+)$/i", $this->_documentRoot, $m)) {
 99:             $this->_documentRoot = $m[1] . '\\' . $m[2];
100:         }
101: 
102:         $this->_iniPath = rtrim($this->_iniPath, DIRECTORY_SEPARATOR);
103:         if (preg_match("/^([a-z]:)[\\\]+(.+)$/i", $this->_iniPath, $m)) {
104:             $this->_iniPath = $m[1] . '\\' . $m[2];
105:         }
106: 
107:         parent::startup();
108:     }
109: 
110:     /**
111:      * Displays a header for the shell
112:      *
113:      * @return void
114:      */
115:     protected function _welcome()
116:     {
117:         $this->out();
118:         $this->out(sprintf('<info>Welcome to CakePHP %s Console</info>', 'v' . Configure::version()));
119:         $this->hr();
120:         $this->out(sprintf('App : %s', APP_DIR));
121:         $this->out(sprintf('Path: %s', APP));
122:         $this->out(sprintf('DocumentRoot: %s', $this->_documentRoot));
123:         $this->out(sprintf('Ini Path: %s', $this->_iniPath));
124:         $this->hr();
125:     }
126: 
127:     /**
128:      * Override main() to handle action
129:      *
130:      * @return void
131:      */
132:     public function main()
133:     {
134:         $command = sprintf(
135:             'php -S %s:%d -t %s',
136:             $this->_host,
137:             $this->_port,
138:             escapeshellarg($this->_documentRoot)
139:         );
140: 
141:         if (!empty($this->_iniPath)) {
142:             $command = sprintf('%s -c %s', $command, $this->_iniPath);
143:         }
144: 
145:         $command = sprintf('%s %s', $command, escapeshellarg($this->_documentRoot . '/index.php'));
146: 
147:         $port = ':' . $this->_port;
148:         $this->out(sprintf('built-in server is running in http://%s%s/', $this->_host, $port));
149:         $this->out(sprintf('You can exit with <info>`CTRL-C`</info>'));
150:         system($command);
151:     }
152: 
153:     /**
154:      * Gets the option parser instance and configures it.
155:      *
156:      * @return \Cake\Console\ConsoleOptionParser
157:      */
158:     public function getOptionParser()
159:     {
160:         $parser = parent::getOptionParser();
161: 
162:         $parser->setDescription([
163:             'PHP Built-in Server for CakePHP',
164:             '<warning>[WARN] Don\'t use this in a production environment</warning>',
165:         ])->addOption('host', [
166:             'short' => 'H',
167:             'help' => 'ServerHost'
168:         ])->addOption('port', [
169:             'short' => 'p',
170:             'help' => 'ListenPort'
171:         ])->addOption('ini_path', [
172:             'short' => 'I',
173:             'help' => 'php.ini path'
174:         ])->addOption('document_root', [
175:             'short' => 'd',
176:             'help' => 'DocumentRoot'
177:         ]);
178: 
179:         return $parser;
180:     }
181: }
182: 
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