|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of SebastianFeldmann\Cli. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Sebastian Feldmann <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
namespace SebastianFeldmann\Cli\Command\Runner; |
|
11
|
|
|
|
|
12
|
|
|
use SebastianFeldmann\Cli\Command\Result as CommandResult; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class Result |
|
16
|
|
|
* |
|
17
|
|
|
* @package SebastianFeldmann\Cli |
|
18
|
|
|
* @author Sebastian Feldmann <[email protected]> |
|
19
|
|
|
* @link https://github.com/sebastianfeldmann/cli |
|
20
|
|
|
* @since Class available since Release 0.9.0 |
|
21
|
|
|
*/ |
|
22
|
|
|
class Result |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* Result of executed command. |
|
26
|
|
|
* |
|
27
|
|
|
* @var \SebastianFeldmann\Cli\Command\Result |
|
28
|
|
|
*/ |
|
29
|
|
|
private $cmdResult; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Formatted output of executed result. |
|
33
|
|
|
* |
|
34
|
|
|
* @var iterable |
|
35
|
|
|
*/ |
|
36
|
|
|
private $formatted; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Result constructor. |
|
40
|
|
|
* |
|
41
|
|
|
* @param \SebastianFeldmann\Cli\Command\Result $cmdResult |
|
42
|
|
|
* @param iterable $formatted |
|
43
|
|
|
*/ |
|
44
|
10 |
|
public function __construct(CommandResult $cmdResult, $formatted = []) |
|
45
|
|
|
{ |
|
46
|
10 |
|
$this->cmdResult = $cmdResult; |
|
47
|
10 |
|
$this->formatted = $formatted; |
|
48
|
10 |
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Get the raw command result. |
|
52
|
|
|
* |
|
53
|
|
|
* @return \SebastianFeldmann\Cli\Command\Result |
|
54
|
|
|
*/ |
|
55
|
1 |
|
public function getCommandResult() : CommandResult |
|
56
|
|
|
{ |
|
57
|
1 |
|
return $this->cmdResult; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Return true if command execution was successful. |
|
62
|
|
|
* |
|
63
|
|
|
* @return bool |
|
64
|
|
|
*/ |
|
65
|
1 |
|
public function isSuccessful() : bool |
|
66
|
|
|
{ |
|
67
|
1 |
|
return $this->cmdResult->isSuccessful(); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Return the executed cli command. |
|
72
|
|
|
* |
|
73
|
|
|
* @return string |
|
74
|
|
|
*/ |
|
75
|
1 |
|
public function getCmd() : string |
|
76
|
|
|
{ |
|
77
|
1 |
|
return $this->cmdResult->getCmd(); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Return commands output to stdOut. |
|
82
|
|
|
* |
|
83
|
|
|
* @return string |
|
84
|
|
|
*/ |
|
85
|
1 |
|
public function getStdOut() : string |
|
86
|
|
|
{ |
|
87
|
1 |
|
return $this->cmdResult->getStdOut(); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Return commands error output to stdErr. |
|
92
|
|
|
* |
|
93
|
|
|
* @return string |
|
94
|
|
|
*/ |
|
95
|
1 |
|
public function getStdErr() : string |
|
96
|
|
|
{ |
|
97
|
1 |
|
return $this->cmdResult->getStdErr(); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Is the output redirected to a file. |
|
102
|
|
|
* |
|
103
|
|
|
* @return bool |
|
104
|
|
|
*/ |
|
105
|
2 |
|
public function isOutputRedirected() : bool |
|
106
|
|
|
{ |
|
107
|
2 |
|
return $this->cmdResult->isOutputRedirected(); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* Return path to the file where the output is redirected to. |
|
112
|
|
|
* |
|
113
|
|
|
* @return string |
|
114
|
|
|
*/ |
|
115
|
2 |
|
public function getRedirectPath() : string |
|
116
|
|
|
{ |
|
117
|
2 |
|
return $this->cmdResult->getRedirectPath(); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* Return cmd output as array. |
|
122
|
|
|
* |
|
123
|
|
|
* @return array |
|
124
|
|
|
*/ |
|
125
|
2 |
|
public function getBufferedOutput() : array |
|
126
|
|
|
{ |
|
127
|
2 |
|
return $this->cmdResult->getStdOutAsArray(); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* Return formatted output. |
|
132
|
|
|
* |
|
133
|
|
|
* @return iterable |
|
134
|
|
|
*/ |
|
135
|
1 |
|
public function getFormattedOutput() |
|
136
|
|
|
{ |
|
137
|
1 |
|
return $this->formatted; |
|
138
|
|
|
} |
|
139
|
|
|
} |
|
140
|
|
|
|