1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the webmozart/console package. |
5
|
|
|
* |
6
|
|
|
* (c) Bernhard Schussek <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Webmozart\Console\Handler\Help; |
13
|
|
|
|
14
|
|
|
use RuntimeException; |
15
|
|
|
use Symfony\Component\Process\ExecutableFinder; |
16
|
|
|
use Webmozart\Assert\Assert; |
17
|
|
|
use Webmozart\Console\Process\ProcessLauncher; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @since 1.0 |
21
|
|
|
* |
22
|
|
|
* @author Bernhard Schussek <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
class HelpManHandler |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
private $path; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
private $manBinary; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var ExecutableFinder |
38
|
|
|
*/ |
39
|
|
|
private $executableFinder; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var ProcessLauncher |
43
|
|
|
*/ |
44
|
|
|
private $processLauncher; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Creates a new AsciiDoc descriptor. |
48
|
|
|
* |
49
|
|
|
* @param ExecutableFinder $executableFinder The finder used to find the |
|
|
|
|
50
|
|
|
* "man" binary. |
51
|
|
|
* @param ProcessLauncher $processLauncher The launcher for executing the |
|
|
|
|
52
|
|
|
* "man" binary. |
53
|
|
|
*/ |
54
|
19 |
View Code Duplication |
public function __construct($path, ExecutableFinder $executableFinder = null, ProcessLauncher $processLauncher = null) |
|
|
|
|
55
|
|
|
{ |
56
|
19 |
|
Assert::file($path); |
57
|
|
|
|
58
|
19 |
|
$this->path = $path; |
59
|
19 |
|
$this->executableFinder = $executableFinder ?: new ExecutableFinder(); |
60
|
19 |
|
$this->processLauncher = $processLauncher ?: new ProcessLauncher(); |
61
|
19 |
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* {@inheritdoc} |
65
|
|
|
*/ |
66
|
17 |
|
public function handle() |
67
|
|
|
{ |
68
|
17 |
|
if (!$this->processLauncher->isSupported()) { |
69
|
1 |
|
throw new RuntimeException('The ProcessLauncher must be supported for the man help to run.'); |
70
|
|
|
} |
71
|
|
|
|
72
|
16 |
|
if (!$this->manBinary) { |
73
|
10 |
|
$this->manBinary = $this->executableFinder->find('man'); |
74
|
|
|
} |
75
|
|
|
|
76
|
16 |
|
if (!$this->manBinary) { |
77
|
1 |
|
throw new RuntimeException('The "man" binary was not found.'); |
78
|
|
|
} |
79
|
|
|
|
80
|
15 |
|
return $this->processLauncher->launchProcess( |
81
|
15 |
|
escapeshellcmd($this->manBinary).' -l %path%', |
82
|
15 |
|
array('path' => $this->path), |
83
|
15 |
|
false |
84
|
|
|
); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return string |
89
|
|
|
*/ |
90
|
|
|
public function getManBinary() |
91
|
|
|
{ |
92
|
|
|
return $this->manBinary; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @param string $manBinary |
97
|
|
|
*/ |
98
|
14 |
|
public function setManBinary($manBinary) |
99
|
|
|
{ |
100
|
14 |
|
$this->manBinary = $manBinary; |
101
|
14 |
|
} |
102
|
|
|
} |
103
|
|
|
|
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.