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