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 | /** @var bool $ignore */ |
||
39 | protected $ignore = false; |
||
40 | |||
41 | /** |
||
42 | * Whether to merge the -dev sections. |
||
43 | * |
||
44 | * @var bool |
||
45 | */ |
||
46 | protected $mergeDev = true; |
||
47 | |||
48 | /** |
||
49 | * Whether to merge the extra section. |
||
50 | * |
||
51 | * By default, the extra section is not merged and there will be many cases where |
||
52 | * the merge of the extra section is performed too late to be of use to other plugins. |
||
53 | * When enabled, merging uses one of two strategies - either 'first wins' or 'last wins'. |
||
54 | * When enabled, 'first wins' is the default behaviour. If Replace mode is activated |
||
55 | * then 'last wins' is used. |
||
56 | * |
||
57 | * @var bool |
||
58 | */ |
||
59 | protected $mergeExtra = false; |
||
60 | |||
61 | /** |
||
62 | * Whether to merge the scripts section. |
||
63 | * |
||
64 | * @var bool $mergeScripts |
||
65 | */ |
||
66 | protected $mergeScripts = false; |
||
67 | |||
68 | /** |
||
69 | * Whether to merge the extra section in a deep / recursive way. |
||
70 | * |
||
71 | * By default the extra section is merged with array_merge() and duplicate keys are ignored. |
||
72 | * When enabled this allows to merge the arrays recursively using the following rule: |
||
73 | * Integer keys are merged, while array values are replaced where the later values overwrite the former. |
||
74 | * |
||
75 | * This is useful especially for the extra section when plugins use larger structures like a 'patches' key with |
||
76 | * the packages as sub-keys and the patches as values. |
||
77 | * |
||
78 | * When 'replace' mode is activated the order of array merges is exchanged. |
||
79 | * |
||
80 | * @var bool |
||
81 | */ |
||
82 | protected $mergeExtraDeep = false; |
||
83 | |||
84 | /** @var bool */ |
||
85 | protected $firstInstall = false; |
||
86 | |||
87 | /** @var bool */ |
||
88 | protected $locked = false; |
||
89 | |||
90 | /** @var bool */ |
||
91 | protected $dumpAutoloader = false; |
||
92 | |||
93 | /** @var bool */ |
||
94 | protected $optimizeAutoloader = false; |
||
95 | |||
96 | /* ------------------------------------------------------------------------------------------------ |
||
97 | | Constructor |
||
98 | | ------------------------------------------------------------------------------------------------ |
||
99 | */ |
||
100 | /** |
||
101 | * Make PluginState instance. |
||
102 | * |
||
103 | * @param \Composer\Composer $composer |
||
104 | */ |
||
105 | 123 | public function __construct(Composer $composer) |
|
109 | |||
110 | /* ------------------------------------------------------------------------------------------------ |
||
111 | | Getters & Setters |
||
112 | | ------------------------------------------------------------------------------------------------ |
||
113 | */ |
||
114 | /** |
||
115 | * Get list of filenames and/or glob patterns to include. |
||
116 | * |
||
117 | * @return array |
||
118 | */ |
||
119 | 102 | public function getIncludes() |
|
123 | |||
124 | /** |
||
125 | * Set the first install flag. |
||
126 | * |
||
127 | * @param bool $flag |
||
128 | * |
||
129 | * @return self |
||
130 | */ |
||
131 | 6 | public function setFirstInstall($flag) |
|
137 | |||
138 | /** |
||
139 | * Is this the first time that the plugin has been installed ? |
||
140 | * |
||
141 | * @return bool |
||
142 | */ |
||
143 | 108 | public function isFirstInstall() |
|
147 | |||
148 | /** |
||
149 | * Set the locked flag. |
||
150 | * |
||
151 | * @param bool $flag |
||
152 | * |
||
153 | * @return self |
||
154 | */ |
||
155 | 9 | public function setLocked($flag) |
|
161 | |||
162 | /** |
||
163 | * Was a lockfile present when the plugin was installed ? |
||
164 | * |
||
165 | * @return bool |
||
166 | */ |
||
167 | 12 | public function isLocked() |
|
171 | |||
172 | /** |
||
173 | * Should an update be forced ? |
||
174 | * |
||
175 | * @return bool |
||
176 | */ |
||
177 | 3 | public function forceUpdate() |
|
181 | |||
182 | /** |
||
183 | * Set the devMode flag. |
||
184 | * |
||
185 | * @param bool $flag |
||
186 | * |
||
187 | * @return self |
||
188 | */ |
||
189 | 102 | public function setDevMode($flag) |
|
195 | |||
196 | /** |
||
197 | * Should devMode settings be processed ? |
||
198 | * |
||
199 | * @return bool |
||
200 | */ |
||
201 | 99 | public function isDevMode() |
|
205 | |||
206 | /** |
||
207 | * Should devMode settings be merged? |
||
208 | * |
||
209 | * @return bool |
||
210 | */ |
||
211 | 99 | public function shouldMergeDev() |
|
215 | |||
216 | /** |
||
217 | * Set the dumpAutoloader flag. |
||
218 | * |
||
219 | * @param bool $flag |
||
220 | * |
||
221 | * @return self |
||
222 | */ |
||
223 | 102 | public function setDumpAutoloader($flag) |
|
229 | |||
230 | /** |
||
231 | * Is the autoloader file supposed to be written out ? |
||
232 | * |
||
233 | * @return bool |
||
234 | */ |
||
235 | 3 | public function shouldDumpAutoloader() |
|
239 | |||
240 | /** |
||
241 | * Set the optimizeAutoloader flag. |
||
242 | * |
||
243 | * @param bool $flag |
||
244 | * |
||
245 | * @return self |
||
246 | */ |
||
247 | 102 | public function setOptimizeAutoloader($flag) |
|
253 | |||
254 | /** |
||
255 | * Should the autoloader be optimized ? |
||
256 | * |
||
257 | * @return bool |
||
258 | */ |
||
259 | 3 | public function shouldOptimizeAutoloader() |
|
263 | |||
264 | /** |
||
265 | * Add duplicate packages. |
||
266 | * |
||
267 | * @param string $type |
||
268 | * @param array $packages |
||
269 | * |
||
270 | * @return self |
||
271 | */ |
||
272 | 54 | public function addDuplicateLinks($type, array $packages) |
|
285 | |||
286 | /** |
||
287 | * Should includes be recursively processed ? |
||
288 | * |
||
289 | * @return bool |
||
290 | */ |
||
291 | 99 | public function recurseIncludes() |
|
295 | |||
296 | /** |
||
297 | * Get list of filenames and/or glob patterns to require |
||
298 | * |
||
299 | * @return array |
||
300 | */ |
||
301 | 102 | public function getRequires() |
|
305 | |||
306 | /** |
||
307 | * Get duplicate packages. |
||
308 | * |
||
309 | * @param string $type |
||
310 | * |
||
311 | * @return array |
||
312 | */ |
||
313 | 99 | public function getDuplicateLinks($type) |
|
317 | |||
318 | /** |
||
319 | * Should duplicate links be replaced in a 'last definition wins' order ? |
||
320 | * |
||
321 | * @return bool |
||
322 | */ |
||
323 | 51 | public function replaceDuplicateLinks() |
|
327 | |||
328 | /** |
||
329 | * Should duplicate links be ignored? |
||
330 | * |
||
331 | * @return bool |
||
332 | */ |
||
333 | 54 | public function ignoreDuplicateLinks() |
|
337 | |||
338 | /** |
||
339 | * Should the extra section be merged ? |
||
340 | * |
||
341 | * By default, the extra section is not merged and there will be many cases where |
||
342 | * the merge of the extra section is performed too late to be of use to other plugins. |
||
343 | * When enabled, merging uses one of two strategies - either 'first wins' or 'last wins'. |
||
344 | * When enabled, 'first wins' is the default behaviour. If Replace mode is activated |
||
345 | * then 'last wins' is used. |
||
346 | * |
||
347 | * @return bool |
||
348 | */ |
||
349 | 99 | public function shouldMergeExtra() |
|
353 | |||
354 | /** |
||
355 | * Should the extra section be merged deep / recursively? |
||
356 | * |
||
357 | * @return bool |
||
358 | */ |
||
359 | 18 | public function shouldMergeExtraDeep() |
|
363 | |||
364 | /** |
||
365 | * Should the scripts section be merged? |
||
366 | * |
||
367 | * @return bool |
||
368 | */ |
||
369 | 99 | public function shouldMergeScripts() |
|
373 | |||
374 | /* ------------------------------------------------------------------------------------------------ |
||
375 | | Main Functions |
||
376 | | ------------------------------------------------------------------------------------------------ |
||
377 | */ |
||
378 | /** |
||
379 | * Load plugin settings. |
||
380 | */ |
||
381 | 102 | public function loadSettings() |
|
395 | |||
396 | /* ------------------------------------------------------------------------------------------------ |
||
397 | | Other Functions |
||
398 | | ------------------------------------------------------------------------------------------------ |
||
399 | */ |
||
400 | /** |
||
401 | * Merge config. |
||
402 | * |
||
403 | * @param array $extra |
||
404 | * |
||
405 | * @return array |
||
406 | */ |
||
407 | 102 | private function mergeConfig(array $extra) |
|
425 | } |
||
426 |