daux.io/libs/Console/Serve.php

56 regels
1.9 KiB
PHP

<?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()
{
parent::configure();
$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);
// Daux can only serve HTML
$daux->getParams()->setFormat('html');
chdir(__DIR__ . '/../../');
putenv('DAUX_VERBOSITY=' . $output->getVerbosity());
putenv('DAUX_SOURCE=' . $daux->getParams()->getDocumentationDirectory());
putenv('DAUX_THEME=' . $daux->getParams()->getThemesPath());
putenv('DAUX_CONFIGURATION=' . $daux->getParams()->getConfigurationOverrideFile());
2018-05-05 18:16:24 +02:00
putenv('DAUX_EXTENSION=' . DAUX_EXTENSION);
$base = escapeshellarg(__DIR__ . '/../../');
$binary = escapeshellarg((new PhpExecutableFinder)->find(false));
echo "Daux development server started on http://{$host}:{$port}/\n";
2018-09-20 20:17:51 +02:00
passthru("{$binary} -S {$host}:{$port} {$base}/index.php");
2019-11-28 22:41:53 +01:00
return 0;
}
}