Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Context.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Framework\View;
7 
15 use Psr\Log\LoggerInterface as Logger;
20 
32 class Context
33 {
39  protected $request;
40 
46  protected $eventManager;
47 
52  protected $urlBuilder;
53 
59  protected $translator;
60 
66  protected $cache;
67 
73  protected $design;
74 
80  protected $session;
81 
87  protected $scopeConfig;
88 
94  protected $frontController;
95 
101  protected $layout;
102 
108  protected $viewConfig;
109 
115  protected $cacheState;
116 
122  protected $logger;
123 
129  protected $appState;
130 
153  public function __construct(
154  Request $request,
158  Cache $cache,
163  ViewConfig $viewConfig,
164  CacheState $cacheState,
165  Logger $logger,
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  }
184 
190  public function getCache()
191  {
192  return $this->cache;
193  }
194 
200  public function getDesignPackage()
201  {
202  return $this->design;
203  }
204 
210  public function getEventManager()
211  {
212  return $this->eventManager;
213  }
214 
220  public function getFrontController()
221  {
222  return $this->frontController;
223  }
224 
230  public function getLayout()
231  {
232  return $this->layout;
233  }
234 
240  public function getRequest()
241  {
242  return $this->request;
243  }
244 
250  public function getSession()
251  {
252  return $this->session;
253  }
254 
260  public function getScopeConfig()
261  {
262  return $this->scopeConfig;
263  }
264 
270  public function getTranslator()
271  {
272  return $this->translator;
273  }
274 
280  public function getUrlBuilder()
281  {
282  return $this->urlBuilder;
283  }
284 
290  public function getViewConfig()
291  {
292  return $this->viewConfig;
293  }
294 
300  public function getCacheState()
301  {
302  return $this->cacheState;
303  }
304 
310  public function getLogger()
311  {
312  return $this->logger;
313  }
314 
320  public function getArea()
321  {
322  return $this->appState->getAreaCode();
323  }
324 
330  public function getModuleName()
331  {
332  return $this->getRequest()->getModuleName();
333  }
334 
338  public function getFrontName()
339  {
340  return $this->getModuleName();
341  }
342 
348  public function getControllerName()
349  {
350  return $this->getRequest()->getControllerName();
351  }
352 
358  public function getActionName()
359  {
360  return $this->getRequest()->getActionName();
361  }
362 
368  public function getFullActionName()
369  {
370  return strtolower($this->getFrontName() . '_' . $this->getControllerName() . '_' . $this->getActionName());
371  }
372 
378  public function getAcceptType()
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  }
392 
400  public function getPost($key = null, $default = null)
401  {
402  return $this->getRequest()->getPost($key, $default);
403  }
404 
412  public function getQuery($key = null, $default = null)
413  {
414  return $this->getRequest()->getPost($key, $default);
415  }
416 
424  public function getParam($key = null, $default = null)
425  {
426  return $this->getRequest()->getParam($key, $default);
427  }
428 
434  public function getParams()
435  {
436  return $this->getRequest()->getParams();
437  }
438 
445  public function getHeader($header)
446  {
447  return $this->getRequest()->getHeader($header);
448  }
449 
455  public function getContent()
456  {
457  return $this->getRequest()->getContent();
458  }
459 
465  public function getAppState()
466  {
467  return $this->appState;
468  }
469 
477  protected function getPhysicalTheme(Design\ThemeInterface $theme)
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  }
488 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
getParam($key=null, $default=null)
Definition: Context.php:424
getPhysicalTheme(Design\ThemeInterface $theme)
Definition: Context.php:477
$type
Definition: item.phtml:13
__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)
Definition: Context.php:153
$theme
getQuery($key=null, $default=null)
Definition: Context.php:412
getPost($key=null, $default=null)
Definition: Context.php:400