Skip to content

Commit 3261737

Browse files
authored
Merge pull request #5842 from magento-performance/MC-31618-2
[Performance] Move static config to files - PLUGIN_LIST
2 parents 735579d + 53dccc7 commit 3261737

File tree

16 files changed

+1109
-428
lines changed

16 files changed

+1109
-428
lines changed

app/etc/di.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@
209209
<preference for="Magento\Framework\MessageQueue\QueueFactoryInterface" type="Magento\Framework\MessageQueue\QueueFactory" />
210210
<preference for="Magento\Framework\Search\Request\IndexScopeResolverInterface" type="Magento\Framework\Indexer\ScopeResolver\IndexScopeResolver"/>
211211
<preference for="Magento\Framework\HTTP\ClientInterface" type="Magento\Framework\HTTP\Client\Curl" />
212+
<preference for="Magento\Framework\Interception\ConfigLoaderInterface" type="Magento\Framework\Interception\PluginListGenerator" />
213+
<preference for="Magento\Framework\Interception\ConfigWriterInterface" type="Magento\Framework\Interception\PluginListGenerator" />
212214
<type name="Magento\Framework\Model\ResourceModel\Db\TransactionManager" shared="false" />
213215
<type name="Magento\Framework\Acl\Data\Cache">
214216
<arguments>
@@ -431,6 +433,16 @@
431433
</argument>
432434
</arguments>
433435
</type>
436+
<type name="Magento\Framework\Interception\PluginListGenerator">
437+
<arguments>
438+
<argument name="reader" xsi:type="object">Magento\Framework\ObjectManager\Config\Reader\Dom\Proxy</argument>
439+
<argument name="logger" xsi:type="object">\Psr\Log\LoggerInterface\Proxy</argument>
440+
<argument name="scopePriorityScheme" xsi:type="array">
441+
<item name="primary" xsi:type="string">primary</item>
442+
<item name="first" xsi:type="string">global</item>
443+
</argument>
444+
</arguments>
445+
</type>
434446
<type name="Magento\Framework\App\ResourceConnection">
435447
<arguments>
436448
<argument name="connectionFactory" xsi:type="object">Magento\Framework\App\ResourceConnection\ConnectionFactory</argument>

dev/tests/integration/framework/Magento/TestFramework/Interception/PluginList.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\TestFramework\Interception;
77

8+
use Magento\Framework\Interception\ConfigLoaderInterface;
9+
use Magento\Framework\Interception\PluginListGenerator;
810
use Magento\Framework\Serialize\SerializerInterface;
911

1012
/**
@@ -31,6 +33,8 @@ class PluginList extends \Magento\Framework\Interception\PluginList\PluginList
3133
* @param array $scopePriorityScheme
3234
* @param string|null $cacheId
3335
* @param SerializerInterface|null $serializer
36+
* @param ConfigLoaderInterface|null $configLoader
37+
* @param PluginListGenerator|null $pluginListGenerator
3438
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
3539
*/
3640
public function __construct(
@@ -44,7 +48,9 @@ public function __construct(
4448
\Magento\Framework\ObjectManager\DefinitionInterface $classDefinitions,
4549
array $scopePriorityScheme,
4650
$cacheId = 'plugins',
47-
SerializerInterface $serializer = null
51+
SerializerInterface $serializer = null,
52+
ConfigLoaderInterface $configLoader = null,
53+
PluginListGenerator $pluginListGenerator = null
4854
) {
4955
parent::__construct(
5056
$reader,
@@ -57,7 +63,9 @@ public function __construct(
5763
$classDefinitions,
5864
$scopePriorityScheme,
5965
$cacheId,
60-
$serializer
66+
$serializer,
67+
$configLoader,
68+
$pluginListGenerator
6169
);
6270
$this->_originScopeScheme = $this->_scopePriorityScheme;
6371
}

dev/tests/integration/testsuite/Magento/Framework/Interception/AbstractPlugin.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Framework\Interception;
77

8+
use Magento\Framework\App\Filesystem\DirectoryList;
9+
810
/**
911
* Class GeneralTest
1012
*
@@ -81,6 +83,10 @@ public function setUpInterceptionConfig($pluginConfig)
8183
$cacheManager->method('load')->willReturn(null);
8284
$definitions = new \Magento\Framework\ObjectManager\Definition\Runtime();
8385
$relations = new \Magento\Framework\ObjectManager\Relations\Runtime();
86+
$configLoader = $this->createMock(ConfigLoaderInterface::class);
87+
$logger = $this->createMock(\Psr\Log\LoggerInterface::class);
88+
$directoryList = $this->createMock(DirectoryList::class);
89+
$configWriter = $this->createMock(PluginListGenerator::class);
8490
$interceptionConfig = new Config\Config(
8591
$this->_configReader,
8692
$configScope,
@@ -104,6 +110,10 @@ public function setUpInterceptionConfig($pluginConfig)
104110
\Magento\Framework\ObjectManager\DefinitionInterface::class => $definitions,
105111
\Magento\Framework\Interception\DefinitionInterface::class => $interceptionDefinitions,
106112
\Magento\Framework\Serialize\SerializerInterface::class => $json,
113+
\Magento\Framework\Interception\ConfigLoaderInterface::class => $configLoader,
114+
\Psr\Log\LoggerInterface::class => $logger,
115+
\Magento\Framework\App\Filesystem\DirectoryList::class => $directoryList,
116+
\Magento\Framework\App\ObjectManager\ConfigWriterInterface::class => $configWriter
107117
];
108118
$this->_objectManager = new \Magento\Framework\ObjectManager\ObjectManager(
109119
$factory,
@@ -118,8 +128,8 @@ public function setUpInterceptionConfig($pluginConfig)
118128
'preferences' => [
119129
\Magento\Framework\Interception\PluginListInterface::class =>
120130
\Magento\Framework\Interception\PluginList\PluginList::class,
121-
\Magento\Framework\Interception\ChainInterface::class =>
122-
\Magento\Framework\Interception\Chain\Chain::class,
131+
\Magento\Framework\Interception\ConfigWriterInterface::class =>
132+
\Magento\Framework\Interception\PluginListGenerator::class
123133
],
124134
]
125135
);
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Framework\Interception;
9+
10+
use Magento\Framework\App\Filesystem\DirectoryList;
11+
use Magento\Framework\Filesystem\DriverInterface;
12+
use Magento\TestFramework\Application;
13+
use Magento\TestFramework\Helper\Bootstrap;
14+
15+
class PluginListGeneratorTest extends \PHPUnit\Framework\TestCase
16+
{
17+
/**
18+
* Generated plugin list config for frontend scope
19+
*/
20+
const CACHE_ID = 'primary|global|frontend|plugin-list';
21+
22+
/**
23+
* @var PluginListGenerator
24+
*/
25+
private $model;
26+
27+
/**
28+
* @var DirectoryList
29+
*/
30+
private $directoryList;
31+
32+
/**
33+
* @var DriverInterface
34+
*/
35+
private $file;
36+
37+
/**
38+
* @var Application
39+
*/
40+
private $application;
41+
42+
/**
43+
* @inheritDoc
44+
*/
45+
protected function setUp(): void
46+
{
47+
$this->application = Bootstrap::getInstance()->getBootstrap()->getApplication();
48+
$this->directoryList = new DirectoryList(BP, $this->getCustomDirs());
49+
$this->file = Bootstrap::getObjectManager()->create(DriverInterface::class);
50+
$reader = Bootstrap::getObjectManager()->create(
51+
// phpstan:ignore "Class Magento\Framework\ObjectManager\Config\Reader\Dom\Proxy not found."
52+
\Magento\Framework\ObjectManager\Config\Reader\Dom\Proxy::class
53+
);
54+
$scopeConfig = Bootstrap::getObjectManager()->create(\Magento\Framework\Config\Scope::class);
55+
$omConfig = Bootstrap::getObjectManager()->create(
56+
\Magento\Framework\Interception\ObjectManager\Config\Developer::class
57+
);
58+
$relations = Bootstrap::getObjectManager()->create(
59+
\Magento\Framework\ObjectManager\Relations\Runtime::class
60+
);
61+
$definitions = Bootstrap::getObjectManager()->create(
62+
\Magento\Framework\Interception\Definition\Runtime::class
63+
);
64+
$classDefinitions = Bootstrap::getObjectManager()->create(
65+
\Magento\Framework\ObjectManager\Definition\Runtime::class
66+
);
67+
// phpstan:ignore "Class Psr\Log\LoggerInterface\Proxy not found."
68+
$logger = Bootstrap::getObjectManager()->create(\Psr\Log\LoggerInterface\Proxy::class);
69+
$this->model = new PluginListGenerator(
70+
$reader,
71+
$scopeConfig,
72+
$omConfig,
73+
$relations,
74+
$definitions,
75+
$classDefinitions,
76+
$logger,
77+
$this->directoryList,
78+
['primary', 'global']
79+
);
80+
}
81+
82+
/**
83+
* Test plugin list configuration generation and load.
84+
*/
85+
public function testPluginListConfigGeneration()
86+
{
87+
$scopes = ['frontend'];
88+
$this->model->write($scopes);
89+
$configData = $this->model->load(self::CACHE_ID);
90+
$this->assertNotEmpty($configData[0]);
91+
$this->assertNotEmpty($configData[1]);
92+
$this->assertNotEmpty($configData[2]);
93+
$expected = [
94+
1 => [
95+
0 => 'genericHeaderPlugin',
96+
1 => 'asyncCssLoad',
97+
2 => 'response-http-page-cache'
98+
]
99+
];
100+
// Here in test is assumed that this class below has 3 plugins. But the amount of plugins and class itself
101+
// may vary. If it is changed, please update these assertions.
102+
$this->assertArrayHasKey(
103+
'Magento\\Framework\\App\\Response\\Http_sendResponse___self',
104+
$configData[2],
105+
'Processed plugin does not exist in the processed plugins array.'
106+
);
107+
$this->assertSame(
108+
$expected,
109+
$configData[2]['Magento\\Framework\\App\\Response\\Http_sendResponse___self'],
110+
'Plugin configurations are not equal'
111+
);
112+
}
113+
114+
/**
115+
* Gets customized directory paths
116+
*
117+
* @return array
118+
*/
119+
private function getCustomDirs()
120+
{
121+
$path = DirectoryList::PATH;
122+
$generated = "{$this->application->getTempDir()}/generated";
123+
124+
return [
125+
DirectoryList::GENERATED_METADATA => [$path => "{$generated}/metadata"],
126+
];
127+
}
128+
129+
/**
130+
* @inheritDoc
131+
*/
132+
protected function tearDown(): void
133+
{
134+
$filePath = $this->directoryList->getPath(DirectoryList::GENERATED_METADATA)
135+
. '/' . self::CACHE_ID . '.' . 'php';
136+
137+
if (file_exists($filePath)) {
138+
$this->file->deleteFile($filePath);
139+
}
140+
}
141+
}

dev/tests/integration/testsuite/Magento/Framework/ObjectManager/Factory/CompiledTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
use Magento\Framework\ObjectManager\TestAsset\InterfaceImplementation;
1515
use Magento\Framework\ObjectManager\TestAsset\TestAssetInterface;
1616

17+
/**
18+
* @magentoAppIsolation enabled
19+
*/
1720
class CompiledTest extends AbstractFactoryRuntimeDefinitionsTestCases
1821
{
1922
/**

dev/tests/integration/testsuite/Magento/Framework/ObjectManager/Factory/Dynamic/DeveloperTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
use Magento\Framework\ObjectManager\TestAsset\InterfaceImplementation;
1616
use Magento\Framework\ObjectManager\TestAsset\TestAssetInterface;
1717

18+
/**
19+
* @magentoAppIsolation enabled
20+
*/
1821
class DeveloperTest extends AbstractFactoryRuntimeDefinitionsTestCases
1922
{
2023
/**
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Framework\Interception;
9+
10+
/**
11+
* Interception configuration loader interface.
12+
*/
13+
interface ConfigLoaderInterface
14+
{
15+
/**
16+
* Load interception configuration data per scope.
17+
*
18+
* @param string $cacheId
19+
* @return array
20+
*/
21+
public function load(string $cacheId): array;
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Framework\Interception;
9+
10+
/**
11+
* Interception config writer interface.
12+
*/
13+
interface ConfigWriterInterface
14+
{
15+
/**
16+
* Write interception configuration for scopes.
17+
*
18+
* @param array $scopes
19+
* @return void
20+
*/
21+
public function write(array $scopes): void;
22+
}

0 commit comments

Comments
 (0)