Completed
Push — master ( 01dfa3...bd9515 )
by C
05:18
created

ServerCommand::doWork()   B

Complexity

Conditions 3
Paths 2

Size

Total Lines 37
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 37
ccs 19
cts 19
cp 1
rs 8.8571
cc 3
eloc 21
nc 2
nop 2
crap 3
1
<?php
2
namespace Tartana\Console\Command;
3
4
use League\Flysystem\Config;
5
use Monolog\Logger;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Input\InputOption;
8
use Symfony\Component\Console\Output\OutputInterface;
9
use Tartana\Component\Command\Command;
10
11
class ServerCommand extends AbstractDaemonCommand
12
{
13
14 4
	protected function configure()
15
	{
16 4
		parent::configure();
17
18 4
		$this->setName('server');
19 4
		$this->setDescription('Runs Tartana own web server!');
20
21 4
		$this->addOption('port', 'p', InputOption::VALUE_OPTIONAL, 'The port listening to.', 8000);
22 4
	}
23
24 2
	protected function doWork(InputInterface $input, OutputInterface $output)
25
	{
26
		// Getting arguments
27 2
		$port = (int)$input->getOption('port');
28 2
		$environment = $input->getOption('env');
29
30 2
		$this->log('Starting server on port ' . $port, Logger::INFO);
31
32
		// On restricted environments we need to be in the web folder
33 2
		chdir(TARTANA_PATH_ROOT . '/web');
34 2
		$command = new Command('php');
35 2
		$command->setAsync(true);
36 2
		$command->setCaptureErrorInOutput(true);
37 2
		$command->addArgument('-S 0.0.0.0:' . $port, false);
38 2
		$command->addArgument(
39 2
				TARTANA_PATH_ROOT . '/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Resources/config/router_' . $environment . '.php');
40 2
		$pid = $this->getCommandRunner()->execute($command);
41
42 2
		$this->attachPid($input, $pid);
43
44
		do
45
		{
46 2
			$output = trim($this->getCommandRunner()->execute(Command::getAppCommand('default')));
47 2
			if ($output)
48
			{
49 2
				$this->log('Default command returned with output, set log level to debug to get the reason', Logger::ERROR);
50 2
				$this->log('Output was: ' . $output);
51
			}
52
			else
53
			{
54
				// @codeCoverageIgnoreStart
55
				sleep(10);
56
				// @codeCoverageIgnoreEnd
57
			}
58
		}
59 2
		while (!$output);
60 2
	}
61
}
62