Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
StatePlugin.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
14 use Psr\Log\LoggerInterface;
15 
20 {
24  private $config;
25 
29  private $newRelicWrapper;
30 
34  private $logger;
35 
41  public function __construct(
42  Config $config,
43  NewRelicWrapper $newRelicWrapper,
44  LoggerInterface $logger
45  ) {
46  $this->config = $config;
47  $this->newRelicWrapper = $newRelicWrapper;
48  $this->logger = $logger;
49  }
50 
58  public function afterSetAreaCode(State $subject, $result)
59  {
60  if (!$this->shouldSetAppName()) {
61  return $result;
62  }
63 
64  try {
65  $this->newRelicWrapper->setAppName($this->appName($subject));
66  } catch (LocalizedException $e) {
67  $this->logger->critical($e);
68  return $result;
69  }
70 
71  return $result;
72  }
73 
81  private function appName(State $state): string
82  {
83  $code = $state->getAreaCode();
84  $current = $this->config->getNewRelicAppName();
85 
86  return $current . ';' . $current . '_' . $code;
87  }
88 
94  private function shouldSetAppName(): bool
95  {
96  return (
97  $this->config->isSeparateApps() &&
98  $this->config->getNewRelicAppName() &&
99  $this->config->isNewRelicEnabled()
100  );
101  }
102 }
afterSetAreaCode(State $subject, $result)
Definition: StatePlugin.php:58
$config
Definition: fraud_order.php:17
$logger
__construct(Config $config, NewRelicWrapper $newRelicWrapper, LoggerInterface $logger)
Definition: StatePlugin.php:41
$code
Definition: info.phtml:12