Skip to content
Permalink
Browse files

Allow user to specify a php.ini in ServerShell

  • Loading branch information...
josegonzalez committed Jan 29, 2018
1 parent 6e1db35 commit 01cf28b76e01774fcb02108b2519d0edf3182663
Showing with 29 additions and 3 deletions.
  1. +29 −3 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 <info>`CTRL-C`</info>'));
@@ -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'

0 comments on commit 01cf28b

Please sign in to comment.
You can’t perform that action at this time.