Skip to content

Commit 8e928d6

Browse files
committed
MAGETWO-62486: Refactor Layout to store data from object only and restore object
- fixed bamboo static builds
1 parent 118dd7c commit 8e928d6

File tree

3 files changed

+75
-53
lines changed

3 files changed

+75
-53
lines changed

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

Lines changed: 38 additions & 31 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 $propertyMap = [
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
/**
@@ -540,17 +549,12 @@ public function flushScheduledStructure()
540549
*/
541550
public function __toArray()
542551
{
543-
return [
544-
'scheduledStructure' => $this->scheduledStructure,
545-
'scheduledData' => $this->scheduledData,
546-
'scheduledElements' => $this->scheduledElements,
547-
'scheduledMoves' => $this->scheduledMoves,
548-
'scheduledRemoves' => $this->scheduledRemoves,
549-
'scheduledIfconfig' => $this->scheduledIfconfig,
550-
'scheduledPaths' => $this->scheduledPaths,
551-
'elementsToSort' => $this->elementsToSort,
552-
'brokenParent' => $this->brokenParent,
553-
];
552+
$result = [];
553+
foreach ($this->propertyMap as $property) {
554+
$result[$property] = $this->{$property};
555+
}
556+
557+
return $result;
554558
}
555559

556560
/**
@@ -559,19 +563,22 @@ public function __toArray()
559563
*
560564
* @param array $data
561565
* @return void
562-
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
563-
* @SuppressWarnings(PHPMD.NPathComplexity)
564566
*/
565567
public function populateWithArray(array $data)
566568
{
567-
$this->scheduledStructure = isset($data['scheduledStructure']) ? $data['scheduledStructure'] : [];
568-
$this->scheduledData = isset($data['scheduledData']) ? $data['scheduledData'] : [];
569-
$this->scheduledElements = isset($data['scheduledElements']) ? $data['scheduledElements'] : [];
570-
$this->scheduledMoves = isset($data['scheduledMoves']) ? $data['scheduledMoves'] : [];
571-
$this->scheduledRemoves = isset($data['scheduledRemoves']) ? $data['scheduledRemoves'] : [];
572-
$this->scheduledIfconfig = isset($data['scheduledIfconfig']) ? $data['scheduledIfconfig'] : [];
573-
$this->scheduledPaths = isset($data['scheduledPaths']) ? $data['scheduledPaths'] : [];
574-
$this->elementsToSort = isset($data['elementsToSort']) ? $data['elementsToSort'] : [];
575-
$this->brokenParent = isset($data['brokenParent']) ? $data['brokenParent'] : [];
569+
foreach ($this->propertyMap as $property) {
570+
$this->{$property} = $this->getDataValue($property, $data);
571+
}
572+
}
573+
574+
/**
575+
* Get value from array by key.
576+
*
577+
* @param string $name
578+
* @param array $data
579+
* @return array
580+
*/
581+
private function getDataValue($name, array $data) {
582+
return isset($data[$name]) ? $data[$name] : [];
576583
}
577584
}

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

Lines changed: 36 additions & 21 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 $propertyMap = [
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
*
@@ -203,16 +219,12 @@ public function getAssets()
203219
*/
204220
public function __toArray()
205221
{
206-
return [
207-
'assets' => $this->assets,
208-
'removeAssets' => $this->removeAssets,
209-
'title' => $this->title,
210-
'metadata' => $this->metadata,
211-
'elementAttributes' => $this->elementAttributes,
212-
'removeElementAttributes' => $this->removeElementAttributes,
213-
'bodyClasses' => $this->bodyClasses,
214-
'isBodyClassesDeleted' => $this->isBodyClassesDeleted,
215-
];
222+
$result = [];
223+
foreach ($this->propertyMap as $property) {
224+
$result[$property] = $this->{$property};
225+
}
226+
227+
return $result;
216228
}
217229

218230
/**
@@ -221,19 +233,22 @@ public function __toArray()
221233
*
222234
* @param array $data
223235
* @return void
224-
* @SuppressWarnings(PHPMD.NPathComplexity)
225236
*/
226237
public function populateWithArray(array $data)
227238
{
228-
$this->assets = isset($data['assets']) ? $data['assets'] : [];
229-
$this->removeAssets = isset($data['removeAssets']) ? $data['removeAssets'] : [];
230-
$this->title = isset($data['title']) ? $data['title'] : '';
231-
$this->metadata = isset($data['metadata']) ? $data['metadata'] : [];
232-
$this->elementAttributes = isset($data['elementAttributes']) ? $data['elementAttributes'] : [];
233-
$this->removeElementAttributes = isset($data['removeElementAttributes'])
234-
? $data['removeElementAttributes']
235-
: [];
236-
$this->bodyClasses = isset($data['bodyClasses']) ? $data['bodyClasses'] : [];
237-
$this->isBodyClassesDeleted = isset($data['isBodyClassesDeleted']) ? $data['isBodyClassesDeleted'] : false;
239+
foreach ($this->propertyMap as $property) {
240+
$this->{$property} = $this->getDataValue($property, $data);
241+
}
242+
}
243+
244+
/**
245+
* Get value from array by key.
246+
*
247+
* @param string $name
248+
* @param array $data
249+
* @return array
250+
*/
251+
private function getDataValue($name, array $data) {
252+
return isset($data[$name]) ? $data[$name] : [];
238253
}
239254
}

lib/internal/Magento/Framework/View/Test/Unit/LayoutTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* See COPYING.txt for license details.
55
*/
66
namespace Magento\Framework\View\Test\Unit;
7+
78
use Magento\Framework\Serialize\SerializerInterface;
89

910
/**
@@ -193,7 +194,6 @@ protected function setUp()
193194
return json_decode($value, true);
194195
});
195196

196-
197197
$this->model = new \Magento\Framework\View\Layout(
198198
$this->processorFactoryMock,
199199
$this->eventManagerMock,

0 commit comments

Comments
 (0)