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 extra section in a deep / recursive way. |
||
60 | * |
||
61 | * By default the extra section is merged with array_merge() and duplicate keys are ignored. |
||
62 | * When enabled this allows to merge the arrays recursively using the following rule: |
||
63 | * Integer keys are merged, while array values are replaced where the later values overwrite the former. |
||
64 | * |
||
65 | * This is useful especially for the extra section when plugins use larger structures like a 'patches' key with |
||
66 | * the packages as sub-keys and the patches as values. |
||
67 | * |
||
68 | * When 'replace' mode is activated the order of array merges is exchanged. |
||
69 | * |
||
70 | * @var bool |
||
71 | */ |
||
72 | protected $mergeExtraDeep = false; |
||
73 | |||
74 | /** @var bool */ |
||
75 | protected $firstInstall = false; |
||
76 | |||
77 | /** @var bool */ |
||
78 | protected $locked = false; |
||
79 | |||
80 | /** @var bool */ |
||
81 | protected $dumpAutoloader = false; |
||
82 | |||
83 | /** @var bool */ |
||
84 | protected $optimizeAutoloader = false; |
||
85 | |||
86 | /* ------------------------------------------------------------------------------------------------ |
||
87 | | Constructor |
||
88 | | ------------------------------------------------------------------------------------------------ |
||
89 | */ |
||
90 | /** |
||
91 | * Make PluginState instance. |
||
92 | * |
||
93 | * @param \Composer\Composer $composer |
||
94 | */ |
||
95 | public function __construct(Composer $composer) |
||
99 | |||
100 | /* ------------------------------------------------------------------------------------------------ |
||
101 | | Getters & Setters |
||
102 | 175 | | ------------------------------------------------------------------------------------------------ |
|
103 | */ |
||
104 | 175 | /** |
|
105 | 175 | * Get list of filenames and/or glob patterns to include. |
|
106 | * |
||
107 | * @return array |
||
108 | */ |
||
109 | public function getIncludes() |
||
113 | |||
114 | /** |
||
115 | * Set the first install flag. |
||
116 | 140 | * |
|
117 | * @param bool $flag |
||
118 | 140 | * |
|
119 | * @return self |
||
120 | */ |
||
121 | public function setFirstInstall($flag) |
||
127 | |||
128 | 10 | /** |
|
129 | * Is this the first time that the plugin has been installed ? |
||
130 | 10 | * |
|
131 | * @return bool |
||
132 | 10 | */ |
|
133 | public function isFirstInstall() |
||
137 | |||
138 | /** |
||
139 | * Set the locked flag. |
||
140 | 150 | * |
|
141 | * @param bool $flag |
||
142 | 150 | * |
|
143 | * @return self |
||
144 | */ |
||
145 | public function setLocked($flag) |
||
151 | |||
152 | 15 | /** |
|
153 | * Was a lockfile present when the plugin was installed ? |
||
154 | 15 | * |
|
155 | * @return bool |
||
156 | 15 | */ |
|
157 | public function isLocked() |
||
161 | |||
162 | /** |
||
163 | * Should an update be forced ? |
||
164 | 20 | * |
|
165 | * @return bool |
||
166 | 20 | */ |
|
167 | public function forceUpdate() |
||
171 | |||
172 | /** |
||
173 | * Set the devMode flag. |
||
174 | 5 | * |
|
175 | * @param bool $flag |
||
176 | 5 | * |
|
177 | * @return self |
||
178 | */ |
||
179 | public function setDevMode($flag) |
||
185 | |||
186 | 140 | /** |
|
187 | * Should devMode settings be processed ? |
||
188 | 140 | * |
|
189 | * @return bool |
||
190 | 140 | */ |
|
191 | public function isDevMode() |
||
195 | |||
196 | /** |
||
197 | * Should devMode settings be merged? |
||
198 | 135 | * |
|
199 | * @return bool |
||
200 | 135 | */ |
|
201 | public function shouldMergeDev() |
||
205 | |||
206 | /** |
||
207 | * Set the dumpAutoloader flag. |
||
208 | * |
||
209 | * @param bool $flag |
||
210 | 140 | * |
|
211 | * @return self |
||
212 | 140 | */ |
|
213 | public function setDumpAutoloader($flag) |
||
219 | |||
220 | /** |
||
221 | * Is the autoloader file supposed to be written out ? |
||
222 | 5 | * |
|
223 | * @return bool |
||
224 | 5 | */ |
|
225 | public function shouldDumpAutoloader() |
||
229 | |||
230 | /** |
||
231 | * Set the optimizeAutoloader flag. |
||
232 | * |
||
233 | * @param bool $flag |
||
234 | 140 | * |
|
235 | * @return self |
||
236 | 140 | */ |
|
237 | public function setOptimizeAutoloader($flag) |
||
243 | |||
244 | /** |
||
245 | * Should the autoloader be optimized ? |
||
246 | 5 | * |
|
247 | * @return bool |
||
248 | 5 | */ |
|
249 | public function shouldOptimizeAutoloader() |
||
253 | |||
254 | /** |
||
255 | * Add duplicate packages. |
||
256 | 135 | * |
|
257 | * @param string $type |
||
258 | 135 | * @param array $packages |
|
259 | * |
||
260 | * @return self |
||
261 | */ |
||
262 | public function addDuplicateLinks($type, array $packages) |
||
275 | 80 | ||
276 | 80 | /** |
|
277 | * Should includes be recursively processed ? |
||
278 | 64 | * |
|
279 | * @return bool |
||
280 | 80 | */ |
|
281 | public function recurseIncludes() |
||
285 | |||
286 | /** |
||
287 | * Get list of filenames and/or glob patterns to require |
||
288 | 135 | * |
|
289 | * @return array |
||
290 | 135 | */ |
|
291 | public function getRequires() |
||
295 | |||
296 | /** |
||
297 | * Get duplicate packages. |
||
298 | 140 | * |
|
299 | * @param string $type |
||
300 | 140 | * |
|
301 | * @return array |
||
302 | */ |
||
303 | public function getDuplicateLinks($type) |
||
309 | |||
310 | 135 | /** |
|
311 | * Should duplicate links be replaced in a 'last definition wins' order ? |
||
312 | 135 | * |
|
313 | 124 | * @return bool |
|
314 | 135 | */ |
|
315 | public function replaceDuplicateLinks() |
||
319 | |||
320 | /** |
||
321 | * Should the extra section be merged ? |
||
322 | 110 | * |
|
323 | * By default, the extra section is not merged and there will be many cases where |
||
324 | 110 | * the merge of the extra section is performed too late to be of use to other plugins. |
|
325 | * When enabled, merging uses one of two strategies - either 'first wins' or 'last wins'. |
||
326 | * When enabled, 'first wins' is the default behaviour. If Replace mode is activated |
||
327 | * then 'last wins' is used. |
||
328 | * |
||
329 | * @return bool |
||
330 | */ |
||
331 | public function shouldMergeExtra() |
||
335 | |||
336 | /** |
||
337 | * Should the extra section be merged deep / recursively? |
||
338 | 135 | * |
|
339 | * @return bool |
||
340 | 135 | */ |
|
341 | public function shouldMergeExtraDeep() |
||
345 | |||
346 | /* ------------------------------------------------------------------------------------------------ |
||
347 | | Main Functions |
||
348 | 30 | | ------------------------------------------------------------------------------------------------ |
|
349 | */ |
||
350 | 30 | /** |
|
351 | * Load plugin settings. |
||
352 | */ |
||
353 | public function loadSettings() |
||
366 | 140 | ||
367 | 140 | /* ------------------------------------------------------------------------------------------------ |
|
368 | 140 | | Other Functions |
|
369 | 140 | | ------------------------------------------------------------------------------------------------ |
|
370 | 140 | */ |
|
371 | 140 | /** |
|
372 | * Merge config. |
||
373 | 140 | * |
|
374 | * @param array $extra |
||
375 | * |
||
376 | * @return array |
||
377 | */ |
||
378 | private function mergeConfig(array $extra) |
||
394 | } |
||
395 |