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

Public Member Functions

 __construct (\Psr\Log\LoggerInterface $logger, \Magento\Framework\Event\ManagerInterface $eventManager, \Magento\Framework\TranslateInterface $translator, \Magento\Framework\ObjectManagerInterface $objectManager, ConfigLoaderInterface $diConfigLoader, \Magento\Framework\App\DesignInterface $design, \Magento\Framework\App\ScopeResolverInterface $scopeResolver, \Magento\Framework\View\DesignExceptions $designExceptions, $areaCode)
 
 load ($part=null)
 
 detectDesign ($request=null)
 

Data Fields

const AREA_GLOBAL = 'global'
 
const AREA_FRONTEND = 'frontend'
 
const AREA_ADMINHTML = 'adminhtml'
 
const AREA_DOC = 'doc'
 
const AREA_CRONTAB = 'crontab'
 
const AREA_WEBAPI_REST = 'webapi_rest'
 
const AREA_WEBAPI_SOAP = 'webapi_soap'
 
const AREA_GRAPHQL = 'graphql'
 
const AREA_ADMIN = 'admin'
 
const PARAM_AREA = 'area'
 
- Data Fields inherited from AreaInterface
const PART_CONFIG = 'config'
 
const PART_TRANSLATE = 'translate'
 
const PART_DESIGN = 'design'
 

Protected Member Functions

 _applyUserAgentDesignException ($request)
 
 _getDesign ()
 
 _loadPart ($part)
 
 _initConfig ()
 
 _initTranslate ()
 
 _initDesign ()
 

Protected Attributes

 $_loadedParts
 
 $_code
 
 $_eventManager
 
 $_translator
 
 $_objectManager
 
 $_diConfigLoader
 
 $_logger
 
 $_design
 
 $_scopeResolver
 
 $_designExceptions
 

Detailed Description

Application area model

@SuppressWarnings(PHPMD.CouplingBetweenObjects)

Definition at line 16 of file Area.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Psr\Log\LoggerInterface  $logger,
\Magento\Framework\Event\ManagerInterface  $eventManager,
\Magento\Framework\TranslateInterface  $translator,
\Magento\Framework\ObjectManagerInterface  $objectManager,
ConfigLoaderInterface  $diConfigLoader,
\Magento\Framework\App\DesignInterface  $design,
\Magento\Framework\App\ScopeResolverInterface  $scopeResolver,
\Magento\Framework\View\DesignExceptions  $designExceptions,
  $areaCode 
)
Parameters
\Psr\Log\LoggerInterface$logger
\Magento\Framework\Event\ManagerInterface$eventManager
\Magento\Framework\TranslateInterface$translator
\Magento\Framework\ObjectManagerInterface$objectManager
ConfigLoaderInterface$diConfigLoader
\Magento\Framework\App\DesignInterface$design
\Magento\Framework\App\ScopeResolverInterface$scopeResolver
\Magento\Framework\View\DesignExceptions$designExceptions
string$areaCode

Definition at line 110 of file Area.php.

120  {
121  $this->_code = $areaCode;
122  $this->_objectManager = $objectManager;
123  $this->_diConfigLoader = $diConfigLoader;
124  $this->_eventManager = $eventManager;
125  $this->_translator = $translator;
126  $this->_logger = $logger;
127  $this->_design = $design;
128  $this->_scopeResolver = $scopeResolver;
129  $this->_designExceptions = $designExceptions;
130  }
$objectManager
Definition: bootstrap.php:17
$logger

Member Function Documentation

◆ _applyUserAgentDesignException()

_applyUserAgentDesignException (   $request)
protected

Analyze user-agent information to override custom design settings

Parameters
\Magento\Framework\App\RequestInterface$request
Returns
bool

Definition at line 174 of file Area.php.

175  {
176  try {
177  $theme = $this->_designExceptions->getThemeByRequest($request);
178  if (false !== $theme) {
179  $this->_getDesign()->setDesignTheme($theme);
180  return true;
181  }
182  } catch (\Exception $e) {
183  $this->_logger->critical($e);
184  }
185  return false;
186  }
$theme

◆ _getDesign()

_getDesign ( )
protected
Returns
\Magento\Framework\View\DesignInterface

Definition at line 191 of file Area.php.

192  {
193  return $this->_objectManager->get(\Magento\Framework\View\DesignInterface::class);
194  }

◆ _initConfig()

_initConfig ( )
protected

Load area configuration

Returns
$this

Definition at line 232 of file Area.php.

233  {
234  $this->_objectManager->configure($this->_diConfigLoader->load($this->_code));
235  return $this;
236  }

◆ _initDesign()

_initDesign ( )
protected

Initialize design

Returns
$this

Definition at line 259 of file Area.php.

260  {
261  $this->_getDesign()->setArea($this->_code)->setDefaultDesignTheme();
262  return $this;
263  }

◆ _initTranslate()

_initTranslate ( )
protected

Initialize translate object.

Returns
$this

Definition at line 243 of file Area.php.

244  {
245  $this->_translator->loadData(null, false);
246 
248  $this->_objectManager->get(\Magento\Framework\Phrase\RendererInterface::class)
249  );
250 
251  return $this;
252  }
static setRenderer(RendererInterface $renderer)
Definition: Phrase.php:46

◆ _loadPart()

_loadPart (   $part)
protected

Loading part of area

Parameters
string$part
Returns
$this

Definition at line 202 of file Area.php.

203  {
204  if (isset($this->_loadedParts[$part])) {
205  return $this;
206  }
207  \Magento\Framework\Profiler::start(
208  'load_area:' . $this->_code . '.' . $part,
209  ['group' => 'load_area', 'area_code' => $this->_code, 'part' => $part]
210  );
211  switch ($part) {
212  case self::PART_CONFIG:
213  $this->_initConfig();
214  break;
216  $this->_initTranslate();
217  break;
218  case self::PART_DESIGN:
219  $this->_initDesign();
220  break;
221  }
222  $this->_loadedParts[$part] = true;
223  \Magento\Framework\Profiler::stop('load_area:' . $this->_code . '.' . $part);
224  return $this;
225  }

◆ detectDesign()

detectDesign (   $request = null)

Detect and apply design for the area

Parameters
\Magento\Framework\App\RequestInterface$request
Returns
void

Definition at line 154 of file Area.php.

155  {
156  if ($this->_code == self::AREA_FRONTEND) {
157  $isDesignException = $request && $this->_applyUserAgentDesignException($request);
158  if (!$isDesignException) {
159  $this->_design->loadChange(
160  $this->_scopeResolver->getScope()->getId()
161  )->changeDesign(
162  $this->_getDesign()
163  );
164  }
165  }
166  }
_applyUserAgentDesignException($request)
Definition: Area.php:174

◆ load()

load (   $part = null)

Load area data

Parameters
string | null$part
Returns
$this

Implements AreaInterface.

Definition at line 138 of file Area.php.

139  {
140  if ($part === null) {
141  $this->_loadPart(self::PART_CONFIG)->_loadPart(self::PART_DESIGN)->_loadPart(self::PART_TRANSLATE);
142  } else {
143  $this->_loadPart($part);
144  }
145  return $this;
146  }

Field Documentation

◆ $_code

$_code
protected

Definition at line 49 of file Area.php.

◆ $_design

$_design
protected

Definition at line 87 of file Area.php.

◆ $_designExceptions

$_designExceptions
protected

Definition at line 97 of file Area.php.

◆ $_diConfigLoader

$_diConfigLoader
protected

Definition at line 75 of file Area.php.

◆ $_eventManager

$_eventManager
protected

Definition at line 56 of file Area.php.

◆ $_loadedParts

$_loadedParts
protected

Definition at line 42 of file Area.php.

◆ $_logger

$_logger
protected

Definition at line 80 of file Area.php.

◆ $_objectManager

$_objectManager
protected

Definition at line 70 of file Area.php.

◆ $_scopeResolver

$_scopeResolver
protected

Definition at line 92 of file Area.php.

◆ $_translator

$_translator
protected

Definition at line 63 of file Area.php.

◆ AREA_ADMIN

const AREA_ADMIN = 'admin'
Deprecated:

Definition at line 30 of file Area.php.

◆ AREA_ADMINHTML

const AREA_ADMINHTML = 'adminhtml'

Definition at line 20 of file Area.php.

◆ AREA_CRONTAB

const AREA_CRONTAB = 'crontab'

Definition at line 22 of file Area.php.

◆ AREA_DOC

const AREA_DOC = 'doc'

Definition at line 21 of file Area.php.

◆ AREA_FRONTEND

const AREA_FRONTEND = 'frontend'

Definition at line 19 of file Area.php.

◆ AREA_GLOBAL

const AREA_GLOBAL = 'global'

Definition at line 18 of file Area.php.

◆ AREA_GRAPHQL

const AREA_GRAPHQL = 'graphql'

Definition at line 25 of file Area.php.

◆ AREA_WEBAPI_REST

const AREA_WEBAPI_REST = 'webapi_rest'

Definition at line 23 of file Area.php.

◆ AREA_WEBAPI_SOAP

const AREA_WEBAPI_SOAP = 'webapi_soap'

Definition at line 24 of file Area.php.

◆ PARAM_AREA

const PARAM_AREA = 'area'

Area parameter.

Definition at line 35 of file Area.php.


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