Skip to content

Commit 3210e52

Browse files
committed
Merge branch 'PR-TROLL-MAGETWO-60419' of github.com:magento-troll/magento2ce into Sprint55
2 parents 6ae3418 + 820bf5a commit 3210e52

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

app/code/Magento/Ui/Model/Manager.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
use Magento\Framework\View\Element\UiComponent\Config\Provider\Component\Definition as ComponentDefinition;
1818
use Magento\Framework\View\Element\UiComponent\Config\ReaderFactory;
1919
use Magento\Framework\View\Element\UiComponent\Config\UiReaderInterface;
20+
use Magento\Framework\Serialize\SerializerInterface;
21+
use Magento\Framework\App\ObjectManager;
2022

2123
/**
2224
* Class Manager
@@ -94,6 +96,11 @@ class Manager implements ManagerInterface
9496
*/
9597
protected $uiReader;
9698

99+
/**
100+
* @var SerializerInterface
101+
*/
102+
private $serializer;
103+
97104
/**
98105
* @param ComponentDefinition $componentConfigProvider
99106
* @param DomMergerInterface $domMerger
@@ -102,6 +109,7 @@ class Manager implements ManagerInterface
102109
* @param AggregatedFileCollectorFactory $aggregatedFileCollectorFactory
103110
* @param CacheInterface $cache
104111
* @param InterpreterInterface $argumentInterpreter
112+
* @param SerializerInterface|null $serializer
105113
*/
106114
public function __construct(
107115
ComponentDefinition $componentConfigProvider,
@@ -110,7 +118,8 @@ public function __construct(
110118
ArrayObjectFactory $arrayObjectFactory,
111119
AggregatedFileCollectorFactory $aggregatedFileCollectorFactory,
112120
CacheInterface $cache,
113-
InterpreterInterface $argumentInterpreter
121+
InterpreterInterface $argumentInterpreter,
122+
SerializerInterface $serializer = null
114123
) {
115124
$this->componentConfigProvider = $componentConfigProvider;
116125
$this->domMerger = $domMerger;
@@ -120,6 +129,7 @@ public function __construct(
120129
$this->aggregatedFileCollectorFactory = $aggregatedFileCollectorFactory;
121130
$this->cache = $cache;
122131
$this->argumentInterpreter = $argumentInterpreter;
132+
$this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class);
123133
}
124134

125135
/**
@@ -164,9 +174,14 @@ public function prepareData($name)
164174
$cachedPool = $this->cache->load($cacheID);
165175
if ($cachedPool === false) {
166176
$this->prepare($name);
167-
$this->cache->save($this->componentsPool->serialize(), $cacheID);
177+
$this->cache->save(
178+
$this->serializer->serialize($this->componentsPool->getArrayCopy()),
179+
$cacheID
180+
);
168181
} else {
169-
$this->componentsPool->unserialize($cachedPool);
182+
$this->componentsPool->exchangeArray(
183+
$this->serializer->unserialize($cachedPool)
184+
);
170185
}
171186
$this->componentsData->offsetSet($name, $this->componentsPool);
172187
$this->componentsData->offsetSet($name, $this->evaluateComponentArguments($this->getData($name)));

app/code/Magento/Ui/Test/Unit/Model/ManagerTest.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ class ManagerTest extends \PHPUnit_Framework_TestCase
7575
*/
7676
protected $aggregatedFileCollectorFactory;
7777

78+
/** @var \Magento\Framework\Serialize\SerializerInterface|\PHPUnit_Framework_MockObject_MockObject */
79+
private $serializer;
80+
7881
protected function setUp()
7982
{
8083
$this->componentConfigProvider = $this->getMockBuilder(
@@ -105,14 +108,33 @@ protected function setUp()
105108
->getMockForAbstractClass();
106109
$this->argumentInterpreter = $this->getMockBuilder(\Magento\Framework\Data\Argument\InterpreterInterface::class)
107110
->getMockForAbstractClass();
111+
$this->serializer = $this->getMockBuilder(
112+
\Magento\Framework\Serialize\SerializerInterface::class
113+
)->getMockForAbstractClass();
114+
$this->serializer->expects($this->any())
115+
->method('serialize')
116+
->willReturnCallback(
117+
function ($value) {
118+
return json_encode($value);
119+
}
120+
);
121+
$this->serializer->expects($this->any())
122+
->method('unserialize')
123+
->willReturnCallback(
124+
function ($value) {
125+
return json_decode($value, true);
126+
}
127+
);
128+
108129
$this->manager = new Manager(
109130
$this->componentConfigProvider,
110131
$this->domMerger,
111132
$this->readerFactory,
112133
$this->arrayObjectFactory,
113134
$this->aggregatedFileCollectorFactory,
114135
$this->cacheConfig,
115-
$this->argumentInterpreter
136+
$this->argumentInterpreter,
137+
$this->serializer
116138
);
117139
}
118140

@@ -192,7 +214,7 @@ public function getComponentData()
192214
[
193215
'test_component1',
194216
new \ArrayObject(),
195-
$cachedData->serialize(),
217+
json_encode($cachedData->getArrayCopy()),
196218
[],
197219
[
198220
'test_component1' => [

0 commit comments

Comments
 (0)