Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ConcealInProduction.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
12 
20 {
39  private $configs = [];
40 
46  private $state;
47 
66  private $exemptions = [];
67 
73  public function __construct(State $state, array $configs = [], array $exemptions = [])
74  {
75  $this->state = $state;
76  $this->configs = $configs;
77  $this->exemptions = $exemptions;
78  }
79 
84  public function isHidden($path)
85  {
86  $path = $this->normalizePath($path);
87  if ($this->state->getMode() === State::MODE_PRODUCTION
88  && preg_match('/(?<group>(?<section>.*?)\/.*?)\/.*?/', $path, $match)) {
89  $group = $match['group'];
90  $section = $match['section'];
91  $exemptions = array_keys($this->exemptions);
92  $checkedItems = [];
93  foreach ([$path, $group, $section] as $itemPath) {
94  $checkedItems[] = $itemPath;
95  if (!empty($this->configs[$itemPath])) {
96  return $this->configs[$itemPath] === static::HIDDEN
97  && empty(array_intersect($checkedItems, $exemptions));
98  }
99  }
100  }
101 
102  return false;
103  }
104 
109  public function isDisabled($path)
110  {
111  $path = $this->normalizePath($path);
112  if ($this->state->getMode() === State::MODE_PRODUCTION) {
113  while (true) {
114  if (!empty($this->configs[$path])) {
115  return $this->configs[$path] === static::DISABLED;
116  }
117 
118  $position = strripos($path, '/');
119  if ($position === false) {
120  break;
121  }
122  $path = substr($path, 0, $position);
123  }
124  }
125 
126  return false;
127  }
128 
135  private function normalizePath($path)
136  {
137  return trim($path, '/');
138  }
139 }
$group
Definition: sections.phtml:16
__construct(State $state, array $configs=[], array $exemptions=[])