Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Write.php
Go to the documentation of this file.
1 <?php
8 
11 
12 class Write extends Read implements WriteInterface
13 {
22  {
23  $this->mode = $mode;
24  parent::__construct($path, $driver);
25  }
26 
33  protected function assertValid()
34  {
35  $fileExists = $this->driver->isExists($this->path);
36  if (!$fileExists && preg_match('/r/', $this->mode)) {
37  throw new FileSystemException(
38  new \Magento\Framework\Phrase('The "%1" file doesn\'t exist.', [$this->path])
39  );
40  } elseif ($fileExists && preg_match('/x/', $this->mode)) {
41  throw new FileSystemException(new \Magento\Framework\Phrase('The file "%1" already exists', [$this->path]));
42  }
43  }
44 
52  public function write($data)
53  {
54  try {
55  return $this->driver->fileWrite($this->resource, $data);
56  } catch (FileSystemException $e) {
57  throw new FileSystemException(
58  new \Magento\Framework\Phrase('Cannot write to the "%1" file. %2', [$this->path, $e->getMessage()])
59  );
60  }
61  }
62 
72  public function writeCsv(array $data, $delimiter = ',', $enclosure = '"')
73  {
74  try {
75  return $this->driver->filePutCsv($this->resource, $data, $delimiter, $enclosure);
76  } catch (FileSystemException $e) {
77  throw new FileSystemException(
78  new \Magento\Framework\Phrase('Cannot write to the "%1" file. %2', [$this->path, $e->getMessage()])
79  );
80  }
81  }
82 
89  public function flush()
90  {
91  try {
92  return $this->driver->fileFlush($this->resource);
93  } catch (FileSystemException $e) {
94  throw new FileSystemException(
95  new \Magento\Framework\Phrase('Cannot flush the "%1" file. %2', [$this->path, $e->getMessage()])
96  );
97  }
98  }
99 
106  public function lock($lockMode = \LOCK_EX)
107  {
108  return $this->driver->fileLock($this->resource, $lockMode);
109  }
110 
116  public function unlock()
117  {
118  return $this->driver->fileUnlock($this->resource);
119  }
120 }
__construct($path, DriverInterface $driver, $mode)
Definition: Write.php:21
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
writeCsv(array $data, $delimiter=',', $enclosure='"')
Definition: Write.php:72