From 01cf28b76e01774fcb02108b2519d0edf3182663 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 29 Jan 2018 02:06:50 -0500 Subject: [PATCH] Allow user to specify a php.ini in ServerShell --- src/Shell/ServerShell.php | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/Shell/ServerShell.php b/src/Shell/ServerShell.php index 788bc05e67f..3f263d1e051 100644 --- a/src/Shell/ServerShell.php +++ b/src/Shell/ServerShell.php @@ -59,6 +59,13 @@ class ServerShell extends Shell */ protected $_documentRoot; + /** + * ini path + * + * @var string + */ + protected $_iniPath; + /** * Override initialize of the Shell * @@ -69,6 +76,7 @@ public function initialize() $this->_host = self::DEFAULT_HOST; $this->_port = self::DEFAULT_PORT; $this->_documentRoot = WWW_ROOT; + $this->_iniPath = ''; } /** @@ -92,6 +100,9 @@ public function startup() if (!empty($this->params['document_root'])) { $this->_documentRoot = $this->params['document_root']; } + if (!empty($this->params['ini_path'])) { + $this->_iniPath = $this->params['ini_path']; + } // For Windows if (substr($this->_documentRoot, -1, 1) === DIRECTORY_SEPARATOR) { @@ -100,6 +111,12 @@ public function startup() if (preg_match("/^([a-z]:)[\\\]+(.+)$/i", $this->_documentRoot, $m)) { $this->_documentRoot = $m[1] . '\\' . $m[2]; } + if (substr($this->_iniPath, -1, 1) === DIRECTORY_SEPARATOR) { + $this->_iniPath = substr($this->_iniPath, 0, strlen($this->_iniPath) - 1); + } + if (preg_match("/^([a-z]:)[\\\]+(.+)$/i", $this->_iniPath, $m)) { + $this->_iniPath = $m[1] . '\\' . $m[2]; + } parent::startup(); } @@ -117,6 +134,7 @@ protected function _welcome() $this->out(sprintf('App : %s', APP_DIR)); $this->out(sprintf('Path: %s', APP)); $this->out(sprintf('DocumentRoot: %s', $this->_documentRoot)); + $this->out(sprintf('Ini Path: %s', $this->_iniPath)); $this->hr(); } @@ -128,13 +146,18 @@ protected function _welcome() public function main() { $command = sprintf( - 'php -S %s:%d -t %s %s', + 'php -S %s:%d -t %s', $this->_host, $this->_port, - escapeshellarg($this->_documentRoot), - escapeshellarg($this->_documentRoot . '/index.php') + escapeshellarg($this->_documentRoot) ); + if (!empty($this->_iniPath)) { + $command = sprintf('%s -c %s', $command, $this->_iniPath); + } + + $command = sprintf('%s %s', $command, escapeshellarg($this->_documentRoot . '/index.php')); + $port = ':' . $this->_port; $this->out(sprintf('built-in server is running in http://%s%s/', $this->_host, $port)); $this->out(sprintf('You can exit with `CTRL-C`')); @@ -159,6 +182,9 @@ public function getOptionParser() ])->addOption('port', [ 'short' => 'p', 'help' => 'ListenPort' + ])->addOption('ini_path', [ + 'short' => 'I', + 'help' => 'php.ini path' ])->addOption('document_root', [ 'short' => 'd', 'help' => 'DocumentRoot'