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 | * Whether to prepend repositories to repository manager. |
||
88 | * |
||
89 | * @var bool |
||
90 | */ |
||
91 | protected $prependRepositories = 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 | * Set the dumpAutoloader flag. |
||
205 | * |
||
206 | * @param bool $flag |
||
207 | * |
||
208 | * @return self |
||
209 | */ |
||
210 | 140 | public function setDumpAutoloader($flag) |
|
216 | |||
217 | /** |
||
218 | * Is the autoloader file supposed to be written out ? |
||
219 | * |
||
220 | * @return bool |
||
221 | */ |
||
222 | 5 | public function shouldDumpAutoloader() |
|
226 | |||
227 | /** |
||
228 | * Set the optimizeAutoloader flag. |
||
229 | * |
||
230 | * @param bool $flag |
||
231 | * |
||
232 | * @return self |
||
233 | */ |
||
234 | 140 | public function setOptimizeAutoloader($flag) |
|
240 | |||
241 | /** |
||
242 | * Should the autoloader be optimized ? |
||
243 | * |
||
244 | * @return bool |
||
245 | */ |
||
246 | 5 | public function shouldOptimizeAutoloader() |
|
250 | |||
251 | /** |
||
252 | * Should the merger prepend repositories to repository manager (instead of adding them to end of the list). |
||
253 | * |
||
254 | * @return bool |
||
255 | */ |
||
256 | 135 | public function shouldPrependRepositories() |
|
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) |
|
282 | |||
283 | /** |
||
284 | * Should includes be recursively processed ? |
||
285 | * |
||
286 | * @return bool |
||
287 | */ |
||
288 | 135 | public function recurseIncludes() |
|
292 | |||
293 | /** |
||
294 | * Get list of filenames and/or glob patterns to require |
||
295 | * |
||
296 | * @return array |
||
297 | */ |
||
298 | 140 | public function getRequires() |
|
302 | |||
303 | /** |
||
304 | * Get duplicate packages. |
||
305 | * |
||
306 | * @param string $type |
||
307 | * |
||
308 | * @return array |
||
309 | */ |
||
310 | 135 | public function getDuplicateLinks($type) |
|
316 | |||
317 | /** |
||
318 | * Should duplicate links be replaced in a 'last definition wins' order ? |
||
319 | * |
||
320 | * @return bool |
||
321 | */ |
||
322 | 110 | 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 | 135 | public function shouldMergeExtra() |
|
342 | |||
343 | /** |
||
344 | * Should the extra section be merged deep / recursively? |
||
345 | * |
||
346 | * @return bool |
||
347 | */ |
||
348 | 30 | public function shouldMergeExtraDeep() |
|
352 | |||
353 | /* ------------------------------------------------------------------------------------------------ |
||
354 | | Main Functions |
||
355 | | ------------------------------------------------------------------------------------------------ |
||
356 | */ |
||
357 | /** |
||
358 | * Load plugin settings. |
||
359 | */ |
||
360 | 140 | public function loadSettings() |
|
374 | |||
375 | /* ------------------------------------------------------------------------------------------------ |
||
376 | | Other Functions |
||
377 | | ------------------------------------------------------------------------------------------------ |
||
378 | */ |
||
379 | /** |
||
380 | * Merge config. |
||
381 | * |
||
382 | * @param array $extra |
||
383 | * |
||
384 | * @return array |
||
385 | */ |
||
386 | 140 | private function mergeConfig(array $extra) |
|
402 | } |
||
403 |