1 | <?php |
||
2 | /** |
||
3 | * @author jan huang <[email protected]> |
||
4 | * @copyright 2017 |
||
5 | * |
||
6 | * @see https://www.github.com/janhuang |
||
7 | * @see http://www.fast-d.cn/ |
||
8 | */ |
||
9 | |||
10 | namespace FastD; |
||
11 | |||
12 | use FastD\Process\ProcessManager; |
||
13 | use Symfony\Component\Console\Input\ArgvInput; |
||
14 | use Symfony\Component\Console\Input\InputInterface; |
||
15 | use Symfony\Component\Console\Output\OutputInterface; |
||
16 | |||
17 | /** |
||
18 | * Class Processor. |
||
19 | */ |
||
20 | class Processor extends Console |
||
21 | { |
||
22 | public function registerCommands() |
||
23 | { |
||
24 | $command = new ProcessManager(); |
||
25 | |||
26 | $this->add($command); |
||
27 | |||
28 | $path = app()->getPath().'/config/process.php'; |
||
29 | |||
30 | if (file_exists($path)) { |
||
31 | config()->set('processes', include $path); |
||
32 | } |
||
33 | } |
||
34 | |||
35 | /** |
||
36 | * @param InputInterface|null $input |
||
37 | * @param OutputInterface|null $output |
||
38 | * |
||
39 | * @return int |
||
40 | * |
||
41 | * @throws \Exception |
||
42 | */ |
||
43 | public function run(InputInterface $input = null, OutputInterface $output = null) |
||
0 ignored issues
–
show
|
|||
44 | { |
||
45 | $argv = $_SERVER['argv']; |
||
46 | $script = array_shift($argv); |
||
47 | array_unshift($argv, 'process'); |
||
48 | array_unshift($argv, $script); |
||
49 | |||
50 | return parent::run(new ArgvInput($argv), $output); |
||
51 | } |
||
52 | } |
||
53 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: