Skip to content
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
35d3823
Log undeclared plugin only if it is not disabled
thomas-kl1 Jul 18, 2025
710453e
Log in dev mode only or when plugin is actually enabled
thomas-kl1 Jul 18, 2025
8988902
Add missing property
thomas-kl1 Jul 18, 2025
7a404b0
Add missing phpdoc
thomas-kl1 Jul 18, 2025
abbee11
Fix License
thomas-kl1 Jul 18, 2025
cc9df6c
Fix typo
thomas-kl1 Jul 19, 2025
cf3bc4c
Merge branch '2.4-develop' into patch-28
engcom-Hotel Jul 29, 2025
3e67495
Add missing signature on private methods + use CPP
thomas-kl1 Aug 3, 2025
de49ca7
Merge branch '2.4-develop' into patch-28
thomas-kl1 Aug 3, 2025
48da421
Inject mode instead of State instance
thomas-kl1 Aug 5, 2025
bbac3c8
Fix typo in property name
thomas-kl1 Aug 5, 2025
c5233f8
Inject app mode in interceptor generator
thomas-kl1 Aug 5, 2025
2d564db
Merge branch '2.4-develop' into patch-28
thomas-kl1 Aug 5, 2025
b4f5cfc
Fix property must not be accessed before initialization
thomas-kl1 Aug 6, 2025
5a82b87
Merge branch '2.4-develop' into patch-28
thomas-kl1 Aug 6, 2025
9e27141
Remove duplicate declaration
thomas-kl1 Aug 6, 2025
56eac3e
Fix phpcs
thomas-kl1 Aug 6, 2025
9fef293
scopeCode can be null
thomas-kl1 Aug 11, 2025
fa9c525
Merge branch '2.4-develop' into patch-28
thomas-kl1 Aug 11, 2025
844e978
Merge branch '2.4-develop' into patch-28
thomas-kl1 Aug 13, 2025
4d2f9ee
Fix phpcs
thomas-kl1 Aug 13, 2025
c610cc7
Merge branch '2.4-develop' into patch-28
engcom-Charlie Aug 19, 2025
471b82e
Merge branch '2.4-develop' into patch-28
engcom-Charlie Aug 25, 2025
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@
<item name="primary" xsi:type="string">primary</item>
<item name="first" xsi:type="string">global</item>
</argument>
<argument name="appMode" xsi:type="init_parameter">Magento\Framework\App\State::PARAM_MODE</argument>
</arguments>
</type>
<type name="Magento\Framework\App\ResourceConnection">
Expand Down
139 changes: 39 additions & 100 deletions lib/internal/Magento/Framework/Interception/PluginListGenerator.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2020 Adobe
* All Rights Reserved.
*/
declare(strict_types=1);

namespace Magento\Framework\Interception;

use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\App\State;
use Magento\Framework\Config\ReaderInterface;
use Magento\Framework\Config\ScopeInterface;
use Magento\Framework\Exception\FileSystemException;
use Magento\Framework\Interception\ObjectManager\ConfigInterface;
use Magento\Framework\ObjectManager\DefinitionInterface as ClassDefinitions;
use Magento\Framework\ObjectManager\RelationsInterface;
Expand All @@ -20,94 +23,37 @@
*/
class PluginListGenerator implements ConfigWriterInterface, ConfigLoaderInterface
{
/**
* @var ScopeInterface
*/
private $scopeConfig;

/**
* Configuration reader
*
* @var ReaderInterface
*/
private $reader;

/**
* Cache tag
*
* @var string
*/
private $cacheId = 'plugin-list';

/**
* @var array
*/
private $loadedScopes = [];

/**
* Type config
*
* @var ConfigInterface
*/
private $omConfig;

/**
* Class relations information provider
*
* @var RelationsInterface
*/
private $relations;

/**
* List of interception methods per plugin
*
* @var DefinitionInterface
*/
private $definitions;

/**
* List of interceptable application classes
*
* @var ClassDefinitions
*/
private $classDefinitions;
private string $cacheId = 'plugin-list';

/**
* @var LoggerInterface
*/
private $logger;

/**
* @var DirectoryList
* @var string[]
*/
private $directoryList;
private array $loadedScopes = [];

/**
* @var array
*/
private $pluginData;
private array $pluginData = [];

/**
* @var array
*/
private $inherited = [];
private array $inherited = [];

/**
* @var array
*/
private $processed;

/**
* Scope priority loading scheme
*
* @var string[]
*/
private $scopePriorityScheme;
private array $processed = [];

/**
* @var array
*/
private $globalScopePluginData = [];
private array $globalScopePluginData = [];

/**
* @param ReaderInterface $reader
Expand All @@ -118,28 +64,22 @@ class PluginListGenerator implements ConfigWriterInterface, ConfigLoaderInterfac
* @param ClassDefinitions $classDefinitions
* @param LoggerInterface $logger
* @param DirectoryList $directoryList
* @param array $scopePriorityScheme
* @param array $scopePriorityScheme [optional]
* @param string $appMode [optional]
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
ReaderInterface $reader,
ScopeInterface $scopeConfig,
ConfigInterface $omConfig,
RelationsInterface $relations,
DefinitionInterface $definitions,
ClassDefinitions $classDefinitions,
LoggerInterface $logger,
DirectoryList $directoryList,
array $scopePriorityScheme = ['global']
private ReaderInterface $reader,
private ScopeInterface $scopeConfig,
private ConfigInterface $omConfig,
private RelationsInterface $relations,
private DefinitionInterface $definitions,
private ClassDefinitions $classDefinitions,
private LoggerInterface $logger,
private DirectoryList $directoryList,
private array $scopePriorityScheme = ['global'],
private string $appMode = State::MODE_DEFAULT
) {
$this->reader = $reader;
$this->scopeConfig = $scopeConfig;
$this->omConfig = $omConfig;
$this->relations = $relations;
$this->definitions = $definitions;
$this->classDefinitions = $classDefinitions;
$this->logger = $logger;
$this->directoryList = $directoryList;
$this->scopePriorityScheme = $scopePriorityScheme;
}

/**
Expand Down Expand Up @@ -245,22 +185,21 @@ public function loadScopedVirtualTypes($scopePriorityScheme, $loadedScopes, $plu

/**
* Returns class definitions
*
* @return array
*/
private function getClassDefinitions()
private function getClassDefinitions(): array
{
return $this->classDefinitions->getClasses();
}

/**
* Whether scope code is current scope code
*
* @param string $scopeCode
* @param string|null $scopeCode
* @return bool
*/
private function isCurrentScope($scopeCode)
private function isCurrentScope(?string $scopeCode): bool
{
// ToDo: $scopeCode can be null in integration tests because of how scope is reset.
return $this->scopeConfig->getCurrentScope() === $scopeCode;
}

Expand Down Expand Up @@ -366,9 +305,12 @@ public function trimInstanceStartingBackslash(&$plugins)
public function filterPlugins(array &$plugins)
{
foreach ($plugins as $name => $plugin) {
if (empty($plugin['instance'])) {
if (!isset($plugin['instance'])) {
unset($plugins[$name]);
$this->logger->info("Reference to undeclared plugin with name '{$name}'.");
// Log the undeclared plugin when it is not disabled or when the app is in Developer mode.
if ($this->appMode === State::MODE_DEVELOPER || !($plugin['disabled'] ?? false)) {
$this->logger->debug("Reference to undeclared plugin with name '{$name}'.");
}
}
}
}
Expand Down Expand Up @@ -401,26 +343,23 @@ public function merge(array $config, $pluginData)
*
* @param string $key
* @param array $config
* @return void
* @throws \Magento\Framework\Exception\FileSystemException
* @throws FileSystemException
*/
private function writeConfig(string $key, array $config)
private function writeConfig(string $key, array $config): void
{
$this->initialize();
$configuration = sprintf('<?php return %s;', var_export($config, true));
file_put_contents(
$this->directoryList->getPath(DirectoryList::GENERATED_METADATA) . '/' . $key . '.php',
$configuration
sprintf('<?php return %s;', var_export($config, true))
);
}

/**
* Initializes writer
*
* @return void
* @throws \Magento\Framework\Exception\FileSystemException
* @throws FileSystemException
*/
private function initialize()
private function initialize(): void
{
if (!file_exists($this->directoryList->getPath(DirectoryList::GENERATED_METADATA))) {
mkdir($this->directoryList->getPath(DirectoryList::GENERATED_METADATA));
Expand Down