5
5
* Copyright © Magento, Inc. All rights reserved.
6
6
* See COPYING.txt for license details.
7
7
*/
8
+ declare (strict_types=1 );
9
+
8
10
namespace Magento \Theme \Model \PageLayout \Config ;
9
11
12
+ use Magento \Framework \App \Cache \Type \Layout ;
13
+ use Magento \Framework \App \ObjectManager ;
14
+ use Magento \Framework \View \Model \PageLayout \Config \BuilderInterface ;
15
+ use Magento \Framework \View \PageLayout \ConfigFactory ;
16
+ use Magento \Framework \View \PageLayout \File \Collector \Aggregated ;
17
+ use Magento \Theme \Model \ResourceModel \Theme \Collection ;
18
+ use Magento \Theme \Model \Theme \Data ;
19
+ use Magento \Framework \Serialize \SerializerInterface ;
20
+
10
21
/**
11
22
* Page layout config builder
12
23
*/
13
- class Builder implements \ Magento \ Framework \ View \ Model \ PageLayout \ Config \ BuilderInterface
24
+ class Builder implements BuilderInterface
14
25
{
15
26
const CACHE_KEY_LAYOUTS = 'THEME_LAYOUTS_FILES_MERGED ' ;
16
27
17
28
/**
18
- * @var \Magento\Framework\View\PageLayout\ ConfigFactory
29
+ * @var ConfigFactory
19
30
*/
20
31
protected $ configFactory ;
21
32
22
33
/**
23
- * @var \Magento\Framework\View\PageLayout\File\Collector\ Aggregated
34
+ * @var Aggregated
24
35
*/
25
36
protected $ fileCollector ;
26
37
27
38
/**
28
- * @var \Magento\Theme\Model\ResourceModel\Theme\ Collection
39
+ * @var Collection
29
40
*/
30
41
protected $ themeCollection ;
31
42
@@ -35,27 +46,36 @@ class Builder implements \Magento\Framework\View\Model\PageLayout\Config\Builder
35
46
private $ configFiles = [];
36
47
37
48
/**
38
- * @var \Magento\Framework\App\Cache\Type\Layout
49
+ * @var Layout|null
50
+ */
51
+ private $ cacheModel ;
52
+ /**
53
+ * @var SerializerInterface|null
39
54
*/
40
- protected $ cacheModel ;
55
+ private $ serializer ;
41
56
42
57
/**
43
- * @param \Magento\Framework\View\PageLayout\ConfigFactory $configFactory
44
- * @param \Magento\Framework\View\PageLayout\File\Collector\Aggregated $fileCollector
45
- * @param \Magento\Theme\Model\ResourceModel\Theme\Collection $themeCollection
46
- * @param \Magento\Framework\App\Cache\Type\Layout $cacheModel
58
+ * @param ConfigFactory $configFactory
59
+ * @param Aggregated $fileCollector
60
+ * @param Collection $themeCollection
61
+ * @param Layout|null $cacheModel
62
+ * @param SerializerInterface|null $serializer
47
63
*/
48
64
public function __construct (
49
- \Magento \Framework \View \PageLayout \ConfigFactory $ configFactory ,
50
- \Magento \Framework \View \PageLayout \File \Collector \Aggregated $ fileCollector ,
51
- \Magento \Theme \Model \ResourceModel \Theme \Collection $ themeCollection ,
52
- \Magento \Framework \App \Cache \Type \Layout $ cacheModel
65
+ ConfigFactory $ configFactory ,
66
+ Aggregated $ fileCollector ,
67
+ Collection $ themeCollection ,
68
+ ?Layout $ cacheModel = null ,
69
+ ?SerializerInterface $ serializer = null
53
70
) {
54
71
$ this ->configFactory = $ configFactory ;
55
72
$ this ->fileCollector = $ fileCollector ;
56
73
$ this ->themeCollection = $ themeCollection ;
57
- $ this ->cacheModel = $ cacheModel ;
58
- $ this ->themeCollection ->setItemObjectClass (\Magento \Theme \Model \Theme \Data::class);
74
+ $ this ->themeCollection ->setItemObjectClass (Data::class);
75
+ $ this ->cacheModel = $ cacheModel
76
+ ?? ObjectManager::getInstance ()->get (Layout::class);
77
+ $ this ->serializer = $ serializer
78
+ ?? ObjectManager::getInstance ()->get (SerializerInterface::class);
59
79
}
60
80
61
81
/**
@@ -77,14 +97,15 @@ protected function getConfigFiles()
77
97
$ configFiles = [];
78
98
$ this ->configFiles = $ this ->cacheModel ->load (self ::CACHE_KEY_LAYOUTS );
79
99
if (!empty ($ this ->configFiles )) {
80
- $ this ->configFiles = @unserialize ($ this ->configFiles );//if value in cache is corrupted.
100
+ //if value in cache is corrupted.
101
+ $ this ->configFiles = $ this ->serializer ->unserialize ($ this ->configFiles );
81
102
}
82
103
if (empty ($ this ->configFiles )) {
83
104
foreach ($ this ->themeCollection ->loadRegisteredThemes () as $ theme ) {
84
105
$ configFiles [] = $ this ->fileCollector ->getFilesContent ($ theme , 'layouts.xml ' );
85
106
}
86
107
$ this ->configFiles = array_merge (...$ configFiles );
87
- $ this ->cacheModel ->save (serialize ($ this ->configFiles ), self ::CACHE_KEY_LAYOUTS );
108
+ $ this ->cacheModel ->save ($ this -> serializer -> serialize ($ this ->configFiles ), self ::CACHE_KEY_LAYOUTS );
88
109
}
89
110
}
90
111
0 commit comments