Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
SectionPool Class Reference
Inheritance diagram for SectionPool:
SectionPoolInterface

Public Member Functions

 __construct (ObjectManagerInterface $objectManager, \Magento\Customer\CustomerData\Section\Identifier $identifier, array $sectionSourceMap=[])
 
 getSectionsData (array $sectionNames=null, $updateIds=false)
 

Protected Member Functions

 getSectionDataByNames ($sectionNames)
 
 getAllSectionData ()
 
 get ($name)
 

Protected Attributes

 $objectManager
 
 $sectionSourceMap
 
 $identifier
 

Detailed Description

Section pool

@api

Since
100.0.2

Definition at line 17 of file SectionPool.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( ObjectManagerInterface  $objectManager,
\Magento\Customer\CustomerData\Section\Identifier  $identifier,
array  $sectionSourceMap = [] 
)

Construct

Parameters
ObjectManagerInterface$objectManager
\Magento\Customer\CustomerData\Section\Identifier$identifier
array$sectionSourceMap

Definition at line 45 of file SectionPool.php.

49  {
50  $this->objectManager = $objectManager;
51  $this->identifier = $identifier;
52  $this->sectionSourceMap = $sectionSourceMap;
53  }

Member Function Documentation

◆ get()

get (   $name)
protected

Get section source by name

Parameters
string$name
Returns
SectionSourceInterface
Exceptions
LocalizedException

Definition at line 105 of file SectionPool.php.

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  }
__()
Definition: __.php:13
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ getAllSectionData()

getAllSectionData ( )
protected

Get all section sources

Returns
array

Definition at line 89 of file SectionPool.php.

90  {
91  $data = [];
92  foreach ($this->sectionSourceMap as $sectionName => $sectionClass) {
93  $data[$sectionName] = $this->get($sectionClass)->getSectionData();
94  }
95  return $data;
96  }

◆ getSectionDataByNames()

getSectionDataByNames (   $sectionNames)
protected

Get section sources by section names

Parameters
array$sectionNames
Returns
array
Exceptions

Definition at line 72 of file SectionPool.php.

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  }
__()
Definition: __.php:13

◆ getSectionsData()

getSectionsData ( array  $sectionNames = null,
  $updateIds = false 
)

{Get section data by section names. If $sectionNames is null then return all sections data

Parameters
array$sectionNames
bool$updateIds
Returns
array
}

Implements SectionPoolInterface.

Definition at line 58 of file SectionPool.php.

59  {
60  $sectionsData = $sectionNames ? $this->getSectionDataByNames($sectionNames) : $this->getAllSectionData();
61  $sectionsData = $this->identifier->markSections($sectionsData, $sectionNames, $updateIds);
62  return $sectionsData;
63  }

Field Documentation

◆ $identifier

$identifier
protected

Definition at line 36 of file SectionPool.php.

◆ $objectManager

$objectManager
protected

Definition at line 24 of file SectionPool.php.

◆ $sectionSourceMap

$sectionSourceMap
protected

Definition at line 31 of file SectionPool.php.


The documentation for this class was generated from the following file: