Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 15 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| CliApp | |
0.00% |
0 / 15 |
|
0.00% |
0 / 4 |
42 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| init | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| process | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
12 | |||
| handleException | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Dynart\Micro; |
| 4 | |
| 5 | /** |
| 6 | * Handles CLI commands |
| 7 | * @package Dynart\Micro |
| 8 | */ |
| 9 | class CliApp extends App { |
| 10 | |
| 11 | /** @var CliCommands */ |
| 12 | protected $commands; |
| 13 | |
| 14 | /** @var CliOutput */ |
| 15 | protected $output; |
| 16 | |
| 17 | public function __construct(array $configPaths) { |
| 18 | parent::__construct($configPaths); |
| 19 | Micro::add(CliCommands::class); |
| 20 | Micro::add(CliOutput::class); |
| 21 | } |
| 22 | |
| 23 | public function init() { |
| 24 | $this->commands = Micro::get(CliCommands::class); |
| 25 | } |
| 26 | |
| 27 | public function process() { |
| 28 | list($callable, $params) = $this->commands->matchCurrent(); |
| 29 | if ($callable) { |
| 30 | $callable = Micro::getCallable($callable); |
| 31 | if (empty($params)) { |
| 32 | $content = call_user_func($callable); |
| 33 | } else { |
| 34 | $content = call_user_func_array($callable, [$params]); |
| 35 | } |
| 36 | $this->finish($content); |
| 37 | } else { |
| 38 | error_log("Unknown command: ".$this->commands->current()); |
| 39 | $this->finish(1); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | protected function handleException(\Exception $e) { |
| 44 | parent::handleException($e); |
| 45 | $this->finish(1); |
| 46 | } |
| 47 | } |