Skip to content

compiled interceptors module #22826

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 74 commits into
base: 2.5-develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
2fb8f2a
Merge pull request #2 from magento/2.3-develop
fsw Jan 7, 2019
e0057b6
Merge pull request #3 from magento/2.3-develop
fsw May 10, 2019
53709eb
add creatuity compiled interceptors module
May 10, 2019
36f069e
Merge remote-tracking branch 'origin/2.3-develop' into user-2.3-develop
May 12, 2019
7f499e1
added scope as constructor parameter and properties for plugins cache
May 13, 2019
d97dba0
Merge branch '2.3-develop' of github.com:fsw/magento2 into 2.3-develop
May 13, 2019
cb0a213
get object manager from DI
May 14, 2019
d19f4f9
clean up code repetition by extending core plugins list
May 15, 2019
32e3cca
static code check fixes
May 15, 2019
224dd4e
hotfic for production mode
May 21, 2019
000d0a5
Merge pull request #4 from magento/2.3-develop
fsw May 21, 2019
e57df09
removed unnecessary inheritance, fix for methods returning self
May 23, 2019
f08394d
Merge branch '2.3-develop' of github.com:fsw/magento2 into 2.3-develop
May 23, 2019
8071fb2
bugfix for methods returning void
May 23, 2019
4948604
void methods fix
May 23, 2019
75e65ac
void methods fix
May 23, 2019
5fc398c
refactor of CompiledInterceptor
May 24, 2019
1999072
fixes for coding standard
May 24, 2019
f30e9cf
coding standards fix
May 27, 2019
82dc39f
coding standard fixes
May 27, 2019
41ca3b0
coding standard fixes
May 27, 2019
944144a
cyclomatic complexity refactor
May 27, 2019
5227be0
Merge pull request #5 from magento/2.3-develop
fsw May 27, 2019
d64c89a
coding standards fixes
May 27, 2019
16add49
Merge branch '2.3-develop' of github.com:fsw/magento2 into 2.3-develop
May 27, 2019
1058be9
fixes for compiled mode
May 30, 2019
ecd9b54
bugfix for primary scope for compiled mode
Jun 6, 2019
6285273
generating interceptors performance fix
Jun 7, 2019
5cb7dc9
Merge pull request #6 from magento/2.3-develop
fsw Jun 10, 2019
5b85a71
Merge branch '2.3-develop' of github.com:fsw/magento2 into 2.3-develop
Jun 10, 2019
d22a34e
optimise generation time from empty cache
Jun 10, 2019
5e62ebc
further optimisation and default scope fix
Jun 12, 2019
9c0aad8
Replaced preferences usage
YevSent Jun 20, 2019
bb6cc62
Merge pull request #7 from magento/2.3-develop
fsw Jun 24, 2019
c334bcf
Merge branch '2.3-develop' of github.com:fsw/magento2 into 2.3-develop
Jun 24, 2019
5665eec
Merge pull request #8 from joni-jones/interceptors
fsw Jun 24, 2019
c3019f3
Merge branch '2.3-develop' of github.com:fsw/magento2 into 2.3-develop
Jun 24, 2019
dfd3c28
manual backport of preferences usage fix
Jun 24, 2019
a7fc720
save plugins cache in generated code folder to simplify cache cleaning
Jun 24, 2019
1657b46
coding standards fix
Jun 24, 2019
07bfca9
move sompiledinterceptorsubstitution to avoid dependency issues, fix …
Jun 24, 2019
7f268ce
fix for plugins overriden by preferences
Jul 12, 2019
8b3cae6
Removed commented line
sidolov Oct 1, 2019
2bc739d
magento/magento2#22826: Refactoring.
engcom-Foxtrot Oct 17, 2019
29a6d8e
magento/magento2#22826: Static test fix.
engcom-Foxtrot Oct 18, 2019
dca21f7
magento/magento2#22826: Class level caching for compiled plugins remo…
engcom-Foxtrot Oct 22, 2019
219382f
magento/magento2#22826: Admin infinite redirect loop fix.
engcom-Foxtrot Oct 23, 2019
f96d546
magento/magento2#22826: Compiled plugin list optimization.
engcom-Foxtrot Oct 27, 2019
528408d
magento/magento2#22826: Static cache path update.
engcom-Foxtrot Oct 27, 2019
aa62a4d
magento/magento2#22826: Compiled interceptor return type fix.
engcom-Foxtrot Nov 1, 2019
eb1018b
magento/magento2#22826: Integration tests fix.
engcom-Foxtrot Nov 1, 2019
1ef18eb
Merge remote-tracking branch 'mainline/2.3-develop' into 2.3-develop
engcom-Foxtrot Nov 1, 2019
53e1e8d
magento/magento2#22826: Enable compiled interceptors.
engcom-Foxtrot Nov 1, 2019
75dea82
magento/magento2#22826: Remove ExecuteCommitCallbacks plugin.
engcom-Foxtrot Nov 1, 2019
b422bb1
magento/magento2#22826: Autoload fix.
engcom-Foxtrot Nov 3, 2019
b40eabe
magento/magento2#22826: Arguments resolving for interceptors fix.
engcom-Foxtrot Nov 6, 2019
94a29c7
Merge remote-tracking branch 'mainline/2.3-develop' into 2.3-develop
engcom-Foxtrot Nov 6, 2019
7fbcecd
Merge branch '2.3-develop' into 2.3-develop
engcom-Foxtrot Nov 6, 2019
53fa5c4
magento/magento2#22826: After plugin calls generation fix.
engcom-Foxtrot Nov 8, 2019
727cfc9
magento/magento2#22826: Tests fix.
engcom-Foxtrot Nov 8, 2019
23bdd02
magento/magento2#22826: Refactoring.
engcom-Foxtrot Nov 13, 2019
c263481
magento/magento2#22826: Compiled interceptor constructors generation …
engcom-Foxtrot Nov 14, 2019
c082b69
magento/magento2#22826: Static test fix.
engcom-Foxtrot Nov 15, 2019
5b57dbc
magento/magento2#22826: Compiled plugin list argument update.
engcom-Foxtrot Nov 18, 2019
de6e95b
magento/magento2#22826: Readme update.
engcom-Foxtrot Nov 18, 2019
7bc9f69
magento/magento2#22826: Disable compiled interceptors.
engcom-Foxtrot Nov 18, 2019
d1b674e
Merge branch '2.4-develop' into 2.3-develop
Sep 16, 2020
f6dccdd
Merge branch '2.4-develop' into 2.3-develop
Sep 17, 2020
f6e7ac4
Fixed incorrectly resolved merge conflicts
Sep 17, 2020
9d1f67c
Fixed incorrectly resolved merge conflicts
Sep 17, 2020
3fb9422
Fixed tests failures
Sep 17, 2020
76864e0
Merge branch '2.4-develop' into 2.3-develop
Sep 17, 2020
8f80b6e
Merge branch '2.5-develop' of https://github.com/magento/magento2 int…
fsw Mar 5, 2021
c9f47ef
Merge branch 'magento-2.5-develop' into 2.3-develop
fsw Mar 5, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions app/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@
<item name="extensionInterfaceFactory" xsi:type="string">\Magento\Framework\Api\Code\Generator\ExtensionAttributesInterfaceFactoryGenerator</item>
<item name="factory" xsi:type="string">\Magento\Framework\ObjectManager\Code\Generator\Factory</item>
<item name="proxy" xsi:type="string">\Magento\Framework\ObjectManager\Code\Generator\Proxy</item>
<item name="interceptor" xsi:type="string">\Magento\Framework\Interception\Code\Generator\Interceptor</item>
<item name="interceptor" xsi:type="string">Magento\Framework\Interception\Code\Generator\InterceptorInterface</item>
<item name="logger" xsi:type="string">\Magento\Framework\ObjectManager\Profiler\Code\Generator\Logger</item>
<item name="mapper" xsi:type="string">\Magento\Framework\Api\Code\Generator\Mapper</item>
<item name="persistor" xsi:type="string">\Magento\Framework\ObjectManager\Code\Generator\Persistor</item>
Expand All @@ -802,6 +802,21 @@
</argument>
</arguments>
</type>
<virtualType name="Magento\Framework\CompiledInterception\PluginList\PluginList"
type="Magento\Framework\Interception\PluginList\PluginList">
<arguments>
<argument name="cache" xsi:type="object">\Magento\Framework\CompiledInterception\Generator\FileCache</argument>
<argument name="cacheId" xsi:type="string">compiled_plugins</argument>
<argument name="serializer" xsi:type="object">\Magento\Framework\CompiledInterception\Generator\NoSerialize</argument>
</arguments>
</virtualType>
<type name="Magento\Framework\CompiledInterception\Generator\CompiledPluginList">
<arguments>
<argument name="pluginList" xsi:type="object">\Magento\Framework\CompiledInterception\PluginList\PluginList</argument>
</arguments>
</type>
<preference for="Magento\Framework\Interception\Code\Generator\InterceptorInterface" type="Magento\Framework\Interception\Code\Generator\Interceptor"/>
<preference for="Magento\Setup\Module\Di\Compiler\Config\Chain\InterceptorSubstitutionInterface" type="Magento\Setup\Module\Di\Compiler\Config\Chain\InterceptorSubstitution"/>
<type name="Magento\Framework\App\Cache\Frontend\Pool">
<arguments>
<argument name="frontendSettings" xsi:type="array">
Expand Down Expand Up @@ -1825,9 +1840,6 @@
type="Magento\Framework\Mail\MimeMessage" />
<preference for="Magento\Framework\Mail\MimePartInterface"
type="Magento\Framework\Mail\MimePart" />
<type name="Magento\Framework\DB\Adapter\AdapterInterface">
<plugin name="execute_commit_callbacks" type="Magento\Framework\Model\ExecuteCommitCallbacks" />
</type>
<preference for="Magento\Framework\GraphQl\Query\ErrorHandlerInterface" type="Magento\Framework\GraphQl\Query\ErrorHandler"/>
<preference for="Magento\Framework\Filter\VariableResolverInterface" type="Magento\Framework\Filter\VariableResolver\StrategyResolver"/>
<virtualType name="configured_block_cache" type="Magento\Framework\App\Cache">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.TooManyFields)
* phpcs:disable Magento2.Functions.DiscouragedFunction
*/
class Application
{
Expand Down Expand Up @@ -725,6 +726,7 @@ protected function getCustomDirs()
DirectoryList::STATIC_VIEW => [$path => "{$this->installDir}/pub/static"],
DirectoryList::TMP_MATERIALIZATION_DIR => [$path => "{$var}/view_preprocessed/pub/static"],
DirectoryList::GENERATED_CODE => [$path => "{$generated}/code"],
DirectoryList::STATIC_CACHE => [$path => "{$generated}/static_cache"],
DirectoryList::CACHE => [$path => "{$var}/cache"],
DirectoryList::LOG => [$path => "{$var}/log"],
DirectoryList::SESSION => [$path => "{$var}/session"],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\TestFramework\Interception;

use Magento\Framework\CompiledInterception\Generator\FileCache;
use Magento\Framework\CompiledInterception\Generator\NoSerialize;
use Magento\Framework\Config\ScopeInterface;
use Magento\Framework\Interception\Definition\Runtime as InterceptionDefinitionRuntime;
use Magento\Framework\Interception\ObjectManager\ConfigInterface;
use Magento\Framework\Interception\PluginList\PluginList as OriginalPluginList;
use Magento\Framework\ObjectManager\Config\Reader\Dom;
use Magento\Framework\ObjectManager\Definition\Runtime as ObjectManagerDefinitionRuntime;
use Magento\Framework\ObjectManager\Relations\Runtime as ObjectManagerRelationsRuntime;
use Magento\TestFramework\ObjectManager;

/**
* Provides compiled plugin list configuration.
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
class CompiledPluginList extends \Magento\Framework\CompiledInterception\Generator\CompiledPluginList
{
/**
* @var PluginList
*/
private $pluginList;

/**
* @param OriginalPluginList $unused
*/
public function __construct(
OriginalPluginList $unused
) {
$objectManager = ObjectManager::getInstance();
$this->pluginList = $objectManager->create(
PluginList::class,
[
$objectManager->get(Dom::class),
$objectManager->get(ScopeInterface ::class),
$objectManager->get(FileCache ::class),
$objectManager->get(ObjectManagerRelationsRuntime ::class),
$objectManager->get(ConfigInterface::class),
$objectManager->get(InterceptionDefinitionRuntime ::class),
$objectManager,
$objectManager->get(ObjectManagerDefinitionRuntime ::class),
['global'],
'compiled_plugins',
$objectManager->get(NoSerialize ::class),
]
);
parent::__construct($this->pluginList);
}

/**
* Reset internal cache
*/
public function reset()
{
$this->pluginList->reset();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Framework\CompiledInterception\CompiledInterceptor;

use Magento\Framework\App\AreaList;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Code\Generator\Io;
use Magento\Framework\CompiledInterception\Generator\AreasPluginList;
use Magento\Framework\CompiledInterception\Generator\CompiledInterceptor;
use Magento\Framework\CompiledInterception\Generator\CompiledPluginList;
use Magento\Framework\CompiledInterception\Generator\CompiledPluginListFactory;
use Magento\Framework\CompiledInterception\Generator\FileCache;
use Magento\Framework\CompiledInterception\Generator\NoSerialize;
use Magento\Framework\CompiledInterception\Generator\StaticScope;
use Magento\Framework\CompiledInterception\CompiledInterceptor\Custom\Module\Model\ComplexItem;
use Magento\Framework\CompiledInterception\CompiledInterceptor\Custom\Module\Model\ComplexItemTyped;
use Magento\Framework\CompiledInterception\CompiledInterceptor\Custom\Module\Model\Item;
use Magento\Framework\CompiledInterception\CompiledInterceptor\Custom\Module\Model\SecondItem;
use Magento\Framework\Config\ScopeInterfaceFactory;
use Magento\Framework\Interception\ObjectManager\ConfigInterface;
use Magento\Framework\Interception\PluginList\PluginList;
use Magento\Framework\ObjectManager\Config\Reader\Dom;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
use PHPUnit\Framework\MockObject\MockObject;

class CompiledInterceptorTest extends \PHPUnit\Framework\TestCase
{
/**
* @var Io|MockObject
*/
private $ioGenerator;

/**
* @var AreaList|MockObject
*/
private $areaList;

/**
* @inheritdoc
*/
protected function setUp(): void
{
$this->ioGenerator = $this->getMockBuilder(Io::class)
->disableOriginalConstructor()
->getMock();

$this->areaList = $this->getMockBuilder(AreaList::class)
->disableOriginalConstructor()
->getMock();
}

/**
* @return array
*/
public function createScopeReaders()
{
$readerMap = include __DIR__ . '/_files/reader_mock_map.php';
$readerMock = $this->createMock(Dom::class);
$readerMock->method('read')->willReturnMap($readerMap);

$omMock = $this->createMock(ObjectManager::class);

$omConfigMock = $this->getMockForAbstractClass(
ConfigInterface::class
);

$omConfigMock->method('getOriginalInstanceType')->willReturnArgument(0);
$ret = [];
$objectManagerHelper = new ObjectManagerHelper($this);
$directoryList = ObjectManager::getInstance()->get(DirectoryList::class);
//clear static cache
$fileCache = new FileCache($directoryList);
$fileCache->clean();
foreach ($readerMap as $readerLine) {
$pluginList = ObjectManager::getInstance()->create(
PluginList::class,
[
'objectManager' => $omMock,
'configScope' => new StaticScope($readerLine[0]),
'reader' => $readerMock,
'omConfig' => $omConfigMock,
'cache' => $fileCache,
'cachePath' => false,
'serializer' => new NoSerialize()
]
);

$ret[$readerLine[0]] = $objectManagerHelper->getObject(
CompiledPluginList::class,
[
'pluginList' => $pluginList
]
);
}
return $ret;
}

/**
* Checks a test case when interceptor generates code for the specified class.
*
* @param string $className
* @param string $resultClassName
* @param string $fileName
* @dataProvider interceptorDataProvider
*/
public function testGenerate($className, $resultClassName, $fileName)
{
$objectManagerHelper = new ObjectManagerHelper($this);
/** @var AreasPluginList $areaPlugins */
$areaPlugins = $objectManagerHelper->getObject(
AreasPluginList::class,
[
'areaList' => $this->areaList,
'scopeInterfaceFactory' => $objectManagerHelper->getObject(ScopeInterfaceFactory::class),
'compiledPluginListFactory' => $objectManagerHelper->getObject(CompiledPluginListFactory::class),
'plugins' => $this->createScopeReaders()
]
);

/** @var CompiledInterceptor|MockObject $interceptor */
$interceptor = $this->getMockBuilder(CompiledInterceptor::class)
->setMethods(['_validateData'])
->setConstructorArgs(
[
$areaPlugins,
$className,
$resultClassName,
$this->ioGenerator,
null,
null
]
)
->getMock();

$this->ioGenerator->method('generateResultFileName')->with('\\' . $resultClassName)
->willReturn($fileName . '.php');

$code = file_get_contents(__DIR__ . '/_out_interceptors/' . $fileName . '.txt');

$this->ioGenerator->method('writeResultFile')->with($fileName . '.php', $code);
$interceptor->method('_validateData')->willReturn(true);

$generated = $interceptor->generate();
$this->assertEquals($fileName . '.php', $generated, 'Generated interceptor is invalid.');
}

/**
* Gets list of interceptor samples.
*
* @return array
*/
public function interceptorDataProvider()
{
return [
[
Item::class,
Item::class . '\Interceptor',
'Item'
],
[
ComplexItem::class,
ComplexItem::class . '\Interceptor',
'ComplexItem'
],
[
ComplexItemTyped::class,
ComplexItemTyped::class . '\Interceptor',
'ComplexItemTyped'
],
[
SecondItem::class,
SecondItem::class . '\Interceptor',
'SecondItem'
],
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
// @codingStandardsIgnoreFile

namespace Magento\Framework\CompiledInterception\CompiledInterceptor\Custom\Module\Model;

class ComplexItem
{
private $attribute;
private $variadicAttribute;

public function getName()
{
return $this->attribute;
}

/**
* @param $value
*/
public function setValue($value)
{
$this->attribute = $value;
}

public function & getReference()
{
}

/**
* @param mixed ...$variadicValue
*/
public function firstVariadicParameter(...$variadicValue)
{
$this->variadicAttribute = $variadicValue;
}

/**
* @param $value
* @param mixed ...$variadicValue
*/
public function secondVariadicParameter($value, ...$variadicValue)
{
$this->attribute = $value;
$this->variadicAttribute = $variadicValue;
}

/**
* @param mixed ...$variadicValue
*/
public function byRefVariadic(& ...$variadicValue)
{
$this->variadicAttribute = $variadicValue;
}

/**
*
*/
public function returnsSelf()
{
return $this;
}
}
Loading