1 | <?php namespace Arcanedev\Composer\Entities; |
||
11 | class PluginState |
||
12 | { |
||
13 | /* ------------------------------------------------------------------------------------------------ |
||
14 | | Properties |
||
15 | | ------------------------------------------------------------------------------------------------ |
||
16 | */ |
||
17 | /** @var \Composer\Composer */ |
||
18 | protected $composer; |
||
19 | |||
20 | /** @var array */ |
||
21 | protected $includes = []; |
||
22 | |||
23 | /** @var array */ |
||
24 | protected $requires = []; |
||
25 | |||
26 | /** @var array */ |
||
27 | protected $duplicateLinks = []; |
||
28 | |||
29 | /** @var bool */ |
||
30 | protected $devMode = false; |
||
31 | |||
32 | /** @var bool */ |
||
33 | protected $recurse = true; |
||
34 | |||
35 | /** @var bool */ |
||
36 | protected $replace = false; |
||
37 | |||
38 | /** |
||
39 | * Whether to merge the -dev sections. |
||
40 | * |
||
41 | * @var bool |
||
42 | */ |
||
43 | protected $mergeDev = true; |
||
44 | |||
45 | /** |
||
46 | * Whether to merge the extra section. |
||
47 | * |
||
48 | * By default, the extra section is not merged and there will be many cases where |
||
49 | * the merge of the extra section is performed too late to be of use to other plugins. |
||
50 | * When enabled, merging uses one of two strategies - either 'first wins' or 'last wins'. |
||
51 | * When enabled, 'first wins' is the default behaviour. If Replace mode is activated |
||
52 | * then 'last wins' is used. |
||
53 | * |
||
54 | * @var bool |
||
55 | */ |
||
56 | protected $mergeExtra = false; |
||
57 | |||
58 | /** |
||
59 | * Whether to merge the scripts section. |
||
60 | * |
||
61 | * @var bool $mergeScripts |
||
62 | */ |
||
63 | protected $mergeScripts = false; |
||
64 | |||
65 | /** |
||
66 | * Whether to merge the extra section in a deep / recursive way. |
||
67 | * |
||
68 | * By default the extra section is merged with array_merge() and duplicate keys are ignored. |
||
69 | * When enabled this allows to merge the arrays recursively using the following rule: |
||
70 | * Integer keys are merged, while array values are replaced where the later values overwrite the former. |
||
71 | * |
||
72 | * This is useful especially for the extra section when plugins use larger structures like a 'patches' key with |
||
73 | * the packages as sub-keys and the patches as values. |
||
74 | * |
||
75 | * When 'replace' mode is activated the order of array merges is exchanged. |
||
76 | * |
||
77 | * @var bool |
||
78 | */ |
||
79 | protected $mergeExtraDeep = false; |
||
80 | |||
81 | /** @var bool */ |
||
82 | protected $firstInstall = false; |
||
83 | |||
84 | /** @var bool */ |
||
85 | protected $locked = false; |
||
86 | |||
87 | /** @var bool */ |
||
88 | protected $dumpAutoloader = false; |
||
89 | |||
90 | /** @var bool */ |
||
91 | protected $optimizeAutoloader = false; |
||
92 | |||
93 | /* ------------------------------------------------------------------------------------------------ |
||
94 | | Constructor |
||
95 | | ------------------------------------------------------------------------------------------------ |
||
96 | */ |
||
97 | /** |
||
98 | * Make PluginState instance. |
||
99 | * |
||
100 | * @param \Composer\Composer $composer |
||
101 | */ |
||
102 | 175 | public function __construct(Composer $composer) |
|
106 | |||
107 | /* ------------------------------------------------------------------------------------------------ |
||
108 | | Getters & Setters |
||
109 | | ------------------------------------------------------------------------------------------------ |
||
110 | */ |
||
111 | /** |
||
112 | * Get list of filenames and/or glob patterns to include. |
||
113 | * |
||
114 | * @return array |
||
115 | */ |
||
116 | 140 | public function getIncludes() |
|
120 | |||
121 | /** |
||
122 | * Set the first install flag. |
||
123 | * |
||
124 | * @param bool $flag |
||
125 | * |
||
126 | * @return self |
||
127 | */ |
||
128 | 10 | public function setFirstInstall($flag) |
|
134 | |||
135 | /** |
||
136 | * Is this the first time that the plugin has been installed ? |
||
137 | * |
||
138 | * @return bool |
||
139 | */ |
||
140 | 150 | public function isFirstInstall() |
|
144 | |||
145 | /** |
||
146 | * Set the locked flag. |
||
147 | * |
||
148 | * @param bool $flag |
||
149 | * |
||
150 | * @return self |
||
151 | */ |
||
152 | 15 | public function setLocked($flag) |
|
158 | |||
159 | /** |
||
160 | * Was a lockfile present when the plugin was installed ? |
||
161 | * |
||
162 | * @return bool |
||
163 | */ |
||
164 | 20 | public function isLocked() |
|
168 | |||
169 | /** |
||
170 | * Should an update be forced ? |
||
171 | * |
||
172 | * @return bool |
||
173 | */ |
||
174 | 5 | public function forceUpdate() |
|
178 | |||
179 | /** |
||
180 | * Set the devMode flag. |
||
181 | * |
||
182 | * @param bool $flag |
||
183 | * |
||
184 | * @return self |
||
185 | */ |
||
186 | 140 | public function setDevMode($flag) |
|
192 | |||
193 | /** |
||
194 | * Should devMode settings be processed ? |
||
195 | * |
||
196 | * @return bool |
||
197 | */ |
||
198 | 135 | public function isDevMode() |
|
202 | |||
203 | /** |
||
204 | * Should devMode settings be merged? |
||
205 | * |
||
206 | * @return bool |
||
207 | */ |
||
208 | public function shouldMergeDev() |
||
212 | 140 | ||
213 | /** |
||
214 | 140 | * Set the dumpAutoloader flag. |
|
215 | * |
||
216 | * @param bool $flag |
||
217 | * |
||
218 | * @return self |
||
219 | */ |
||
220 | public function setDumpAutoloader($flag) |
||
226 | |||
227 | /** |
||
228 | * Is the autoloader file supposed to be written out ? |
||
229 | * |
||
230 | * @return bool |
||
231 | */ |
||
232 | public function shouldDumpAutoloader() |
||
236 | 140 | ||
237 | /** |
||
238 | 140 | * Set the optimizeAutoloader flag. |
|
239 | * |
||
240 | * @param bool $flag |
||
241 | * |
||
242 | * @return self |
||
243 | */ |
||
244 | public function setOptimizeAutoloader($flag) |
||
250 | |||
251 | /** |
||
252 | * Should the autoloader be optimized ? |
||
253 | * |
||
254 | * @return bool |
||
255 | */ |
||
256 | 135 | public function shouldOptimizeAutoloader() |
|
260 | |||
261 | /** |
||
262 | * Add duplicate packages. |
||
263 | * |
||
264 | * @param string $type |
||
265 | * @param array $packages |
||
266 | * |
||
267 | * @return self |
||
268 | */ |
||
269 | 80 | public function addDuplicateLinks($type, array $packages) |
|
270 | { |
||
271 | 80 | if ( ! isset($this->duplicateLinks[$type])) { |
|
272 | 80 | $this->duplicateLinks[$type] = []; |
|
273 | 64 | } |
|
274 | |||
275 | 80 | $this->duplicateLinks[$type] = array_merge( |
|
276 | 80 | $this->duplicateLinks[$type], |
|
277 | $packages |
||
278 | 64 | ); |
|
279 | |||
280 | 80 | return $this; |
|
281 | } |
||
282 | |||
283 | /** |
||
284 | * Should includes be recursively processed ? |
||
285 | * |
||
286 | * @return bool |
||
287 | */ |
||
288 | 135 | public function recurseIncludes() |
|
289 | { |
||
290 | 135 | return $this->recurse; |
|
291 | } |
||
292 | |||
293 | /** |
||
294 | * Get list of filenames and/or glob patterns to require |
||
295 | * |
||
296 | * @return array |
||
297 | */ |
||
298 | 140 | public function getRequires() |
|
299 | { |
||
300 | 140 | return $this->requires; |
|
301 | } |
||
302 | |||
303 | /** |
||
304 | * Get duplicate packages. |
||
305 | * |
||
306 | * @param string $type |
||
307 | * |
||
308 | * @return array |
||
309 | */ |
||
310 | 135 | public function getDuplicateLinks($type) |
|
311 | { |
||
312 | 135 | return isset($this->duplicateLinks[$type]) |
|
313 | 124 | ? $this->duplicateLinks[$type] |
|
314 | 135 | : []; |
|
315 | } |
||
316 | |||
317 | /** |
||
318 | * Should duplicate links be replaced in a 'last definition wins' order ? |
||
319 | * |
||
320 | * @return bool |
||
321 | */ |
||
322 | 110 | public function replaceDuplicateLinks() |
|
323 | { |
||
324 | 110 | return $this->replace; |
|
325 | } |
||
326 | |||
327 | /** |
||
328 | * Should the extra section be merged ? |
||
329 | * |
||
330 | * By default, the extra section is not merged and there will be many cases where |
||
331 | * the merge of the extra section is performed too late to be of use to other plugins. |
||
332 | * When enabled, merging uses one of two strategies - either 'first wins' or 'last wins'. |
||
333 | * When enabled, 'first wins' is the default behaviour. If Replace mode is activated |
||
334 | * then 'last wins' is used. |
||
335 | * |
||
336 | * @return bool |
||
337 | */ |
||
338 | 135 | public function shouldMergeExtra() |
|
339 | { |
||
340 | 135 | return $this->mergeExtra; |
|
341 | } |
||
342 | |||
343 | /** |
||
344 | * Should the extra section be merged deep / recursively? |
||
345 | * |
||
346 | * @return bool |
||
347 | */ |
||
348 | 30 | public function shouldMergeExtraDeep() |
|
349 | { |
||
350 | 30 | return $this->mergeExtraDeep; |
|
351 | } |
||
352 | |||
353 | /** |
||
354 | * Should the scripts section be merged? |
||
355 | * |
||
356 | * @return bool |
||
357 | */ |
||
358 | public function shouldMergeScripts() |
||
359 | { |
||
360 | 140 | return $this->mergeScripts; |
|
361 | } |
||
362 | 140 | ||
363 | 140 | /* ------------------------------------------------------------------------------------------------ |
|
364 | 140 | | Main Functions |
|
365 | 140 | | ------------------------------------------------------------------------------------------------ |
|
366 | 140 | */ |
|
367 | 140 | /** |
|
368 | 140 | * Load plugin settings. |
|
369 | 140 | */ |
|
370 | 140 | public function loadSettings() |
|
384 | |||
385 | /* ------------------------------------------------------------------------------------------------ |
||
386 | 140 | | Other Functions |
|
387 | | ------------------------------------------------------------------------------------------------ |
||
388 | 140 | */ |
|
389 | /** |
||
390 | 140 | * Merge config. |
|
391 | 112 | * |
|
392 | 112 | * @param array $extra |
|
393 | 112 | * |
|
394 | 112 | * @return array |
|
395 | 112 | */ |
|
396 | 112 | private function mergeConfig(array $extra) |
|
413 | } |
||
414 |