1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the PHALCON-EXT package. |
5
|
|
|
* |
6
|
|
|
* (c) Jitendra Adhikari <[email protected]> |
7
|
|
|
* <https://github.com/adhocore> |
8
|
|
|
* |
9
|
|
|
* Licensed under MIT license. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace PhalconExt\Cli\Middleware; |
13
|
|
|
|
14
|
|
|
use Ahc\Cli\Input\Command; |
15
|
|
|
use Phalcon\Cli\Console; |
|
|
|
|
16
|
|
|
use Phalcon\Cli\Task; |
|
|
|
|
17
|
|
|
use PhalconExt\Di\ProvidesDi; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Factory middleware that injects Command and responds to `--help` or `--version`. |
21
|
|
|
*/ |
22
|
|
|
class Factory |
23
|
|
|
{ |
24
|
|
|
use ProvidesDi; |
25
|
|
|
|
26
|
|
|
public function before(Console $console) |
27
|
|
|
{ |
28
|
|
|
$rawArgv = $console->argv($raw = true); |
29
|
|
|
$argv = $console->argv($raw = false); |
30
|
|
|
$app = $console->app(); |
31
|
|
|
$command = $app->commandFor($argv); |
32
|
|
|
|
33
|
|
|
if ($this->isVersion($rawArgv)) { |
34
|
|
|
return $command->showVersion(); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
if ($this->isGlobalHelp($rawArgv)) { |
38
|
|
|
return $app->showHelp(); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
if ($this->isHelp($rawArgv)) { |
42
|
|
|
return $command->showHelp(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
$this->di()->setShared('command', $app->parse($argv)); |
46
|
|
|
|
47
|
|
|
return true; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
protected function isGlobalHelp(array $argv): bool |
51
|
|
|
{ |
52
|
|
|
// For a specific help, it would be [cmd, task, action, --help] |
53
|
|
|
// If it is just [cmd, --help] then we deduce it is global help! |
54
|
|
|
|
55
|
|
|
$isGlobal = ($argv[1][0] ?? '-') === '-' && ($argv[2][0] ?? '-') === '-'; |
56
|
|
|
|
57
|
|
|
return $isGlobal && $this->isHelp($argv); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
protected function isHelp(array $argv): bool |
61
|
|
|
{ |
62
|
|
|
return \in_array('--help', $argv) || \in_array('-h', $argv); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
protected function isVersion(array $argv): bool |
66
|
|
|
{ |
67
|
|
|
return \in_array('--version', $argv) || \in_array('-V', $argv); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
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