55 * Copyright © Magento, Inc. All rights reserved.
66 * See COPYING.txt for license details.
77 */
8+ declare (strict_types=1 );
9+
810namespace Magento \Theme \Model \PageLayout \Config ;
911
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+
1021/**
1122 * Page layout config builder
1223 */
13- class Builder implements \ Magento \ Framework \ View \ Model \ PageLayout \ Config \ BuilderInterface
24+ class Builder implements BuilderInterface
1425{
1526 const CACHE_KEY_LAYOUTS = 'THEME_LAYOUTS_FILES_MERGED ' ;
1627
1728 /**
18- * @var \Magento\Framework\View\PageLayout\ ConfigFactory
29+ * @var ConfigFactory
1930 */
2031 protected $ configFactory ;
2132
2233 /**
23- * @var \Magento\Framework\View\PageLayout\File\Collector\ Aggregated
34+ * @var Aggregated
2435 */
2536 protected $ fileCollector ;
2637
2738 /**
28- * @var \Magento\Theme\Model\ResourceModel\Theme\ Collection
39+ * @var Collection
2940 */
3041 protected $ themeCollection ;
3142
@@ -35,27 +46,36 @@ class Builder implements \Magento\Framework\View\Model\PageLayout\Config\Builder
3546 private $ configFiles = [];
3647
3748 /**
38- * @var \Magento\Framework\App\Cache\Type\Layout
49+ * @var Layout|null
50+ */
51+ private $ cacheModel ;
52+ /**
53+ * @var SerializerInterface|null
3954 */
40- protected $ cacheModel ;
55+ private $ serializer ;
4156
4257 /**
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
4763 */
4864 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
5370 ) {
5471 $ this ->configFactory = $ configFactory ;
5572 $ this ->fileCollector = $ fileCollector ;
5673 $ 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);
5979 }
6080
6181 /**
@@ -77,14 +97,15 @@ protected function getConfigFiles()
7797 $ configFiles = [];
7898 $ this ->configFiles = $ this ->cacheModel ->load (self ::CACHE_KEY_LAYOUTS );
7999 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 );
81102 }
82103 if (empty ($ this ->configFiles )) {
83104 foreach ($ this ->themeCollection ->loadRegisteredThemes () as $ theme ) {
84105 $ configFiles [] = $ this ->fileCollector ->getFilesContent ($ theme , 'layouts.xml ' );
85106 }
86107 $ 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 );
88109 }
89110 }
90111
0 commit comments