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;
|
2019-12-05 21:25:58 +01:00
|
|
|
use Symfony\Component\Console\Terminal;
|
2016-07-29 07:58:48 +02:00
|
|
|
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')
|
|
|
|
|
|
|
|
->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');
|
|
|
|
|
2019-12-05 21:25:58 +01:00
|
|
|
$builder = $this->prepareConfig(Daux::LIVE_MODE, $input, $output);
|
2016-07-29 07:58:48 +02:00
|
|
|
|
|
|
|
// Daux can only serve HTML
|
2019-12-05 21:25:58 +01:00
|
|
|
$builder->withFormat('html');
|
|
|
|
|
|
|
|
$daux = new Daux($builder->build(), $output);
|
|
|
|
|
|
|
|
$width = (new Terminal)->getWidth();
|
|
|
|
|
|
|
|
// Instiantiate the processor if one is defined
|
|
|
|
$this->prepareProcessor($daux, $width);
|
|
|
|
|
|
|
|
// Write the current configuration to a file to read it from the other serving side
|
|
|
|
$file = tmpfile();
|
|
|
|
$path = stream_get_meta_data($file)['uri'];
|
|
|
|
fwrite($file, serialize($daux->getConfig()));
|
2016-07-29 07:58:48 +02:00
|
|
|
|
|
|
|
chdir(__DIR__ . '/../../');
|
|
|
|
|
2019-12-05 21:25:58 +01:00
|
|
|
putenv('DAUX_CONFIG='. $path);
|
2019-11-26 22:43:12 +01:00
|
|
|
putenv('DAUX_VERBOSITY=' . $output->getVerbosity());
|
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";
|
|
|
|
|
2018-09-20 20:17:51 +02:00
|
|
|
passthru("{$binary} -S {$host}:{$port} {$base}/index.php");
|
2019-12-05 21:25:58 +01:00
|
|
|
fclose($file);
|
2019-11-28 22:41:53 +01:00
|
|
|
|
|
|
|
return 0;
|
2016-07-29 07:58:48 +02:00
|
|
|
}
|
|
|
|
}
|