2016-07-29 07:58:48 +02:00
|
|
|
<?php namespace Todaymade\Daux\Console;
|
|
|
|
|
|
|
|
use Exception;
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
use Symfony\Component\Process\PhpExecutableFinder;
|
|
|
|
use Symfony\Component\Process\ProcessUtils;
|
|
|
|
use Todaymade\Daux\Daux;
|
|
|
|
use Todaymade\Daux\Server\Server;
|
|
|
|
|
|
|
|
class Serve extends DauxCommand
|
|
|
|
{
|
|
|
|
protected function configure()
|
|
|
|
{
|
2017-11-05 23:56:46 +01:00
|
|
|
parent::configure();
|
|
|
|
|
2016-07-29 07:58:48 +02:00
|
|
|
$this
|
|
|
|
->setName('serve')
|
|
|
|
->setDescription('Serve documentation')
|
|
|
|
|
|
|
|
// Serve the current documentation
|
|
|
|
->addOption('serve', null, InputOption::VALUE_NONE, 'Serve the current directory')
|
|
|
|
->addOption('host', null, InputOption::VALUE_REQUIRED, 'The host to serve on', 'localhost')
|
|
|
|
->addOption('port', null, InputOption::VALUE_REQUIRED, 'The port to serve on', 8085);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output)
|
|
|
|
{
|
|
|
|
$host = $input->getOption('host');
|
|
|
|
$port = $input->getOption('port');
|
|
|
|
|
2018-06-05 20:31:51 +02:00
|
|
|
$daux = $this->prepareDaux($input, $output);
|
2016-07-29 07:58:48 +02:00
|
|
|
|
|
|
|
// Daux can only serve HTML
|
|
|
|
$daux->getParams()->setFormat('html');
|
|
|
|
|
|
|
|
chdir(__DIR__ . '/../../');
|
|
|
|
|
|
|
|
putenv('DAUX_SOURCE=' . $daux->getParams()->getDocumentationDirectory());
|
2016-09-12 23:58:58 +02:00
|
|
|
putenv('DAUX_THEME=' . $daux->getParams()->getThemesPath());
|
2016-09-15 17:20:24 +02:00
|
|
|
putenv('DAUX_CONFIGURATION=' . $daux->getParams()->getConfigurationOverrideFile());
|
2018-05-05 18:16:24 +02:00
|
|
|
putenv('DAUX_EXTENSION=' . DAUX_EXTENSION);
|
2016-07-29 07:58:48 +02:00
|
|
|
|
2018-08-13 08:42:14 +02:00
|
|
|
$base = escapeshellarg(__DIR__ . '/../../');
|
|
|
|
$binary = escapeshellarg((new PhpExecutableFinder)->find(false));
|
2016-07-29 07:58:48 +02:00
|
|
|
|
|
|
|
echo "Daux development server started on http://{$host}:{$port}/\n";
|
|
|
|
|
|
|
|
if (defined('HHVM_VERSION')) {
|
|
|
|
if (version_compare(HHVM_VERSION, '3.8.0') >= 0) {
|
|
|
|
passthru("{$binary} -m server -v Server.Type=proxygen -v Server.SourceRoot={$base}/ -v Server.IP={$host} -v Server.Port={$port} -v Server.DefaultDocument=server.php -v Server.ErrorDocument404=server.php");
|
|
|
|
} else {
|
|
|
|
throw new Exception("HHVM's built-in server requires HHVM >= 3.8.0.");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
passthru("{$binary} -S {$host}:{$port} {$base}/index.php");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|