1 | <?php namespace Arcanedev\Composer\Entities; |
||
11 | class PluginState |
||
12 | { |
||
13 | /* ----------------------------------------------------------------- |
||
14 | | Properties |
||
15 | | ----------------------------------------------------------------- |
||
16 | */ |
||
17 | |||
18 | /** @var \Composer\Composer */ |
||
19 | protected $composer; |
||
20 | |||
21 | /** @var array */ |
||
22 | protected $includes = []; |
||
23 | |||
24 | /** @var array */ |
||
25 | protected $requires = []; |
||
26 | |||
27 | /** @var array */ |
||
28 | protected $duplicateLinks = []; |
||
29 | |||
30 | /** @var bool */ |
||
31 | protected $devMode = false; |
||
32 | |||
33 | /** @var bool */ |
||
34 | protected $recurse = true; |
||
35 | |||
36 | /** @var bool */ |
||
37 | protected $replace = false; |
||
38 | |||
39 | /** @var bool $ignore */ |
||
40 | protected $ignore = false; |
||
41 | |||
42 | /** |
||
43 | * Whether to merge the -dev sections. |
||
44 | * |
||
45 | * @var bool |
||
46 | */ |
||
47 | protected $mergeDev = true; |
||
48 | |||
49 | /** |
||
50 | * Whether to merge the extra section. |
||
51 | * |
||
52 | * By default, the extra section is not merged and there will be many cases where |
||
53 | * the merge of the extra section is performed too late to be of use to other plugins. |
||
54 | * When enabled, merging uses one of two strategies - either 'first wins' or 'last wins'. |
||
55 | * When enabled, 'first wins' is the default behaviour. If Replace mode is activated |
||
56 | * then 'last wins' is used. |
||
57 | * |
||
58 | * @var bool |
||
59 | */ |
||
60 | protected $mergeExtra = false; |
||
61 | |||
62 | /** |
||
63 | * Whether to merge the scripts section. |
||
64 | * |
||
65 | * @var bool $mergeScripts |
||
66 | */ |
||
67 | protected $mergeScripts = false; |
||
68 | |||
69 | /** |
||
70 | * Whether to merge the extra section in a deep / recursive way. |
||
71 | * |
||
72 | * By default the extra section is merged with array_merge() and duplicate keys are ignored. |
||
73 | * When enabled this allows to merge the arrays recursively using the following rule: |
||
74 | * Integer keys are merged, while array values are replaced where the later values overwrite the former. |
||
75 | * |
||
76 | * This is useful especially for the extra section when plugins use larger structures like a 'patches' key with |
||
77 | * the packages as sub-keys and the patches as values. |
||
78 | * |
||
79 | * When 'replace' mode is activated the order of array merges is exchanged. |
||
80 | * |
||
81 | * @var bool |
||
82 | */ |
||
83 | protected $mergeExtraDeep = false; |
||
84 | |||
85 | /** @var bool */ |
||
86 | protected $firstInstall = false; |
||
87 | |||
88 | /** @var bool */ |
||
89 | protected $locked = false; |
||
90 | |||
91 | /** @var bool */ |
||
92 | protected $dumpAutoloader = false; |
||
93 | |||
94 | /** @var bool */ |
||
95 | protected $optimizeAutoloader = false; |
||
96 | |||
97 | /* ----------------------------------------------------------------- |
||
98 | | Constructor |
||
99 | | ----------------------------------------------------------------- |
||
100 | */ |
||
101 | |||
102 | /** |
||
103 | * Make PluginState instance. |
||
104 | * |
||
105 | * @param \Composer\Composer $composer |
||
106 | */ |
||
107 | 123 | public function __construct(Composer $composer) |
|
111 | |||
112 | /* ----------------------------------------------------------------- |
||
113 | | Getters & Setters |
||
114 | | ----------------------------------------------------------------- |
||
115 | */ |
||
116 | |||
117 | /** |
||
118 | * Get list of filenames and/or glob patterns to include. |
||
119 | * |
||
120 | * @return array |
||
121 | */ |
||
122 | 102 | public function getIncludes() |
|
126 | |||
127 | /** |
||
128 | * Set the first install flag. |
||
129 | * |
||
130 | * @param bool $flag |
||
131 | * |
||
132 | * @return self |
||
133 | */ |
||
134 | 6 | public function setFirstInstall($flag) |
|
140 | |||
141 | /** |
||
142 | * Is this the first time that the plugin has been installed ? |
||
143 | * |
||
144 | * @return bool |
||
145 | */ |
||
146 | 108 | public function isFirstInstall() |
|
150 | |||
151 | /** |
||
152 | * Set the locked flag. |
||
153 | * |
||
154 | * @param bool $flag |
||
155 | * |
||
156 | * @return self |
||
157 | */ |
||
158 | 9 | public function setLocked($flag) |
|
164 | |||
165 | /** |
||
166 | * Was a lockfile present when the plugin was installed ? |
||
167 | * |
||
168 | * @return bool |
||
169 | */ |
||
170 | 12 | public function isLocked() |
|
174 | |||
175 | /** |
||
176 | * Should an update be forced ? |
||
177 | * |
||
178 | * @return bool |
||
179 | */ |
||
180 | 3 | public function forceUpdate() |
|
184 | |||
185 | /** |
||
186 | * Set the devMode flag. |
||
187 | * |
||
188 | * @param bool $flag |
||
189 | * |
||
190 | * @return self |
||
191 | */ |
||
192 | 102 | public function setDevMode($flag) |
|
198 | |||
199 | /** |
||
200 | * Should devMode settings be processed ? |
||
201 | * |
||
202 | * @return bool |
||
203 | */ |
||
204 | 99 | public function isDevMode() |
|
208 | |||
209 | /** |
||
210 | * Should devMode settings be merged? |
||
211 | * |
||
212 | * @return bool |
||
213 | */ |
||
214 | 99 | public function shouldMergeDev() |
|
218 | |||
219 | /** |
||
220 | * Set the dumpAutoloader flag. |
||
221 | * |
||
222 | * @param bool $flag |
||
223 | * |
||
224 | * @return self |
||
225 | */ |
||
226 | 102 | public function setDumpAutoloader($flag) |
|
232 | |||
233 | /** |
||
234 | * Is the autoloader file supposed to be written out ? |
||
235 | * |
||
236 | * @return bool |
||
237 | */ |
||
238 | 3 | public function shouldDumpAutoloader() |
|
242 | |||
243 | /** |
||
244 | * Set the optimizeAutoloader flag. |
||
245 | * |
||
246 | * @param bool $flag |
||
247 | * |
||
248 | * @return self |
||
249 | */ |
||
250 | 102 | public function setOptimizeAutoloader($flag) |
|
256 | |||
257 | /** |
||
258 | * Should the autoloader be optimized ? |
||
259 | * |
||
260 | * @return bool |
||
261 | */ |
||
262 | 3 | public function shouldOptimizeAutoloader() |
|
266 | |||
267 | /** |
||
268 | * Add duplicate packages. |
||
269 | * |
||
270 | * @param string $type |
||
271 | * @param array $packages |
||
272 | * |
||
273 | * @return self |
||
274 | */ |
||
275 | 54 | public function addDuplicateLinks($type, array $packages) |
|
288 | |||
289 | /** |
||
290 | * Should includes be recursively processed ? |
||
291 | * |
||
292 | * @return bool |
||
293 | */ |
||
294 | 99 | public function recurseIncludes() |
|
298 | |||
299 | /** |
||
300 | * Get list of filenames and/or glob patterns to require |
||
301 | * |
||
302 | * @return array |
||
303 | */ |
||
304 | 102 | public function getRequires() |
|
308 | |||
309 | /** |
||
310 | * Get duplicate packages. |
||
311 | * |
||
312 | * @param string $type |
||
313 | * |
||
314 | * @return array |
||
315 | */ |
||
316 | 99 | public function getDuplicateLinks($type) |
|
320 | |||
321 | /** |
||
322 | * Should duplicate links be replaced in a 'last definition wins' order ? |
||
323 | * |
||
324 | * @return bool |
||
325 | */ |
||
326 | 51 | public function replaceDuplicateLinks() |
|
330 | |||
331 | /** |
||
332 | * Should duplicate links be ignored? |
||
333 | * |
||
334 | * @return bool |
||
335 | */ |
||
336 | 54 | public function ignoreDuplicateLinks() |
|
340 | |||
341 | /** |
||
342 | * Should the extra section be merged ? |
||
343 | * |
||
344 | * By default, the extra section is not merged and there will be many cases where |
||
345 | * the merge of the extra section is performed too late to be of use to other plugins. |
||
346 | * When enabled, merging uses one of two strategies - either 'first wins' or 'last wins'. |
||
347 | * When enabled, 'first wins' is the default behaviour. If Replace mode is activated |
||
348 | * then 'last wins' is used. |
||
349 | * |
||
350 | * @return bool |
||
351 | */ |
||
352 | 99 | public function shouldMergeExtra() |
|
356 | |||
357 | /** |
||
358 | * Should the extra section be merged deep / recursively? |
||
359 | * |
||
360 | * @return bool |
||
361 | */ |
||
362 | 18 | public function shouldMergeExtraDeep() |
|
366 | |||
367 | /** |
||
368 | * Should the scripts section be merged? |
||
369 | * |
||
370 | * @return bool |
||
371 | */ |
||
372 | 99 | public function shouldMergeScripts() |
|
376 | |||
377 | /* ------------------------------------------------------------------------------------------------ |
||
378 | | Main Functions |
||
379 | | ------------------------------------------------------------------------------------------------ |
||
380 | */ |
||
381 | /** |
||
382 | * Load plugin settings. |
||
383 | */ |
||
384 | 102 | public function loadSettings() |
|
398 | |||
399 | /* ----------------------------------------------------------------- |
||
400 | | Other Methods |
||
401 | | ----------------------------------------------------------------- |
||
402 | */ |
||
403 | |||
404 | /** |
||
405 | * Merge config. |
||
406 | * |
||
407 | * @param array $extra |
||
408 | * |
||
409 | * @return array |
||
410 | */ |
||
411 | 102 | private static function mergeConfig(array $extra) |
|
426 | } |
||
427 |
Let’s assume you have a class which uses late-static binding:
}
The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the
getSomeVariable()
on that sub-class, you will receive a runtime error:In the case above, it makes sense to update
SomeClass
to useself
instead: