1
|
|
|
<?php |
2
|
|
|
namespace Fructify\Reload\Command; |
3
|
|
|
|
4
|
|
|
use Symfony\Component\Console\Command\Command; |
5
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
6
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
7
|
|
|
use Symfony\Component\Console\Input\InputOption; |
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
9
|
|
|
use Fructify\Reload\Application\ServerApplication; |
10
|
|
|
|
11
|
|
|
class RunCommand extends Command |
12
|
|
|
{ |
13
|
|
|
protected function configure() |
14
|
|
|
{ |
15
|
|
|
$this->setName('server:run') |
16
|
|
|
->setAliases(array('sr')) |
17
|
|
|
->setDescription('Starts a live reload server.') |
18
|
|
|
->addArgument('address', InputArgument::OPTIONAL, 'Address:port', '127.0.0.1:35729') |
19
|
|
|
->addOption('config', '-c', InputOption::VALUE_OPTIONAL, 'Path to livereload.json') |
20
|
|
|
->addOption('no-watch', '', InputOption::VALUE_NONE, 'Disable watching') |
21
|
|
|
; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
25
|
|
|
{ |
26
|
|
|
$noWatching = $input->getOption('no-watch'); |
27
|
|
|
$address = $input->getArgument('address', '127.0.0.1:35729'); |
|
|
|
|
28
|
|
|
list($host, $port) = explode(':', $address); |
29
|
|
|
$output->writeln(sprintf("Server running on <info>http://%s</info>\n", $input->getArgument('address'))); |
30
|
|
|
$output->writeln('Quit the server with CONTROL-C.'); |
31
|
|
|
$output->writeln(''); |
32
|
|
|
$app = new ServerApplication($host, $port); |
33
|
|
|
if(!$noWatching){ |
34
|
|
|
$config = $this->loadConfig($input, $output); |
35
|
|
|
$app->watching($config['period'], $config); |
36
|
|
|
} |
37
|
|
|
$app->setOutput($output); |
38
|
|
|
$app->run(); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
protected function loadConfig(InputInterface $input, OutputInterface $output) |
|
|
|
|
42
|
|
|
{ |
43
|
|
|
$configFile = $input->getOption('config'); |
44
|
|
|
if($configFile === null){ |
45
|
|
|
$configFile = 'livereload.json'; |
46
|
|
|
} |
47
|
|
|
if(!file_exists($configFile)){ |
48
|
|
|
throw new \Exception("$configFile not found."); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
$config = json_decode(file_get_contents($configFile), true); |
52
|
|
|
return $config; |
53
|
|
|
} |
54
|
|
|
} |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.