Skip to content

Commit

Permalink
Allow user to specify a php.ini in ServerShell
Browse files Browse the repository at this point in the history
  • Loading branch information
josegonzalez committed Jan 29, 2018
1 parent 6e1db35 commit 01cf28b
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions src/Shell/ServerShell.php
Expand Up @@ -59,6 +59,13 @@ class ServerShell extends Shell
*/
protected $_documentRoot;

/**
* ini path
*
* @var string
*/
protected $_iniPath;

/**
* Override initialize of the Shell
*
Expand All @@ -69,6 +76,7 @@ public function initialize()
$this->_host = self::DEFAULT_HOST;
$this->_port = self::DEFAULT_PORT;
$this->_documentRoot = WWW_ROOT;
$this->_iniPath = '';
}

/**
Expand All @@ -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) {
Expand All @@ -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();
}
Expand All @@ -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();
}

Expand All @@ -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>'));
Expand All @@ -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'
Expand Down

0 comments on commit 01cf28b

Please sign in to comment.