1 | <?php |
||
25 | class Command |
||
26 | { |
||
27 | /** |
||
28 | * @var string |
||
29 | */ |
||
30 | private $executable; |
||
31 | |||
32 | /** |
||
33 | * @var array |
||
34 | */ |
||
35 | private $options = array(); |
||
36 | |||
37 | /** |
||
38 | * @var array |
||
39 | */ |
||
40 | private $arguments = array(); |
||
41 | |||
42 | /** |
||
43 | * @var string |
||
44 | */ |
||
45 | private $command; |
||
46 | |||
47 | /** |
||
48 | * @var array |
||
49 | */ |
||
50 | private $parameters = array(); |
||
51 | |||
52 | /** |
||
53 | * Every command must have an executable |
||
54 | * |
||
55 | * @param $executable |
||
56 | */ |
||
57 | public function __construct($executable) |
||
61 | |||
62 | /** |
||
63 | * Adds a parameter to the command, will be appended |
||
64 | * in the same order as insertion at the end |
||
65 | * |
||
66 | * @param $parameter |
||
67 | */ |
||
68 | public function addParameter($parameter) |
||
72 | |||
73 | /** |
||
74 | * Adds an option to the command, will be |
||
75 | * appended to the command in the next format: |
||
76 | * |
||
77 | * <pre> |
||
78 | * -aBLs |
||
79 | * </pre> |
||
80 | * |
||
81 | * @param $option |
||
82 | */ |
||
83 | public function addOption($option) |
||
87 | |||
88 | /** |
||
89 | * Adds an argument to the command. If the argument |
||
90 | * is more than one letter, "-- " will be appended before |
||
91 | * if not, it will act as an option with a value: |
||
92 | * |
||
93 | * <pre> |
||
94 | * --argument [value] |
||
95 | * -p [value] |
||
96 | * </pre> |
||
97 | * |
||
98 | * @param $name |
||
99 | * @param bool|mixed $value |
||
100 | */ |
||
101 | public function addArgument($name, $value = true) |
||
105 | |||
106 | /** |
||
107 | * @param $executable |
||
108 | */ |
||
109 | public function setExecutable($executable) |
||
113 | |||
114 | /** |
||
115 | * @return string |
||
116 | */ |
||
117 | public function getExecutable() |
||
121 | |||
122 | /** |
||
123 | * Constructs the command appendind options, |
||
124 | * arguments, executable and parameters |
||
125 | * |
||
126 | * @return string |
||
127 | */ |
||
128 | protected function constructCommand() |
||
155 | |||
156 | /** |
||
157 | * Gets the command string |
||
158 | * |
||
159 | * @return mixed |
||
160 | */ |
||
161 | public function getCommand() |
||
169 | |||
170 | /** |
||
171 | * @see getCommand |
||
172 | * @return mixed |
||
173 | */ |
||
174 | public function __toString() |
||
178 | |||
179 | /** |
||
180 | * Execute command, with optional output printer |
||
181 | * |
||
182 | * @param bool $showOutput |
||
183 | */ |
||
184 | public function execute($showOutput = false) |
||
194 | |||
195 | /** |
||
196 | * Execute and buffers command result to print it |
||
197 | * |
||
198 | * @throws \InvalidArgumentException When the command couldn't be executed |
||
199 | */ |
||
200 | private function executeWithOutput() |
||
213 | } |
||
214 |