Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DesignExceptions.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Framework\View;
7 
10 
15 {
21  protected $scopeConfig;
22 
29 
35  protected $scopeType;
36 
40  private $serializer;
41 
50  public function __construct(
53  $scopeType,
54  Json $serializer = null
55  ) {
56  $this->scopeConfig = $scopeConfig;
57  $this->exceptionConfigPath = $exceptionConfigPath;
58  $this->scopeType = $scopeType;
59  $this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class);
60  }
61 
68  public function getThemeByRequest(\Magento\Framework\App\Request\Http $request)
69  {
70  $userAgent = $request->getServer('HTTP_USER_AGENT');
71  if (empty($userAgent)) {
72  return false;
73  }
74  $expressions = $this->scopeConfig->getValue(
75  $this->exceptionConfigPath,
76  $this->scopeType
77  );
78  if (!$expressions) {
79  return false;
80  }
81  $expressions = $this->serializer->unserialize($expressions);
82  foreach ($expressions as $rule) {
83  if (preg_match($rule['regexp'], $userAgent)) {
84  return $rule['value'];
85  }
86  }
87  return false;
88  }
89 }
$expressions
Definition: side-menu.phtml:10
__construct(\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, $exceptionConfigPath, $scopeType, Json $serializer=null)
getThemeByRequest(\Magento\Framework\App\Request\Http $request)