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 | 117 | 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 | 96 | public function getIncludes() |
|
120 | |||
121 | /** |
||
122 | * Set the first install flag. |
||
123 | * |
||
124 | * @param bool $flag |
||
125 | * |
||
126 | * @return self |
||
127 | */ |
||
128 | 6 | public function setFirstInstall($flag) |
|
134 | |||
135 | /** |
||
136 | * Is this the first time that the plugin has been installed ? |
||
137 | * |
||
138 | * @return bool |
||
139 | */ |
||
140 | 102 | public function isFirstInstall() |
|
144 | |||
145 | /** |
||
146 | * Set the locked flag. |
||
147 | * |
||
148 | * @param bool $flag |
||
149 | * |
||
150 | * @return self |
||
151 | */ |
||
152 | 9 | public function setLocked($flag) |
|
158 | |||
159 | /** |
||
160 | * Was a lockfile present when the plugin was installed ? |
||
161 | * |
||
162 | * @return bool |
||
163 | */ |
||
164 | 12 | public function isLocked() |
|
168 | |||
169 | /** |
||
170 | * Should an update be forced ? |
||
171 | * |
||
172 | * @return bool |
||
173 | */ |
||
174 | 3 | public function forceUpdate() |
|
178 | |||
179 | /** |
||
180 | * Set the devMode flag. |
||
181 | * |
||
182 | * @param bool $flag |
||
183 | * |
||
184 | * @return self |
||
185 | */ |
||
186 | 96 | public function setDevMode($flag) |
|
192 | |||
193 | /** |
||
194 | * Should devMode settings be processed ? |
||
195 | * |
||
196 | * @return bool |
||
197 | */ |
||
198 | 93 | public function isDevMode() |
|
202 | |||
203 | /** |
||
204 | * Should devMode settings be merged? |
||
205 | * |
||
206 | * @return bool |
||
207 | */ |
||
208 | 93 | public function shouldMergeDev() |
|
209 | { |
||
210 | 93 | return $this->mergeDev; |
|
211 | } |
||
212 | |||
213 | /** |
||
214 | * Set the dumpAutoloader flag. |
||
215 | * |
||
216 | * @param bool $flag |
||
217 | * |
||
218 | * @return self |
||
219 | */ |
||
220 | 96 | public function setDumpAutoloader($flag) |
|
221 | { |
||
222 | 96 | $this->dumpAutoloader = (bool) $flag; |
|
223 | |||
224 | 96 | return $this; |
|
225 | } |
||
226 | |||
227 | /** |
||
228 | * Is the autoloader file supposed to be written out ? |
||
229 | * |
||
230 | * @return bool |
||
231 | */ |
||
232 | 3 | public function shouldDumpAutoloader() |
|
233 | { |
||
234 | 3 | return $this->dumpAutoloader; |
|
235 | } |
||
236 | |||
237 | /** |
||
238 | * Set the optimizeAutoloader flag. |
||
239 | * |
||
240 | * @param bool $flag |
||
241 | * |
||
242 | * @return self |
||
243 | */ |
||
244 | 96 | public function setOptimizeAutoloader($flag) |
|
245 | { |
||
246 | 96 | $this->optimizeAutoloader = (bool) $flag; |
|
247 | |||
248 | 96 | return $this; |
|
249 | } |
||
250 | |||
251 | /** |
||
252 | * Should the autoloader be optimized ? |
||
253 | * |
||
254 | * @return bool |
||
255 | */ |
||
256 | 3 | public function shouldOptimizeAutoloader() |
|
260 | |||
261 | /** |
||
262 | * Add duplicate packages. |
||
263 | * |
||
264 | * @param string $type |
||
265 | * @param array $packages |
||
266 | * |
||
267 | * @return self |
||
268 | */ |
||
269 | 48 | public function addDuplicateLinks($type, array $packages) |
|
282 | |||
283 | /** |
||
284 | * Should includes be recursively processed ? |
||
285 | * |
||
286 | * @return bool |
||
287 | */ |
||
288 | 93 | public function recurseIncludes() |
|
292 | |||
293 | /** |
||
294 | * Get list of filenames and/or glob patterns to require |
||
295 | * |
||
296 | * @return array |
||
297 | */ |
||
298 | 96 | public function getRequires() |
|
302 | |||
303 | /** |
||
304 | * Get duplicate packages. |
||
305 | * |
||
306 | * @param string $type |
||
307 | * |
||
308 | * @return array |
||
309 | */ |
||
310 | 93 | public function getDuplicateLinks($type) |
|
316 | |||
317 | /** |
||
318 | * Should duplicate links be replaced in a 'last definition wins' order ? |
||
319 | * |
||
320 | * @return bool |
||
321 | */ |
||
322 | 78 | public function replaceDuplicateLinks() |
|
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 | 93 | public function shouldMergeExtra() |
|
342 | |||
343 | /** |
||
344 | * Should the extra section be merged deep / recursively? |
||
345 | * |
||
346 | * @return bool |
||
347 | */ |
||
348 | 18 | public function shouldMergeExtraDeep() |
|
352 | |||
353 | /** |
||
354 | * Should the scripts section be merged? |
||
355 | * |
||
356 | * @return bool |
||
357 | */ |
||
358 | 93 | public function shouldMergeScripts() |
|
362 | |||
363 | /* ------------------------------------------------------------------------------------------------ |
||
364 | | Main Functions |
||
365 | | ------------------------------------------------------------------------------------------------ |
||
366 | */ |
||
367 | /** |
||
368 | * Load plugin settings. |
||
369 | */ |
||
370 | 96 | public function loadSettings() |
|
384 | |||
385 | /* ------------------------------------------------------------------------------------------------ |
||
386 | | Other Functions |
||
387 | | ------------------------------------------------------------------------------------------------ |
||
388 | */ |
||
389 | /** |
||
390 | * Merge config. |
||
391 | * |
||
392 | * @param array $extra |
||
393 | * |
||
394 | * @return array |
||
395 | */ |
||
396 | 96 | private function mergeConfig(array $extra) |
|
413 | } |
||
414 |