Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Config.php
Go to the documentation of this file.
1 <?php
7 
12 
13 class Config
14 {
20  protected $cacheFilePath;
21 
27  protected $config;
28 
34  protected $rootDirectory;
35 
41  public function __construct(
42  \Magento\MediaStorage\Model\File\Storage $storage,
43  \Magento\Framework\Filesystem $filesystem,
44  $cacheFile
45  ) {
46  $this->config = $storage->getScriptConfig();
47  $this->rootDirectory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
48  $this->cacheFilePath = $cacheFile;
49  }
50 
56  public function getMediaDirectory()
57  {
58  return $this->config['media_directory'];
59  }
60 
66  public function getAllowedResources()
67  {
68  return $this->config['allowed_resources'];
69  }
70 
76  public function save()
77  {
79  $file = $this->rootDirectory->openFile($this->rootDirectory->getRelativePath($this->cacheFilePath), 'w');
80  try {
81  $file->lock();
82  $file->write(json_encode($this->config));
83  $file->unlock();
84  $file->close();
85  } catch (FileSystemException $e) {
86  $file->close();
87  }
88  }
89 }
__construct(\Magento\MediaStorage\Model\File\Storage $storage, \Magento\Framework\Filesystem $filesystem, $cacheFile)
Definition: Config.php:41