Skip to content

Commit 8233bef

Browse files
committed
MAGETWO-31111: Plugins configuration caching
- Interception configuration caching added
1 parent 172dcb9 commit 8233bef

File tree

5 files changed

+81
-4
lines changed

5 files changed

+81
-4
lines changed

dev/tools/Magento/Tools/Di/App/Compiler.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ public function launch()
7373
BP . '/' . 'app/code', BP . '/' . 'lib/internal/Magento/Framework', BP . '/' . 'var/generation'
7474
],
7575
Task\OperationFactory::PLUGINS =>
76-
BP . '/app'
76+
BP . '/app',
77+
Task\OperationFactory::INTERCEPTION_CACHE => [
78+
BP . '/' . 'app/code', BP . '/' . 'lib/internal/Magento/Framework', BP . '/' . 'var/generation'
79+
]
7780
];
7881

7982
$responseCode = Response::SUCCESS;
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
/**
3+
*
4+
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
5+
*/
6+
7+
namespace Magento\Tools\Di\App\Task\Operation;
8+
use Magento\Tools\Di\App\Task\OperationInterface;
9+
10+
class InterceptionCache implements OperationInterface
11+
{
12+
/**
13+
* @var array
14+
*/
15+
private $data = [];
16+
17+
private $configInterface;
18+
19+
public function __construct(
20+
\Magento\Framework\Interception\Config\Config $configInterface,
21+
$data = []
22+
) {
23+
$this->data = $data;
24+
$this->configInterface = $configInterface;
25+
}
26+
27+
/**
28+
* Flushes interception cached configuration and generates a new one
29+
*
30+
* @return void
31+
*/
32+
public function doOperation()
33+
{
34+
if (empty($this->data)) {
35+
return;
36+
}
37+
38+
$logWriter = new \Magento\Tools\Di\Compiler\Log\Writer\Quiet();
39+
$errorWriter = new \Magento\Tools\Di\Compiler\Log\Writer\Console();
40+
41+
$log = new \Magento\Tools\Di\Compiler\Log\Log($logWriter, $errorWriter);
42+
43+
$validator = new \Magento\Framework\Code\Validator();
44+
$validator->add(new \Magento\Framework\Code\Validator\ConstructorIntegrity());
45+
$validator->add(new \Magento\Framework\Code\Validator\ContextAggregation());
46+
47+
$directoryCompiler = new \Magento\Tools\Di\Compiler\Directory($log, $validator);
48+
foreach ($this->data as $path) {
49+
if (is_readable($path)) {
50+
$directoryCompiler->compile($path);
51+
}
52+
}
53+
54+
list($definitions, ) = $directoryCompiler->getResult();
55+
56+
$this->configInterface->initialize(array_keys($definitions));
57+
}
58+
}

dev/tools/Magento/Tools/Di/App/Task/OperationFactory.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ class OperationFactory
3333
*/
3434
const PLUGINS = 'plugins';
3535

36+
/**
37+
* Interception cache
38+
*/
39+
const INTERCEPTION_CACHE = 'interception_cache';
40+
3641
/**
3742
* Operations definitions
3843
*
@@ -43,6 +48,7 @@ class OperationFactory
4348
self::INTERCEPTION => 'Magento\Tools\Di\App\Task\Operation\Interception',
4449
self::RELATIONS => 'Magento\Tools\Di\App\Task\Operation\Relations',
4550
self::PLUGINS => 'Magento\Tools\Di\App\Task\Operation\Plugins',
51+
self::INTERCEPTION_CACHE => 'Magento\Tools\Di\App\Task\Operation\InterceptionCache',
4652
];
4753

4854
/**

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,19 @@ public function __construct(
9999
if ($intercepted !== false) {
100100
$this->_intercepted = unserialize($intercepted);
101101
} else {
102-
$this->initialize();
102+
$this->initialize($this->_classDefinitions->getClasses());
103103
}
104104
}
105105

106106
/**
107107
* Initialize interception config
108108
*
109+
* @param array $classDefinitions
109110
* @return void
110111
*/
111-
protected function initialize()
112+
public function initialize($classDefinitions = [])
112113
{
114+
$this->_cache->clean(\Zend_Cache::CLEANING_MODE_MATCHING_TAG, [$this->_cacheId]);
113115
$config = [];
114116
foreach ($this->_scopeList->getAllScopes() as $scope) {
115117
$config = array_replace_recursive($config, $this->_reader->read($scope));
@@ -123,7 +125,7 @@ protected function initialize()
123125
foreach ($config as $typeName => $typeConfig) {
124126
$this->hasPlugins(ltrim($typeName, '\\'));
125127
}
126-
foreach ($this->_classDefinitions->getClasses() as $class) {
128+
foreach ($classDefinitions as $class) {
127129
$this->hasPlugins($class);
128130
}
129131
$this->_cache->save(serialize($this->_intercepted), $this->_cacheId);

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,12 @@ interface ConfigInterface
1515
* @return bool
1616
*/
1717
public function hasPlugins($type);
18+
19+
/**
20+
* Initialize interception config
21+
*
22+
* @param array $classDefinitions
23+
* @return void
24+
*/
25+
public function initialize($classDefinitions = []);
1826
}

0 commit comments

Comments
 (0)