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 | * Set the dumpAutoloader flag. |
||
198 | 135 | * |
|
199 | * @param bool $flag |
||
200 | 135 | * |
|
201 | * @return self |
||
202 | */ |
||
203 | public function setDumpAutoloader($flag) |
||
209 | |||
210 | 140 | /** |
|
211 | * Is the autoloader file supposed to be written out ? |
||
212 | 140 | * |
|
213 | * @return bool |
||
214 | 140 | */ |
|
215 | public function shouldDumpAutoloader() |
||
219 | |||
220 | /** |
||
221 | * Set the optimizeAutoloader flag. |
||
222 | 5 | * |
|
223 | * @param bool $flag |
||
224 | 5 | * |
|
225 | * @return self |
||
226 | */ |
||
227 | public function setOptimizeAutoloader($flag) |
||
233 | |||
234 | 140 | /** |
|
235 | * Should the autoloader be optimized ? |
||
236 | 140 | * |
|
237 | * @return bool |
||
238 | 140 | */ |
|
239 | public function shouldOptimizeAutoloader() |
||
243 | |||
244 | /** |
||
245 | * Add duplicate packages. |
||
246 | 5 | * |
|
247 | * @param string $type |
||
248 | 5 | * @param array $packages |
|
249 | * |
||
250 | * @return self |
||
251 | */ |
||
252 | public function addDuplicateLinks($type, array $packages) |
||
265 | |||
266 | /** |
||
267 | * Should includes be recursively processed ? |
||
268 | * |
||
269 | 80 | * @return bool |
|
270 | */ |
||
271 | 80 | public function recurseIncludes() |
|
275 | 80 | ||
276 | 80 | /** |
|
277 | * Get list of filenames and/or glob patterns to require |
||
278 | 64 | * |
|
279 | * @return array |
||
280 | 80 | */ |
|
281 | public function getRequires() |
||
285 | |||
286 | /** |
||
287 | * Get duplicate packages. |
||
288 | 135 | * |
|
289 | * @param string $type |
||
290 | 135 | * |
|
291 | * @return array |
||
292 | */ |
||
293 | public function getDuplicateLinks($type) |
||
299 | |||
300 | 140 | /** |
|
301 | * Should duplicate links be replaced in a 'last definition wins' order ? |
||
302 | * |
||
303 | * @return bool |
||
304 | */ |
||
305 | public function replaceDuplicateLinks() |
||
309 | |||
310 | 135 | /** |
|
311 | * Should the extra section be merged ? |
||
312 | 135 | * |
|
313 | 124 | * By default, the extra section is not merged and there will be many cases where |
|
314 | 135 | * the merge of the extra section is performed too late to be of use to other plugins. |
|
315 | * When enabled, merging uses one of two strategies - either 'first wins' or 'last wins'. |
||
316 | * When enabled, 'first wins' is the default behaviour. If Replace mode is activated |
||
317 | * then 'last wins' is used. |
||
318 | * |
||
319 | * @return bool |
||
320 | */ |
||
321 | public function shouldMergeExtra() |
||
325 | |||
326 | /** |
||
327 | * Should the extra section be merged deep / recursively? |
||
328 | * |
||
329 | * @return bool |
||
330 | */ |
||
331 | public function shouldMergeExtraDeep() |
||
335 | |||
336 | /* ------------------------------------------------------------------------------------------------ |
||
337 | | Main Functions |
||
338 | 135 | | ------------------------------------------------------------------------------------------------ |
|
339 | */ |
||
340 | 135 | /** |
|
341 | * Load plugin settings. |
||
342 | */ |
||
343 | public function loadSettings() |
||
356 | |||
357 | /* ------------------------------------------------------------------------------------------------ |
||
358 | | Other Functions |
||
359 | | ------------------------------------------------------------------------------------------------ |
||
360 | 140 | */ |
|
361 | /** |
||
362 | 140 | * Merge config. |
|
363 | 140 | * |
|
364 | 140 | * @param array $extra |
|
365 | 140 | * |
|
366 | 140 | * @return array |
|
367 | 140 | */ |
|
368 | 140 | private function mergeConfig(array $extra) |
|
384 | } |
||
385 |