Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Design.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Theme\Model;
7 
14 
28 {
32  const CACHE_TAG = 'CORE_DESIGN';
33 
39  protected $_eventPrefix = 'core_design';
40 
49 
53  protected $_localeDate;
54 
58  protected $_dateTime;
59 
63  private $serializer;
64 
75  public function __construct(
76  \Magento\Framework\Model\Context $context,
77  \Magento\Framework\Registry $registry,
78  \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
79  \Magento\Framework\Stdlib\DateTime $dateTime,
81  \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
82  array $data = [],
83  SerializerInterface $serializer = null
84  ) {
85  $this->_localeDate = $localeDate;
86  $this->_dateTime = $dateTime;
87  $this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class);
88  parent::__construct($context, $registry, $resource, $resourceCollection, $data);
89  }
90 
96  protected function _construct()
97  {
98  $this->_init(\Magento\Theme\Model\ResourceModel\Design::class);
99  }
100 
108  public function loadChange($storeId, $date = null)
109  {
110  if ($date === null) {
111  $date = $this->_dateTime->formatDate($this->_localeDate->scopeTimeStamp($storeId), false);
112  }
113 
114  $changeCacheId = 'design_change_' . md5($storeId . $date);
115  $result = $this->_cacheManager->load($changeCacheId);
116  if ($result === false) {
117  $result = $this->getResource()->loadChange($storeId, $date);
118  if (!$result) {
119  $result = [];
120  }
121  $this->_cacheManager->save($this->serializer->serialize($result), $changeCacheId, [self::CACHE_TAG], 86400);
122  } else {
123  $result = $this->serializer->unserialize($result);
124  }
125 
126  if ($result) {
127  $this->setData($result);
128  }
129 
130  return $this;
131  }
132 
139  public function changeDesign(\Magento\Framework\View\DesignInterface $packageInto)
140  {
141  $design = $this->getDesign();
142  if ($design) {
143  $packageInto->setDesignTheme($design);
144  }
145  return $this;
146  }
147 
153  public function getIdentities()
154  {
155  return [self::CACHE_TAG . '_' . $this->getId()];
156  }
157 }
changeDesign(\Magento\Framework\View\DesignInterface $packageInto)
Definition: Design.php:139
$resource
Definition: bulk.php:12
loadChange($storeId, $date=null)
Definition: Design.php:108
__construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, \Magento\Framework\Stdlib\DateTime $dateTime, AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[], SerializerInterface $serializer=null)
Definition: Design.php:75
$dateTime