Skip to content

Commit aaf530f

Browse files
Merge remote-tracking branch '38554/patch-28' into comprs
2 parents 835e075 + 471b82e commit aaf530f

File tree

2 files changed

+40
-100
lines changed

2 files changed

+40
-100
lines changed

app/etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,7 @@
472472
<item name="primary" xsi:type="string">primary</item>
473473
<item name="first" xsi:type="string">global</item>
474474
</argument>
475+
<argument name="appMode" xsi:type="init_parameter">Magento\Framework\App\State::PARAM_MODE</argument>
475476
</arguments>
476477
</type>
477478
<type name="Magento\Framework\App\ResourceConnection">

lib/internal/Magento/Framework/Interception/PluginListGenerator.php

Lines changed: 39 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2020 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

88
namespace Magento\Framework\Interception;
99

1010
use Magento\Framework\App\Filesystem\DirectoryList;
11+
use Magento\Framework\App\ObjectManager;
12+
use Magento\Framework\App\State;
1113
use Magento\Framework\Config\ReaderInterface;
1214
use Magento\Framework\Config\ScopeInterface;
15+
use Magento\Framework\Exception\FileSystemException;
1316
use Magento\Framework\Interception\ObjectManager\ConfigInterface;
1417
use Magento\Framework\ObjectManager\DefinitionInterface as ClassDefinitions;
1518
use Magento\Framework\ObjectManager\RelationsInterface;
@@ -20,94 +23,37 @@
2023
*/
2124
class PluginListGenerator implements ConfigWriterInterface, ConfigLoaderInterface
2225
{
23-
/**
24-
* @var ScopeInterface
25-
*/
26-
private $scopeConfig;
27-
28-
/**
29-
* Configuration reader
30-
*
31-
* @var ReaderInterface
32-
*/
33-
private $reader;
34-
3526
/**
3627
* Cache tag
3728
*
3829
* @var string
3930
*/
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';
7432

7533
/**
76-
* @var LoggerInterface
77-
*/
78-
private $logger;
79-
80-
/**
81-
* @var DirectoryList
34+
* @var string[]
8235
*/
83-
private $directoryList;
36+
private array $loadedScopes = [];
8437

8538
/**
8639
* @var array
8740
*/
88-
private $pluginData;
41+
private array $pluginData = [];
8942

9043
/**
9144
* @var array
9245
*/
93-
private $inherited = [];
46+
private array $inherited = [];
9447

9548
/**
9649
* @var array
9750
*/
98-
private $processed;
99-
100-
/**
101-
* Scope priority loading scheme
102-
*
103-
* @var string[]
104-
*/
105-
private $scopePriorityScheme;
51+
private array $processed = [];
10652

10753
/**
10854
* @var array
10955
*/
110-
private $globalScopePluginData = [];
56+
private array $globalScopePluginData = [];
11157

11258
/**
11359
* @param ReaderInterface $reader
@@ -118,28 +64,22 @@ class PluginListGenerator implements ConfigWriterInterface, ConfigLoaderInterfac
11864
* @param ClassDefinitions $classDefinitions
11965
* @param LoggerInterface $logger
12066
* @param DirectoryList $directoryList
121-
* @param array $scopePriorityScheme
67+
* @param array $scopePriorityScheme [optional]
68+
* @param string $appMode [optional]
69+
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
12270
*/
12371
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
13382
) {
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;
14383
}
14484

14585
/**
@@ -245,22 +185,21 @@ public function loadScopedVirtualTypes($scopePriorityScheme, $loadedScopes, $plu
245185

246186
/**
247187
* Returns class definitions
248-
*
249-
* @return array
250188
*/
251-
private function getClassDefinitions()
189+
private function getClassDefinitions(): array
252190
{
253191
return $this->classDefinitions->getClasses();
254192
}
255193

256194
/**
257195
* Whether scope code is current scope code
258196
*
259-
* @param string $scopeCode
197+
* @param string|null $scopeCode
260198
* @return bool
261199
*/
262-
private function isCurrentScope($scopeCode)
200+
private function isCurrentScope(?string $scopeCode): bool
263201
{
202+
// ToDo: $scopeCode can be null in integration tests because of how scope is reset.
264203
return $this->scopeConfig->getCurrentScope() === $scopeCode;
265204
}
266205

@@ -366,9 +305,12 @@ public function trimInstanceStartingBackslash(&$plugins)
366305
public function filterPlugins(array &$plugins)
367306
{
368307
foreach ($plugins as $name => $plugin) {
369-
if (empty($plugin['instance'])) {
308+
if (!isset($plugin['instance'])) {
370309
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+
}
372314
}
373315
}
374316
}
@@ -401,26 +343,23 @@ public function merge(array $config, $pluginData)
401343
*
402344
* @param string $key
403345
* @param array $config
404-
* @return void
405-
* @throws \Magento\Framework\Exception\FileSystemException
346+
* @throws FileSystemException
406347
*/
407-
private function writeConfig(string $key, array $config)
348+
private function writeConfig(string $key, array $config): void
408349
{
409350
$this->initialize();
410-
$configuration = sprintf('<?php return %s;', var_export($config, true));
411351
file_put_contents(
412352
$this->directoryList->getPath(DirectoryList::GENERATED_METADATA) . '/' . $key . '.php',
413-
$configuration
353+
sprintf('<?php return %s;', var_export($config, true))
414354
);
415355
}
416356

417357
/**
418358
* Initializes writer
419359
*
420-
* @return void
421-
* @throws \Magento\Framework\Exception\FileSystemException
360+
* @throws FileSystemException
422361
*/
423-
private function initialize()
362+
private function initialize(): void
424363
{
425364
if (!file_exists($this->directoryList->getPath(DirectoryList::GENERATED_METADATA))) {
426365
mkdir($this->directoryList->getPath(DirectoryList::GENERATED_METADATA));

0 commit comments

Comments
 (0)