1
1
<?php
2
2
/**
3
- * Copyright © Magento, Inc. All rights reserved.
4
- * See COPYING.txt for license details .
3
+ * Copyright 2020 Adobe
4
+ * All Rights Reserved .
5
5
*/
6
6
declare (strict_types=1 );
7
7
8
8
namespace Magento \Framework \Interception ;
9
9
10
10
use Magento \Framework \App \Filesystem \DirectoryList ;
11
+ use Magento \Framework \App \ObjectManager ;
12
+ use Magento \Framework \App \State ;
11
13
use Magento \Framework \Config \ReaderInterface ;
12
14
use Magento \Framework \Config \ScopeInterface ;
15
+ use Magento \Framework \Exception \FileSystemException ;
13
16
use Magento \Framework \Interception \ObjectManager \ConfigInterface ;
14
17
use Magento \Framework \ObjectManager \DefinitionInterface as ClassDefinitions ;
15
18
use Magento \Framework \ObjectManager \RelationsInterface ;
20
23
*/
21
24
class PluginListGenerator implements ConfigWriterInterface, ConfigLoaderInterface
22
25
{
23
- /**
24
- * @var ScopeInterface
25
- */
26
- private $ scopeConfig ;
27
-
28
- /**
29
- * Configuration reader
30
- *
31
- * @var ReaderInterface
32
- */
33
- private $ reader ;
34
-
35
26
/**
36
27
* Cache tag
37
28
*
38
29
* @var string
39
30
*/
40
- private $ cacheId = 'plugin-list ' ;
41
-
42
- /**
43
- * @var array
44
- */
45
- private $ loadedScopes = [];
46
-
47
- /**
48
- * Type config
49
- *
50
- * @var ConfigInterface
51
- */
52
- private $ omConfig ;
53
-
54
- /**
55
- * Class relations information provider
56
- *
57
- * @var RelationsInterface
58
- */
59
- private $ relations ;
60
-
61
- /**
62
- * List of interception methods per plugin
63
- *
64
- * @var DefinitionInterface
65
- */
66
- private $ definitions ;
67
-
68
- /**
69
- * List of interceptable application classes
70
- *
71
- * @var ClassDefinitions
72
- */
73
- private $ classDefinitions ;
31
+ private string $ cacheId = 'plugin-list ' ;
74
32
75
33
/**
76
- * @var LoggerInterface
77
- */
78
- private $ logger ;
79
-
80
- /**
81
- * @var DirectoryList
34
+ * @var string[]
82
35
*/
83
- private $ directoryList ;
36
+ private array $ loadedScopes = [] ;
84
37
85
38
/**
86
39
* @var array
87
40
*/
88
- private $ pluginData ;
41
+ private array $ pluginData = [] ;
89
42
90
43
/**
91
44
* @var array
92
45
*/
93
- private $ inherited = [];
46
+ private array $ inherited = [];
94
47
95
48
/**
96
49
* @var array
97
50
*/
98
- private $ processed ;
99
-
100
- /**
101
- * Scope priority loading scheme
102
- *
103
- * @var string[]
104
- */
105
- private $ scopePriorityScheme ;
51
+ private array $ processed = [];
106
52
107
53
/**
108
54
* @var array
109
55
*/
110
- private $ globalScopePluginData = [];
56
+ private array $ globalScopePluginData = [];
111
57
112
58
/**
113
59
* @param ReaderInterface $reader
@@ -118,28 +64,22 @@ class PluginListGenerator implements ConfigWriterInterface, ConfigLoaderInterfac
118
64
* @param ClassDefinitions $classDefinitions
119
65
* @param LoggerInterface $logger
120
66
* @param DirectoryList $directoryList
121
- * @param array $scopePriorityScheme
67
+ * @param array $scopePriorityScheme [optional]
68
+ * @param string $appMode [optional]
69
+ * @SuppressWarnings(PHPMD.ExcessiveParameterList)
122
70
*/
123
71
public function __construct (
124
- ReaderInterface $ reader ,
125
- ScopeInterface $ scopeConfig ,
126
- ConfigInterface $ omConfig ,
127
- RelationsInterface $ relations ,
128
- DefinitionInterface $ definitions ,
129
- ClassDefinitions $ classDefinitions ,
130
- LoggerInterface $ logger ,
131
- DirectoryList $ directoryList ,
132
- array $ scopePriorityScheme = ['global ' ]
72
+ private ReaderInterface $ reader ,
73
+ private ScopeInterface $ scopeConfig ,
74
+ private ConfigInterface $ omConfig ,
75
+ private RelationsInterface $ relations ,
76
+ private DefinitionInterface $ definitions ,
77
+ private ClassDefinitions $ classDefinitions ,
78
+ private LoggerInterface $ logger ,
79
+ private DirectoryList $ directoryList ,
80
+ private array $ scopePriorityScheme = ['global ' ],
81
+ private string $ appMode = State::MODE_DEFAULT
133
82
) {
134
- $ this ->reader = $ reader ;
135
- $ this ->scopeConfig = $ scopeConfig ;
136
- $ this ->omConfig = $ omConfig ;
137
- $ this ->relations = $ relations ;
138
- $ this ->definitions = $ definitions ;
139
- $ this ->classDefinitions = $ classDefinitions ;
140
- $ this ->logger = $ logger ;
141
- $ this ->directoryList = $ directoryList ;
142
- $ this ->scopePriorityScheme = $ scopePriorityScheme ;
143
83
}
144
84
145
85
/**
@@ -245,22 +185,21 @@ public function loadScopedVirtualTypes($scopePriorityScheme, $loadedScopes, $plu
245
185
246
186
/**
247
187
* Returns class definitions
248
- *
249
- * @return array
250
188
*/
251
- private function getClassDefinitions ()
189
+ private function getClassDefinitions (): array
252
190
{
253
191
return $ this ->classDefinitions ->getClasses ();
254
192
}
255
193
256
194
/**
257
195
* Whether scope code is current scope code
258
196
*
259
- * @param string $scopeCode
197
+ * @param string|null $scopeCode
260
198
* @return bool
261
199
*/
262
- private function isCurrentScope ($ scopeCode )
200
+ private function isCurrentScope (? string $ scopeCode ): bool
263
201
{
202
+ // ToDo: $scopeCode can be null in integration tests because of how scope is reset.
264
203
return $ this ->scopeConfig ->getCurrentScope () === $ scopeCode ;
265
204
}
266
205
@@ -366,9 +305,12 @@ public function trimInstanceStartingBackslash(&$plugins)
366
305
public function filterPlugins (array &$ plugins )
367
306
{
368
307
foreach ($ plugins as $ name => $ plugin ) {
369
- if (empty ($ plugin ['instance ' ])) {
308
+ if (! isset ($ plugin ['instance ' ])) {
370
309
unset($ plugins [$ name ]);
371
- $ this ->logger ->info ("Reference to undeclared plugin with name ' {$ name }'. " );
310
+ // Log the undeclared plugin when it is not disabled or when the app is in Developer mode.
311
+ if ($ this ->appMode === State::MODE_DEVELOPER || !($ plugin ['disabled ' ] ?? false )) {
312
+ $ this ->logger ->debug ("Reference to undeclared plugin with name ' {$ name }'. " );
313
+ }
372
314
}
373
315
}
374
316
}
@@ -401,26 +343,23 @@ public function merge(array $config, $pluginData)
401
343
*
402
344
* @param string $key
403
345
* @param array $config
404
- * @return void
405
- * @throws \Magento\Framework\Exception\FileSystemException
346
+ * @throws FileSystemException
406
347
*/
407
- private function writeConfig (string $ key , array $ config )
348
+ private function writeConfig (string $ key , array $ config ): void
408
349
{
409
350
$ this ->initialize ();
410
- $ configuration = sprintf ('<?php return %s; ' , var_export ($ config , true ));
411
351
file_put_contents (
412
352
$ this ->directoryList ->getPath (DirectoryList::GENERATED_METADATA ) . '/ ' . $ key . '.php ' ,
413
- $ configuration
353
+ sprintf ( ' <?php return %s; ' , var_export ( $ config , true ))
414
354
);
415
355
}
416
356
417
357
/**
418
358
* Initializes writer
419
359
*
420
- * @return void
421
- * @throws \Magento\Framework\Exception\FileSystemException
360
+ * @throws FileSystemException
422
361
*/
423
- private function initialize ()
362
+ private function initialize (): void
424
363
{
425
364
if (!file_exists ($ this ->directoryList ->getPath (DirectoryList::GENERATED_METADATA ))) {
426
365
mkdir ($ this ->directoryList ->getPath (DirectoryList::GENERATED_METADATA ));
0 commit comments