Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SectionPool.php
Go to the documentation of this file.
1 <?php
7 
10 
18 {
24  protected $objectManager;
25 
31  protected $sectionSourceMap;
32 
36  protected $identifier;
37 
45  public function __construct(
47  \Magento\Customer\CustomerData\Section\Identifier $identifier,
48  array $sectionSourceMap = []
49  ) {
50  $this->objectManager = $objectManager;
51  $this->identifier = $identifier;
52  $this->sectionSourceMap = $sectionSourceMap;
53  }
54 
58  public function getSectionsData(array $sectionNames = null, $updateIds = false)
59  {
60  $sectionsData = $sectionNames ? $this->getSectionDataByNames($sectionNames) : $this->getAllSectionData();
61  $sectionsData = $this->identifier->markSections($sectionsData, $sectionNames, $updateIds);
62  return $sectionsData;
63  }
64 
72  protected function getSectionDataByNames($sectionNames)
73  {
74  $data = [];
75  foreach ($sectionNames as $sectionName) {
76  if (!isset($this->sectionSourceMap[$sectionName])) {
77  throw new LocalizedException(__('The "%1" section source isn\'t supported.', $sectionName));
78  }
79  $data[$sectionName] = $this->get($this->sectionSourceMap[$sectionName])->getSectionData();
80  }
81  return $data;
82  }
83 
89  protected function getAllSectionData()
90  {
91  $data = [];
92  foreach ($this->sectionSourceMap as $sectionName => $sectionClass) {
93  $data[$sectionName] = $this->get($sectionClass)->getSectionData();
94  }
95  return $data;
96  }
97 
105  protected function get($name)
106  {
107  $sectionSource = $this->objectManager->get($name);
108 
109  if (!$sectionSource instanceof SectionSourceInterface) {
110  throw new LocalizedException(
111  __('%1 doesn\'t extend \Magento\Customer\CustomerData\SectionSourceInterface', $name)
112  );
113  }
114  return $sectionSource;
115  }
116 }
getSectionsData(array $sectionNames=null, $updateIds=false)
Definition: SectionPool.php:58
__()
Definition: __.php:13
__construct(ObjectManagerInterface $objectManager, \Magento\Customer\CustomerData\Section\Identifier $identifier, array $sectionSourceMap=[])
Definition: SectionPool.php:45
if(!isset($_GET['name'])) $name
Definition: log.php:14