Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Filesystem.php
Go to the documentation of this file.
1 <?php
8 namespace Magento\Framework;
9 
11 
17 {
21  protected $directoryList;
22 
26  protected $readFactory;
27 
31  protected $writeFactory;
32 
36  protected $readInstances = [];
37 
41  protected $writeInstances = [];
42 
48  public function __construct(
50  \Magento\Framework\Filesystem\Directory\ReadFactory $readFactory,
51  \Magento\Framework\Filesystem\Directory\WriteFactory $writeFactory
52  ) {
53  $this->directoryList = $directoryList;
54  $this->readFactory = $readFactory;
55  $this->writeFactory = $writeFactory;
56  }
57 
65  public function getDirectoryRead($directoryCode, $driverCode = DriverPool::FILE)
66  {
67  $code = $directoryCode . '_' . $driverCode;
68  if (!array_key_exists($code, $this->readInstances)) {
69  $this->readInstances[$code] = $this->readFactory->create($this->getDirPath($directoryCode), $driverCode);
70  }
71  return $this->readInstances[$code];
72  }
73 
83  public function getDirectoryReadByPath($path, $driverCode = DriverPool::FILE)
84  {
85  return $this->readFactory->create($path, $driverCode);
86  }
87 
96  public function getDirectoryWrite($directoryCode, $driverCode = DriverPool::FILE)
97  {
98  $code = $directoryCode . '_' . $driverCode;
99  if (!array_key_exists($code, $this->writeInstances)) {
100  $this->writeInstances[$code] = $this->writeFactory->create($this->getDirPath($directoryCode), $driverCode);
101  }
102  return $this->writeInstances[$code];
103  }
104 
111  protected function getDirPath($code)
112  {
113  return $this->directoryList->getPath($code);
114  }
115 
122  public function getUri($code)
123  {
124  return $this->directoryList->getUrlPath($code);
125  }
126 }
getDirectoryReadByPath($path, $driverCode=DriverPool::FILE)
Definition: Filesystem.php:83
getDirectoryWrite($directoryCode, $driverCode=DriverPool::FILE)
Definition: Filesystem.php:96
getDirectoryRead($directoryCode, $driverCode=DriverPool::FILE)
Definition: Filesystem.php:65
$code
Definition: info.phtml:12
__construct(\Magento\Framework\Filesystem\DirectoryList $directoryList, \Magento\Framework\Filesystem\Directory\ReadFactory $readFactory, \Magento\Framework\Filesystem\Directory\WriteFactory $writeFactory)
Definition: Filesystem.php:48