1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhalconExt\Cli\Middleware; |
4
|
|
|
|
5
|
|
|
use Ahc\Cli\Input\Command; |
|
|
|
|
6
|
|
|
use Phalcon\Cli\Console; |
|
|
|
|
7
|
|
|
use Phalcon\Cli\Task; |
|
|
|
|
8
|
|
|
use PhalconExt\Di\ProvidesDi; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Factory middleware that injects Parser instance and responses to `--help` or `--version`. |
12
|
|
|
*/ |
13
|
|
|
class Factory |
14
|
|
|
{ |
15
|
|
|
use ProvidesDi; |
16
|
|
|
|
17
|
|
|
public function before(Console $console) |
18
|
|
|
{ |
19
|
|
|
$rawArgv = $console->argv($raw = true); |
20
|
|
|
$argv = $console->argv($raw = false); |
21
|
|
|
$app = $console->app(); |
22
|
|
|
$command = $app->commandFor($argv); |
23
|
|
|
|
24
|
|
|
if ($this->isVersion($rawArgv)) { |
25
|
|
|
return $command->showVersion(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
if ($this->isGlobalHelp($rawArgv)) { |
29
|
|
|
return $app->showHelp(); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
if ($this->isHelp($rawArgv)) { |
33
|
|
|
return $command->showHelp(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
$this->di()->setShared('command', $app->parse($argv)); |
37
|
|
|
|
38
|
|
|
return true; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
protected function isGlobalHelp(array $argv): bool |
42
|
|
|
{ |
43
|
|
|
// For a specific help, it would be [cmd, task, action, --help] |
44
|
|
|
// If it is just [cmd, --help] then we deduce it is global help! |
45
|
|
|
|
46
|
|
|
$isGlobal = ($argv[1][0] ?? '-') === '-' && ($argv[2][0] ?? '-') === '-'; |
47
|
|
|
|
48
|
|
|
return $isGlobal && $this->isHelp($argv); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
protected function isHelp(array $argv): bool |
52
|
|
|
{ |
53
|
|
|
return \in_array('--help', $argv) || \in_array('-h', $argv); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
protected function isVersion(array $argv): bool |
57
|
|
|
{ |
58
|
|
|
return \in_array('--version', $argv) || \in_array('-V', $argv); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths