Skip to content

Commit 5f76007

Browse files
committed
Merge branch 'MAGETWO-62486' of github.com:magento-troll/magento2ce into Sprint55
2 parents 3210e52 + 0a65f0b commit 5f76007

File tree

4 files changed

+226
-19
lines changed

4 files changed

+226
-19
lines changed

lib/internal/Magento/Framework/View/Layout.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
use Magento\Framework\Cache\FrontendInterface;
99
use Magento\Framework\Event\ManagerInterface;
1010
use Magento\Framework\Message\ManagerInterface as MessageManagerInterface;
11+
use Magento\Framework\Serialize\SerializerInterface;
1112
use Magento\Framework\View\Layout\Element;
1213
use Magento\Framework\View\Layout\ScheduledStructure;
1314
use Magento\Framework\App\State as AppState;
1415
use Psr\Log\LoggerInterface as Logger;
1516
use Magento\Framework\Exception\LocalizedException;
17+
use Magento\Framework\App\ObjectManager;
1618

1719
/**
1820
* Layout model
@@ -165,6 +167,11 @@ class Layout extends \Magento\Framework\Simplexml\Config implements \Magento\Fra
165167
*/
166168
protected $logger;
167169

170+
/**
171+
* @var SerializerInterface
172+
*/
173+
private $serializer;
174+
168175
/**
169176
* @param Layout\ProcessorFactory $processorFactory
170177
* @param ManagerInterface $eventManager
@@ -179,6 +186,7 @@ class Layout extends \Magento\Framework\Simplexml\Config implements \Magento\Fra
179186
* @param \Magento\Framework\App\State $appState
180187
* @param \Psr\Log\LoggerInterface $logger
181188
* @param bool $cacheable
189+
* @param SerializerInterface|null $serializer
182190
*/
183191
public function __construct(
184192
Layout\ProcessorFactory $processorFactory,
@@ -193,10 +201,12 @@ public function __construct(
193201
Layout\Generator\ContextFactory $generatorContextFactory,
194202
AppState $appState,
195203
Logger $logger,
196-
$cacheable = true
204+
$cacheable = true,
205+
SerializerInterface $serializer = null
197206
) {
198207
$this->_elementClass = \Magento\Framework\View\Layout\Element::class;
199208
$this->_renderingOutput = new \Magento\Framework\DataObject();
209+
$this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class);
200210

201211
$this->_processorFactory = $processorFactory;
202212
$this->_eventManager = $eventManager;
@@ -308,12 +318,19 @@ public function generateElements()
308318
$cacheId = 'structure_' . $this->getUpdate()->getCacheId();
309319
$result = $this->cache->load($cacheId);
310320
if ($result) {
311-
$this->readerContext = unserialize($result);
321+
$data = $this->serializer->unserialize($result);
322+
$this->getReaderContext()->getPageConfigStructure()->populateWithArray($data['pageConfigStructure']);
323+
$this->getReaderContext()->getScheduledStructure()->populateWithArray($data['scheduledStructure']);
312324
} else {
313325
\Magento\Framework\Profiler::start('build_structure');
314326
$this->readerPool->interpret($this->getReaderContext(), $this->getNode());
315327
\Magento\Framework\Profiler::stop('build_structure');
316-
$this->cache->save(serialize($this->getReaderContext()), $cacheId, $this->getUpdate()->getHandles());
328+
329+
$data = [
330+
'pageConfigStructure' => $this->getReaderContext()->getPageConfigStructure()->__toArray(),
331+
'scheduledStructure' => $this->getReaderContext()->getScheduledStructure()->__toArray(),
332+
];
333+
$this->cache->save($this->serializer->serialize($data), $cacheId, $this->getUpdate()->getHandles());
317334
}
318335

319336
$generatorContext = $this->generatorContextFactory->create(

lib/internal/Magento/Framework/View/Layout/ScheduledStructure.php

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,23 @@ class ScheduledStructure
1919
const ELEMENT_IS_AFTER = 'isAfter';
2020
/**#@-*/
2121

22+
/**
23+
* Map of class properties.
24+
*
25+
* @var array
26+
*/
27+
private $serializableProperties = [
28+
'scheduledStructure',
29+
'scheduledData',
30+
'scheduledElements',
31+
'scheduledMoves',
32+
'scheduledRemoves',
33+
'scheduledIfconfig',
34+
'scheduledPaths',
35+
'elementsToSort',
36+
'brokenParent',
37+
];
38+
2239
/**
2340
* Information about structural elements, scheduled for creation
2441
*
@@ -84,18 +101,10 @@ class ScheduledStructure
84101

85102
/**
86103
* @param array $data
87-
*
88-
* @SuppressWarnings(PHPMD.NPathComplexity)
89104
*/
90105
public function __construct(array $data = [])
91106
{
92-
$this->scheduledStructure = isset($data['scheduledStructure']) ? $data['scheduledStructure'] : [];
93-
$this->scheduledData = isset($data['scheduledData']) ? $data['scheduledData'] : [];
94-
$this->scheduledElements = isset($data['scheduledElements']) ? $data['scheduledElements'] : [];
95-
$this->scheduledMoves = isset($data['scheduledMoves']) ? $data['scheduledMoves'] : [];
96-
$this->scheduledRemoves = isset($data['scheduledRemoves']) ? $data['scheduledRemoves'] : [];
97-
$this->scheduledIfconfig = isset($data['scheduledIfconfig']) ? $data['scheduledIfconfig'] : [];
98-
$this->scheduledPaths = isset($data['scheduledPaths']) ? $data['scheduledPaths'] : [];
107+
$this->populateWithArray($data);
99108
}
100109

101110
/**
@@ -531,4 +540,44 @@ public function flushScheduledStructure()
531540
$this->scheduledElements = [];
532541
$this->scheduledStructure = [];
533542
}
543+
544+
/**
545+
* Reformat 'Layout scheduled structure' to array.
546+
*
547+
* @return array
548+
*/
549+
public function __toArray()
550+
{
551+
$result = [];
552+
foreach ($this->serializableProperties as $property) {
553+
$result[$property] = $this->{$property};
554+
}
555+
556+
return $result;
557+
}
558+
559+
/**
560+
* Update 'Layout scheduled structure' data.
561+
*
562+
* @param array $data
563+
* @return void
564+
*/
565+
public function populateWithArray(array $data)
566+
{
567+
foreach ($this->serializableProperties as $property) {
568+
$this->{$property} = $this->getArrayValueByKey($property, $data);
569+
}
570+
}
571+
572+
/**
573+
* Get value from array by key.
574+
*
575+
* @param string $key
576+
* @param array $array
577+
* @return array
578+
*/
579+
private function getArrayValueByKey($key, array $array)
580+
{
581+
return isset($array[$key]) ? $array[$key] : [];
582+
}
534583
}

lib/internal/Magento/Framework/View/Page/Config/Structure.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,22 @@
1212
*/
1313
class Structure
1414
{
15+
/**
16+
* Map of class properties.
17+
*
18+
* @var array
19+
*/
20+
private $serializableProperties = [
21+
'assets',
22+
'removeAssets',
23+
'title',
24+
'metadata',
25+
'elementAttributes',
26+
'removeElementAttributes',
27+
'bodyClasses',
28+
'isBodyClassesDeleted',
29+
];
30+
1531
/**
1632
* Information assets elements on page
1733
*
@@ -194,4 +210,44 @@ public function getAssets()
194210
{
195211
return $this->assets;
196212
}
213+
214+
/**
215+
* Reformat 'Page config structure' to array.
216+
*
217+
* @return array
218+
*/
219+
public function __toArray()
220+
{
221+
$result = [];
222+
foreach ($this->serializableProperties as $property) {
223+
$result[$property] = $this->{$property};
224+
}
225+
226+
return $result;
227+
}
228+
229+
/**
230+
* Update 'Page config structure' data.
231+
*
232+
* @param array $data
233+
* @return void
234+
*/
235+
public function populateWithArray(array $data)
236+
{
237+
foreach ($this->serializableProperties as $property) {
238+
$this->{$property} = $this->getArrayValueByKey($property, $data);
239+
}
240+
}
241+
242+
/**
243+
* Get value from array by key.
244+
*
245+
* @param string $key
246+
* @param array $array
247+
* @return array
248+
*/
249+
private function getArrayValueByKey($key, array $array)
250+
{
251+
return isset($array[$key]) ? $array[$key] : [];
252+
}
197253
}

0 commit comments

Comments
 (0)