1 | <?php |
||
21 | abstract class AbstractAnsibleCommand |
||
22 | { |
||
23 | /** |
||
24 | * @var ProcessBuilder |
||
25 | */ |
||
26 | protected $processBuilder; |
||
27 | |||
28 | /** |
||
29 | * @var array |
||
30 | */ |
||
31 | private $options; |
||
32 | |||
33 | /** |
||
34 | * @var array |
||
35 | */ |
||
36 | private $parameters; |
||
37 | |||
38 | /** |
||
39 | * @var array |
||
40 | */ |
||
41 | private $baseOptions; |
||
42 | |||
43 | /** |
||
44 | * @param ProcessBuilder $processBuilder |
||
45 | */ |
||
46 | 13 | public function __construct(ProcessBuilder $processBuilder) |
|
47 | { |
||
48 | 13 | $this->processBuilder = $processBuilder; |
|
49 | 13 | $this->options = []; |
|
50 | 13 | $this->parameters = []; |
|
51 | 13 | $this->baseOptions = []; |
|
52 | 13 | } |
|
53 | |||
54 | /** |
||
55 | * Get parameter string which will be used to call ansible. |
||
56 | * |
||
57 | * @param bool $asArray |
||
58 | * @return string[] |
||
59 | */ |
||
60 | 43 | protected function prepareArguments($asArray = true) |
|
61 | { |
||
62 | 43 | $arguments = array_merge( |
|
63 | 43 | [$this->getBaseOptions()], |
|
64 | 43 | $this->getOptions(), |
|
65 | 43 | $this->getParameters() |
|
66 | 43 | ); |
|
67 | |||
68 | 43 | if (false === $asArray) { |
|
69 | 6 | $arguments = implode(' ', $arguments); |
|
70 | 6 | } |
|
71 | |||
72 | 43 | return $arguments; |
|
73 | } |
||
74 | |||
75 | /** |
||
76 | * Add an Option. |
||
77 | * |
||
78 | * @param string $name |
||
79 | * @param string $value |
||
80 | */ |
||
81 | 16 | protected function addOption($name, $value) |
|
85 | |||
86 | /** |
||
87 | * Add a parameter. |
||
88 | * |
||
89 | * @param string $name |
||
90 | */ |
||
91 | 19 | protected function addParameter($name) |
|
95 | |||
96 | /** |
||
97 | * Get all options as array. |
||
98 | * |
||
99 | * @return string |
||
100 | */ |
||
101 | 43 | protected function getOptions() |
|
102 | { |
||
103 | 43 | $options = []; |
|
104 | |||
105 | 43 | foreach ($this->options as $name => $value) { |
|
106 | 33 | $options[] = $name . '=' . $value; |
|
107 | 43 | } |
|
108 | |||
109 | 43 | return $options; |
|
110 | } |
||
111 | |||
112 | /** |
||
113 | * Get all parameters as array. |
||
114 | * |
||
115 | * @return string |
||
116 | */ |
||
117 | 43 | protected function getParameters() |
|
121 | |||
122 | |||
123 | /** |
||
124 | * Add base options to internal storage. |
||
125 | * |
||
126 | * @param string $baseOption |
||
127 | * @return $this |
||
128 | */ |
||
129 | 41 | protected function addBaseoption($baseOption) |
|
130 | { |
||
131 | 41 | $this->baseOptions[] = $baseOption; |
|
132 | |||
133 | 41 | return $this; |
|
134 | } |
||
135 | |||
136 | /** |
||
137 | * Generate base options string. |
||
138 | * |
||
139 | * @return string |
||
140 | */ |
||
141 | 43 | protected function getBaseOptions() |
|
145 | |||
146 | /** |
||
147 | * Check if param is array or string and implode with glue if necessary. |
||
148 | * |
||
149 | * @param string|array $param |
||
150 | * @param string $glue |
||
151 | * @return string |
||
152 | */ |
||
153 | 9 | protected function checkParam($param, $glue = ' ') |
|
154 | { |
||
155 | 9 | if (is_array($param)) { |
|
156 | 6 | $param = implode($glue, $param); |
|
157 | 6 | } |
|
158 | |||
159 | 9 | return $param; |
|
160 | } |
||
161 | |||
162 | /** |
||
163 | * Creates process with process builder and executes it. |
||
164 | * |
||
165 | * @param null $callback |
||
166 | * @return int|string |
||
167 | */ |
||
168 | 2 | protected function runProcess($callback) |
|
190 | } |
||
191 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: