Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Read.php
Go to the documentation of this file.
1 <?php
8 
11 
12 class Read implements ReadInterface
13 {
19  protected $path;
20 
26  protected $mode = 'r';
27 
33  protected $resource;
34 
38  protected $driver;
39 
47  {
48  $this->path = $path;
49 
50  $this->driver = $driver;
51 
52  $this->open();
53  }
54 
60  protected function open()
61  {
62  $this->assertValid();
63  $this->resource = $this->driver->fileOpen($this->path, $this->mode);
64  return $this;
65  }
66 
73  protected function assertValid()
74  {
75  if (!$this->driver->isExists($this->path)) {
76  throw new FileSystemException(
77  new \Magento\Framework\Phrase('The "%1" file doesn\'t exist.', [$this->path])
78  );
79  }
80  return true;
81  }
82 
89  public function read($length)
90  {
91  return $this->driver->fileRead($this->resource, $length);
92  }
93 
101  public function readAll($flag = null, $context = null)
102  {
103  return $this->driver->fileGetContents($this->path, $flag, $context);
104  }
105 
113  public function readLine($length, $ending = null)
114  {
115  return $this->driver->fileReadLine($this->resource, $length, $ending);
116  }
117 
127  public function readCsv($length = 0, $delimiter = ',', $enclosure = '"', $escape = '\\')
128  {
129  return $this->driver->fileGetCsv($this->resource, $length, $delimiter, $enclosure, $escape);
130  }
131 
137  public function tell()
138  {
139  return $this->driver->fileTell($this->resource);
140  }
141 
149  public function seek($offset, $whence = SEEK_SET)
150  {
151  return $this->driver->fileSeek($this->resource, $offset, $whence);
152  }
153 
159  public function eof()
160  {
161  return $this->driver->endOfFile($this->resource);
162  }
163 
169  public function close()
170  {
171  return $this->driver->fileClose($this->resource);
172  }
173 
179  public function stat()
180  {
181  return $this->driver->stat($this->path);
182  }
183 }
seek($offset, $whence=SEEK_SET)
Definition: Read.php:149
readCsv($length=0, $delimiter=',', $enclosure='"', $escape = '\\')
Definition: Read.php:127
readAll($flag=null, $context=null)
Definition: Read.php:101
readLine($length, $ending=null)
Definition: Read.php:113
__construct($path, DriverInterface $driver)
Definition: Read.php:46