Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Reader.php
Go to the documentation of this file.
1 <?php
8 
15 
22 class Reader
23 {
27  private $dirList;
28 
32  private $configFilePool;
33 
37  private $driverPool;
38 
44  private $files;
45 
55  public function __construct(
56  DirectoryList $dirList,
57  DriverPool $driverPool,
58  ConfigFilePool $configFilePool,
59  $file = null
60  ) {
61  $this->dirList = $dirList;
62  $this->configFilePool = $configFilePool;
63  $this->driverPool = $driverPool;
64  if (null !== $file) {
65  if (!preg_match('/^[a-z\d\.\-]+\.php$/i', $file)) {
66  throw new \InvalidArgumentException("Invalid file name: {$file}");
67  }
68  $this->files = [$file];
69  } else {
70  $this->files = $this->configFilePool->getPaths();
71  }
72  }
73 
79  public function getFiles()
80  {
81  return $this->files;
82  }
83 
96  public function load($fileKey = null)
97  {
98  $path = $this->dirList->getPath(DirectoryList::CONFIG);
99  $fileDriver = $this->driverPool->getDriver(DriverPool::FILE);
100  $result = [];
101  if ($fileKey) {
102  $filePath = $path . '/' . $this->configFilePool->getPath($fileKey);
103  if ($fileDriver->isExists($filePath)) {
104  $result = include $filePath;
105  if (!is_array($result)) {
106  throw new RuntimeException(new Phrase("Invalid configuration file: '%1'", [$filePath]));
107  }
108  }
109  } else {
110  $configFiles = $this->configFilePool->getPaths();
111  $allFilesData = [];
112  $result = [];
113  foreach (array_keys($configFiles) as $fileKey) {
114  $configFile = $path . '/' . $this->configFilePool->getPath($fileKey);
115  if ($fileDriver->isExists($configFile)) {
116  $fileData = include $configFile;
117  if (!is_array($fileData)) {
118  throw new RuntimeException(new Phrase("Invalid configuration file: '%1'", [$configFile]));
119  }
120  } else {
121  continue;
122  }
123  $allFilesData[$configFile] = $fileData;
124  if ($fileData) {
125  $result = array_replace_recursive($result, $fileData);
126  }
127  }
128  }
129  return $result ?: [];
130  }
131 
142  public function loadConfigFile($fileKey, $pathConfig, $ignoreInitialConfigFiles = false)
143  {
144  return $this->load($fileKey);
145  }
146 }
if(!file_exists($installConfigFile)) $dirList
Definition: bootstrap.php:57
loadConfigFile($fileKey, $pathConfig, $ignoreInitialConfigFiles=false)
Definition: Reader.php:142
__construct(DirectoryList $dirList, DriverPool $driverPool, ConfigFilePool $configFilePool, $file=null)
Definition: Reader.php:55