Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Attributes
Zend_Pdf_FileParserDataSource_File Class Reference
Inheritance diagram for Zend_Pdf_FileParserDataSource_File:
Zend_Pdf_FileParserDataSource

Public Member Functions

 __construct ($filePath)
 
 __destruct ()
 
 readBytes ($byteCount)
 
 readAllBytes ()
 
 __toString ()
 
 moveToOffset ($offset)
 
- Public Member Functions inherited from Zend_Pdf_FileParserDataSource
 __destruct ()
 
 readBytes ($byteCount)
 
 readAllBytes ()
 
 __toString ()
 
 getOffset ()
 
 getSize ()
 
 moveToOffset ($offset)
 
 skipBytes ($byteCount)
 

Protected Attributes

 $_filePath = ''
 
 $_fileResource = null
 
- Protected Attributes inherited from Zend_Pdf_FileParserDataSource
 $_size = 0
 
 $_offset = 0
 

Detailed Description

Definition at line 40 of file File.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $filePath)

Object constructor.

Validates the path to the file, ensures that it is readable, then opens it for reading.

Throws an exception if the file is missing or cannot be opened.

Parameters
string$filePathFully-qualified path to the file.
Exceptions
Zend_Pdf_Exception

Definition at line 75 of file File.php.

76  {
77  if (! (is_file($filePath) || is_link($filePath))) {
78  #require_once 'Zend/Pdf/Exception.php';
79  throw new Zend_Pdf_Exception("Invalid file path: $filePath",
81  }
82  if (! is_readable($filePath)) {
83  #require_once 'Zend/Pdf/Exception.php';
84  throw new Zend_Pdf_Exception("File is not readable: $filePath",
86  }
87  if (($this->_size = @filesize($filePath)) === false) {
88  #require_once 'Zend/Pdf/Exception.php';
89  throw new Zend_Pdf_Exception("Error while obtaining file size: $filePath",
91  }
92  if (($this->_fileResource = @fopen($filePath, 'rb')) === false) {
93  #require_once 'Zend/Pdf/Exception.php';
94  throw new Zend_Pdf_Exception("Cannot open file for reading: $filePath",
96  }
97  $this->_filePath = $filePath;
98  }
const CANT_GET_FILE_SIZE
Definition: Exception.php:157

◆ __destruct()

__destruct ( )

Object destructor.

Closes the file if it had been successfully opened.

Definition at line 105 of file File.php.

106  {
107  if (is_resource($this->_fileResource)) {
108  @fclose($this->_fileResource);
109  }
110  }

Member Function Documentation

◆ __toString()

__toString ( )

Returns the full filesystem path of the file.

Returns
string

Definition at line 162 of file File.php.

163  {
164  return $this->_filePath;
165  }

◆ moveToOffset()

moveToOffset (   $offset)

Seeks the file read position to the specified byte offset.

Throws an exception if the file pointer cannot be moved or if it is moved beyond EOF (end of file).

Parameters
integer$offsetDestination byte offset.
Exceptions
Zend_Pdf_Exception

Definition at line 179 of file File.php.

180  {
181  if ($this->_offset == $offset) {
182  return; // Not moving; do nothing.
183  }
184  parent::moveToOffset($offset);
185  $result = @fseek($this->_fileResource, $offset, SEEK_SET);
186  if ($result !== 0) {
187  #require_once 'Zend/Pdf/Exception.php';
188  throw new Zend_Pdf_Exception('Error while setting new file position',
190  }
191  if (feof($this->_fileResource)) {
192  #require_once 'Zend/Pdf/Exception.php';
193  throw new Zend_Pdf_Exception('Moved beyond the end of the file',
195  }
196  }
const CANT_SET_FILE_POSITION
Definition: Exception.php:140
const MOVE_BEYOND_END_OF_FILE
Definition: Exception.php:152

◆ readAllBytes()

readAllBytes ( )

Returns the entire contents of the file as a string.

Preserves the current file seek position.

Returns
string

Definition at line 149 of file File.php.

150  {
151  return file_get_contents($this->_filePath);
152  }

◆ readBytes()

readBytes (   $byteCount)

Returns the specified number of raw bytes from the file at the byte offset of the current read position.

Advances the read position by the number of bytes read.

Throws an exception if an error was encountered while reading the file or if there is insufficient data to completely fulfill the request.

Parameters
integer$byteCountNumber of bytes to read.
Returns
string
Exceptions
Zend_Pdf_Exception

Definition at line 125 of file File.php.

126  {
127  $bytes = @fread($this->_fileResource, $byteCount);
128  if ($bytes === false) {
129  #require_once 'Zend/Pdf/Exception.php';
130  throw new Zend_Pdf_Exception('Unexpected error while reading file',
132  }
133  if (strlen($bytes) != $byteCount) {
134  #require_once 'Zend/Pdf/Exception.php';
135  throw new Zend_Pdf_Exception("Insufficient data to read $byteCount bytes",
137  }
138  $this->_offset += $byteCount;
139  return $bytes;
140  }

Field Documentation

◆ $_filePath

$_filePath = ''
protected

Definition at line 49 of file File.php.

◆ $_fileResource

$_fileResource = null
protected

Definition at line 55 of file File.php.


The documentation for this class was generated from the following file: