Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DeploymentConfig.php
Go to the documentation of this file.
1 <?php
7 namespace Magento\Framework\App;
8 
10 
18 {
24  private $reader;
25 
31  private $data;
32 
38  private $flatData;
39 
45  private $overrideData;
46 
55  public function __construct(DeploymentConfig\Reader $reader, $overrideData = [])
56  {
57  $this->reader = $reader;
58  $this->overrideData = $overrideData;
59  }
60 
68  public function get($key = null, $defaultValue = null)
69  {
70  $this->load();
71  if ($key === null) {
72  return $this->flatData;
73  }
74  return $this->flatData[$key] ?? $defaultValue;
75  }
76 
82  public function isAvailable()
83  {
84  $this->data = null;
85  $this->load();
86  return isset($this->flatData[ConfigOptionsListConstants::CONFIG_PATH_INSTALL_DATE]);
87  }
88 
95  public function getConfigData($key = null)
96  {
97  $this->load();
98 
99  if ($key !== null && !isset($this->data[$key])) {
100  return null;
101  }
102 
103  if (isset($this->data[$key])) {
104  return $this->data[$key];
105  }
106 
107  return $this->data;
108  }
109 
115  public function resetData()
116  {
117  $this->data = null;
118  }
119 
126  public function isDbAvailable()
127  {
128  $this->load();
129  return isset($this->data['db']);
130  }
131 
137  private function load()
138  {
139  if (null === $this->data) {
140  $this->data = $this->reader->load();
141  if ($this->overrideData) {
142  $this->data = array_replace($this->data, $this->overrideData);
143  }
144  // flatten data for config retrieval using get()
145  $this->flatData = $this->flattenParams($this->data);
146  }
147  }
148 
158  private function flattenParams(array $params, $path = null)
159  {
160  $cache = [];
161 
162  foreach ($params as $key => $param) {
163  if ($path) {
164  $newPath = $path . '/' . $key;
165  } else {
166  $newPath = $key;
167  }
168  if (isset($cache[$newPath])) {
169  throw new \Exception("Key collision {$newPath} is already defined.");
170  }
171  $cache[$newPath] = $param;
172  if (is_array($param)) {
173  $cache = array_merge($cache, $this->flattenParams($param, $newPath));
174  }
175  }
176 
177  return $cache;
178  }
179 }
__construct(DeploymentConfig\Reader $reader, $overrideData=[])
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18