Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AreaList.php
Go to the documentation of this file.
1 <?php
8 namespace Magento\Framework\App;
9 
10 class AreaList
11 {
17  protected $_areas = [];
18 
22  protected $_areaInstances = [];
23 
27  protected $_defaultAreaCode;
28 
32  protected $_resolverFactory;
33 
37  protected $objectManager;
38 
45  public function __construct(
47  Area\FrontNameResolverFactory $resolverFactory,
48  array $areas = [],
49  $default = null
50  ) {
51  $this->objectManager = $objectManager;
52  $this->_resolverFactory = $resolverFactory;
53  if ($areas) {
54  $this->_areas = $areas;
55  }
56  if ($default) {
57  $this->_defaultAreaCode = $default;
58  }
59  }
60 
68  public function getCodeByFrontName($frontName)
69  {
70  foreach ($this->_areas as $areaCode => &$areaInfo) {
71  if (!isset($areaInfo['frontName']) && isset($areaInfo['frontNameResolver'])) {
72  $resolver = $this->_resolverFactory->create($areaInfo['frontNameResolver']);
73  $areaInfo['frontName'] = $resolver->getFrontName(true);
74  }
75  if ($areaInfo['frontName'] == $frontName) {
76  return $areaCode;
77  }
78  }
80  }
81 
89  public function getFrontName($areaCode)
90  {
91  return $this->_areas[$areaCode]['frontName'] ?? null;
92  }
93 
100  public function getCodes()
101  {
102  return array_keys($this->_areas);
103  }
104 
112  public function getDefaultRouter($areaCode)
113  {
114  return $this->_areas[$areaCode]['router'] ?? null;
115  }
116 
123  public function getArea($code)
124  {
125  if (!isset($this->_areaInstances[$code])) {
126  $this->_areaInstances[$code] = $this->objectManager->create(
127  \Magento\Framework\App\AreaInterface::class,
128  ['areaCode' => $code]
129  );
130  }
131  return $this->_areaInstances[$code];
132  }
133 }
__construct(\Magento\Framework\ObjectManagerInterface $objectManager, Area\FrontNameResolverFactory $resolverFactory, array $areas=[], $default=null)
Definition: AreaList.php:45
$code
Definition: info.phtml:12