1 | <?php |
||
26 | class ResolveResult |
||
27 | { |
||
28 | /** |
||
29 | * @var Command |
||
30 | */ |
||
31 | private $command; |
||
32 | |||
33 | /** |
||
34 | * @var RawArgs |
||
35 | */ |
||
36 | private $rawArgs; |
||
37 | |||
38 | /** |
||
39 | * @var Args |
||
40 | */ |
||
41 | private $parsedArgs; |
||
42 | |||
43 | /** |
||
44 | * @var CannotParseArgsException |
||
45 | */ |
||
46 | private $parseError; |
||
47 | |||
48 | /** |
||
49 | * @var bool |
||
50 | */ |
||
51 | private $parsed = false; |
||
52 | |||
53 | /** |
||
54 | * Creates a new resolved command. |
||
55 | * |
||
56 | * @param Command $command The command. |
||
57 | * @param RawArgs $rawArgs The raw console arguments. |
||
58 | */ |
||
59 | 216 | public function __construct(Command $command, RawArgs $rawArgs) |
|
64 | |||
65 | /** |
||
66 | * Returns the command. |
||
67 | * |
||
68 | * @return Command The command. |
||
69 | */ |
||
70 | 215 | public function getCommand() |
|
74 | |||
75 | /** |
||
76 | * The raw console arguments. |
||
77 | * |
||
78 | * @return RawArgs The raw console arguments. |
||
79 | */ |
||
80 | public function getRawArgs() |
||
84 | |||
85 | /** |
||
86 | * Returns the parsed console arguments. |
||
87 | * |
||
88 | * @return Args The parsed console arguments or `null` if the console |
||
89 | * arguments cannot be parsed. |
||
90 | * |
||
91 | * @see isParsable(), getParseError() |
||
92 | */ |
||
93 | 215 | public function getParsedArgs() |
|
94 | { |
||
95 | 215 | if (!$this->parsed) { |
|
96 | $this->parse(); |
||
97 | } |
||
98 | |||
99 | 215 | return $this->parsedArgs; |
|
100 | } |
||
101 | |||
102 | /** |
||
103 | * Returns the error that happened during argument parsing. |
||
104 | * |
||
105 | * @return CannotParseArgsException The parse error or `null` if the |
||
106 | * arguments were parsed successfully. |
||
107 | * |
||
108 | * @see isParsable(), getParsedArgs() |
||
109 | */ |
||
110 | 1 | public function getParseError() |
|
111 | { |
||
112 | 1 | if (!$this->parsed) { |
|
113 | $this->parse(); |
||
114 | } |
||
115 | |||
116 | 1 | return $this->parseError; |
|
117 | } |
||
118 | |||
119 | /** |
||
120 | * Returns whether the console arguments can be parsed. |
||
121 | * |
||
122 | * @return bool Returns `true` if the console arguments can be parsed and |
||
123 | * `false` if a parse error occurred. |
||
124 | * |
||
125 | * @see getParsedArgs(), getParseError() |
||
126 | */ |
||
127 | 216 | public function isParsable() |
|
128 | { |
||
129 | 216 | if (!$this->parsed) { |
|
130 | 216 | $this->parse(); |
|
131 | } |
||
132 | |||
133 | 216 | return null === $this->parseError; |
|
134 | } |
||
135 | |||
136 | 216 | private function parse() |
|
146 | } |
||
147 |