Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Context Class Reference

Public Member Functions

 __construct (Request $request, ManagerInterface $eventManager, UrlInterface $urlBuilder, TranslateInterface $translator, Cache $cache, DesignInterface $design, SessionManager $session, ScopeConfigInterface $scopeConfig, FrontControllerInterface $frontController, ViewConfig $viewConfig, CacheState $cacheState, Logger $logger, AppState $appState, LayoutInterface $layout)
 
 getCache ()
 
 getDesignPackage ()
 
 getEventManager ()
 
 getFrontController ()
 
 getLayout ()
 
 getRequest ()
 
 getSession ()
 
 getScopeConfig ()
 
 getTranslator ()
 
 getUrlBuilder ()
 
 getViewConfig ()
 
 getCacheState ()
 
 getLogger ()
 
 getArea ()
 
 getModuleName ()
 
 getFrontName ()
 
 getControllerName ()
 
 getActionName ()
 
 getFullActionName ()
 
 getAcceptType ()
 
 getPost ($key=null, $default=null)
 
 getQuery ($key=null, $default=null)
 
 getParam ($key=null, $default=null)
 
 getParams ()
 
 getHeader ($header)
 
 getContent ()
 
 getAppState ()
 

Protected Member Functions

 getPhysicalTheme (Design\ThemeInterface $theme)
 

Protected Attributes

 $request
 
 $eventManager
 
 $urlBuilder
 
 $translator
 
 $cache
 
 $design
 
 $session
 
 $scopeConfig
 
 $frontController
 
 $layout
 
 $viewConfig
 
 $cacheState
 
 $logger
 
 $appState
 

Detailed Description

Application Runtime Context

Todo:

Reduce fields number

Reduce class dependencies

@SuppressWarnings(PHPMD.TooManyFields) @SuppressWarnings(PHPMD.CouplingBetweenObjects) @api

Since
100.0.2

Definition at line 32 of file Context.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( Request  $request,
ManagerInterface  $eventManager,
UrlInterface  $urlBuilder,
TranslateInterface  $translator,
Cache  $cache,
DesignInterface  $design,
SessionManager  $session,
ScopeConfigInterface  $scopeConfig,
FrontControllerInterface  $frontController,
ViewConfig  $viewConfig,
CacheState  $cacheState,
Logger  $logger,
AppState  $appState,
LayoutInterface  $layout 
)

Constructor

Parameters
Request$request
ManagerInterface$eventManager
UrlInterface$urlBuilder
TranslateInterface$translator
Cache$cache
DesignInterface$design
SessionManager$session
ScopeConfigInterface$scopeConfig
FrontControllerInterface$frontController
ViewConfig$viewConfig
CacheState$cacheState
Logger$logger
AppState$appState
LayoutInterface$layout
Todo:
reduce parameter number

@SuppressWarnings(PHPMD.ExcessiveParameterList)

Definition at line 153 of file Context.php.

168  {
169  $this->request = $request;
170  $this->eventManager = $eventManager;
171  $this->urlBuilder = $urlBuilder;
172  $this->translator = $translator;
173  $this->cache = $cache;
174  $this->design = $design;
175  $this->session = $session;
176  $this->scopeConfig = $scopeConfig;
177  $this->frontController = $frontController;
178  $this->viewConfig = $viewConfig;
179  $this->cacheState = $cacheState;
180  $this->logger = $logger;
181  $this->appState = $appState;
182  $this->layout = $layout;
183  }

Member Function Documentation

◆ getAcceptType()

getAcceptType ( )

Retrieve acceptance type

Returns
string

Definition at line 378 of file Context.php.

379  {
380  // TODO: do intelligence here
381  $type = $this->getHeader('Accept', 'html');
382  if (strpos($type, 'json') !== false) {
383  return 'json';
384  } elseif (strpos($type, 'soap') !== false) {
385  return 'soap';
386  } elseif (strpos($type, 'text/html') !== false) {
387  return 'html';
388  } else {
389  return 'xml';
390  }
391  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$type
Definition: item.phtml:13

◆ getActionName()

getActionName ( )

Retrieve the action name

Returns
string

Definition at line 358 of file Context.php.

359  {
360  return $this->getRequest()->getActionName();
361  }

◆ getAppState()

getAppState ( )

Retrieve application state

Returns
\Magento\Framework\App\State

Definition at line 465 of file Context.php.

466  {
467  return $this->appState;
468  }

◆ getArea()

getArea ( )

Retrieve layout area

Returns
string

Definition at line 320 of file Context.php.

321  {
322  return $this->appState->getAreaCode();
323  }

◆ getCache()

getCache ( )

Retrieve cache

Returns
\Magento\Framework\App\CacheInterface

Definition at line 190 of file Context.php.

191  {
192  return $this->cache;
193  }

◆ getCacheState()

getCacheState ( )

Retrieve cache state

Returns
\Magento\Framework\App\Cache\StateInterface

Definition at line 300 of file Context.php.

301  {
302  return $this->cacheState;
303  }

◆ getContent()

getContent ( )

Return the raw body of the request, if present

Returns
string|false Raw body, or false if not present

Definition at line 455 of file Context.php.

456  {
457  return $this->getRequest()->getContent();
458  }

◆ getControllerName()

getControllerName ( )

Retrieve the controller name

Returns
string

Definition at line 348 of file Context.php.

349  {
350  return $this->getRequest()->getControllerName();
351  }

◆ getDesignPackage()

getDesignPackage ( )

Retrieve design package

Returns
\Magento\Framework\View\DesignInterface

Definition at line 200 of file Context.php.

201  {
202  return $this->design;
203  }

◆ getEventManager()

getEventManager ( )

Retrieve event manager

Returns
ManagerInterface

Definition at line 210 of file Context.php.

211  {
212  return $this->eventManager;
213  }

◆ getFrontController()

getFrontController ( )

Retrieve front controller

Returns
FrontControllerInterface

Definition at line 220 of file Context.php.

221  {
222  return $this->frontController;
223  }

◆ getFrontName()

getFrontName ( )
See also
getModuleName

Definition at line 338 of file Context.php.

339  {
340  return $this->getModuleName();
341  }

◆ getFullActionName()

getFullActionName ( )

Retrieve the full action name

Returns
string

Definition at line 368 of file Context.php.

369  {
370  return strtolower($this->getFrontName() . '_' . $this->getControllerName() . '_' . $this->getActionName());
371  }

◆ getHeader()

getHeader (   $header)

Return the value of the given HTTP header.

Parameters
string$header
Returns
string|false HTTP header value, or false if not found

Definition at line 445 of file Context.php.

446  {
447  return $this->getRequest()->getHeader($header);
448  }

◆ getLayout()

getLayout ( )

Retrieve layout

Returns
\Magento\Framework\View\LayoutInterface

Definition at line 230 of file Context.php.

231  {
232  return $this->layout;
233  }

◆ getLogger()

getLogger ( )

Retrieve logger

Returns
\Psr\Log\LoggerInterface

Definition at line 310 of file Context.php.

311  {
312  return $this->logger;
313  }

◆ getModuleName()

getModuleName ( )

Retrieve the module name

Returns
string

Definition at line 330 of file Context.php.

331  {
332  return $this->getRequest()->getModuleName();
333  }

◆ getParam()

getParam (   $key = null,
  $default = null 
)

Retrieve a parameter

Parameters
string | null$key
mixed$defaultDefault value to use if key not found
Returns
mixed

Definition at line 424 of file Context.php.

425  {
426  return $this->getRequest()->getParam($key, $default);
427  }

◆ getParams()

getParams ( )

Retrieve an array of parameters

Returns
array

Definition at line 434 of file Context.php.

435  {
436  return $this->getRequest()->getParams();
437  }

◆ getPhysicalTheme()

getPhysicalTheme ( Design\ThemeInterface  $theme)
protected

Retrieve parent theme instance

Parameters
Design\ThemeInterface$theme
Returns
Design\ThemeInterface
Exceptions

Definition at line 477 of file Context.php.

478  {
479  $result = $theme;
480  while ($result->getId() && !$result->isPhysical()) {
481  $result = $result->getParentTheme();
482  }
483  if (!$result) {
484  throw new \Exception("Unable to find a physical ancestor for a theme '{$theme->getThemeTitle()}'.");
485  }
486  return $result;
487  }
$theme

◆ getPost()

getPost (   $key = null,
  $default = null 
)

Retrieve a member of the $_POST superglobal

Parameters
string$key
mixed$defaultDefault value to use if key not found
Returns
mixed|null if key does not exist

Definition at line 400 of file Context.php.

401  {
402  return $this->getRequest()->getPost($key, $default);
403  }

◆ getQuery()

getQuery (   $key = null,
  $default = null 
)

Retrieve a member of the $_POST superglobal

Parameters
string | null$key
mixed$defaultDefault value to use if key not found
Returns
mixed alias of getPost

Definition at line 412 of file Context.php.

413  {
414  return $this->getRequest()->getPost($key, $default);
415  }

◆ getRequest()

getRequest ( )

Retrieve request

Returns
Request

Definition at line 240 of file Context.php.

241  {
242  return $this->request;
243  }

◆ getScopeConfig()

getScopeConfig ( )

Retrieve scope config

Returns
\Magento\Framework\App\Config\ScopeConfigInterface

Definition at line 260 of file Context.php.

261  {
262  return $this->scopeConfig;
263  }

◆ getSession()

getSession ( )

Retrieve session

Returns
\Magento\Framework\Session\SessionManagerInterface

Definition at line 250 of file Context.php.

251  {
252  return $this->session;
253  }

◆ getTranslator()

getTranslator ( )

Retrieve translator

Returns
\Magento\Framework\TranslateInterface

Definition at line 270 of file Context.php.

271  {
272  return $this->translator;
273  }

◆ getUrlBuilder()

getUrlBuilder ( )

Retrieve URL builder

Returns
\Magento\Framework\UrlInterface

Definition at line 280 of file Context.php.

281  {
282  return $this->urlBuilder;
283  }

◆ getViewConfig()

getViewConfig ( )

Retrieve view config

Returns
\Magento\Framework\View\ConfigInterface

Definition at line 290 of file Context.php.

291  {
292  return $this->viewConfig;
293  }

Field Documentation

◆ $appState

$appState
protected

Definition at line 129 of file Context.php.

◆ $cache

$cache
protected

Definition at line 66 of file Context.php.

◆ $cacheState

$cacheState
protected

Definition at line 115 of file Context.php.

◆ $design

$design
protected

Definition at line 73 of file Context.php.

◆ $eventManager

$eventManager
protected

Definition at line 46 of file Context.php.

◆ $frontController

$frontController
protected

Definition at line 94 of file Context.php.

◆ $layout

$layout
protected

Definition at line 101 of file Context.php.

◆ $logger

$logger
protected

Definition at line 122 of file Context.php.

◆ $request

$request
protected

Definition at line 39 of file Context.php.

◆ $scopeConfig

$scopeConfig
protected

Definition at line 87 of file Context.php.

◆ $session

$session
protected

Definition at line 80 of file Context.php.

◆ $translator

$translator
protected

Definition at line 59 of file Context.php.

◆ $urlBuilder

$urlBuilder
protected

Definition at line 52 of file Context.php.

◆ $viewConfig

$viewConfig
protected

Definition at line 108 of file Context.php.


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