X-Git-Url: https://git.mxchange.org/?p=core.git;a=blobdiff_plain;f=framework%2Fmain%2Fclasses%2Ffile_directories%2Finput%2Fraw%2Fclass_FrameworkRawFileInputPointer.php;h=3de4dc7412bc1c4433f5c3615876d39165ce10d7;hp=1adbdb294fa31bac308053f87b8d2725a10c2653;hb=868c877607670760eb36e63ebeb1a04237907be9;hpb=c43b569f2b140f40ece9f6e5b9a3825cb76b6413 diff --git a/framework/main/classes/file_directories/input/raw/class_FrameworkRawFileInputPointer.php b/framework/main/classes/file_directories/input/raw/class_FrameworkRawFileInputPointer.php index 1adbdb29..3de4dc74 100644 --- a/framework/main/classes/file_directories/input/raw/class_FrameworkRawFileInputPointer.php +++ b/framework/main/classes/file_directories/input/raw/class_FrameworkRawFileInputPointer.php @@ -1,15 +1,19 @@ isFile())) { // File does not exist - throw new FileNotFoundException($fileName, self::EXCEPTION_FILE_NOT_FOUND); + throw new FileNotFoundException($infoInstance, self::EXCEPTION_FILE_NOT_FOUND); + } elseif ((!FrameworkBootstrap::isReadableFile($infoInstance)) && ($infoInstance->isFile())) { + // File exists but cannot be read from + throw new FileReadProtectedException($infoInstance, self::EXCEPTION_FILE_CANNOT_BE_READ); } // Try to open a handler - $filePointer = fopen($fileName, 'rb'); - if ((is_null($filePointer)) || ($filePointer === false)) { + $fileObject = $infoInstance->openFile('rb'); + if ((is_null($fileObject)) || ($fileObject === false)) { // Something bad happend - throw new FileIoException($fileName, self::EXCEPTION_FILE_POINTER_INVALID); + throw new FileIoException($infoInstance, self::EXCEPTION_FILE_POINTER_INVALID); } // END - if // Create new instance $pointerInstance = new FrameworkRawFileInputPointer(); // Set file pointer and file name - $pointerInstance->setPointer($filePointer); - $pointerInstance->setFileName($fileName); + $pointerInstance->setFileObject($fileObject); // Return the instance return $pointerInstance; @@ -93,17 +92,16 @@ class FrameworkRawFileInputPointer extends BaseFileIo implements InputPointer { * Read data a file pointer * * @return mixed The result of fread() - * @throws NullPointerException If the file pointer instance - * is not set by setPointer() - * @throws InvalidResourceException If there is being set + * @throws NullPointerException If the file pointer instance is not set by setFileObject() + * @throws LogicException If there is no object being set */ public function readFromFile () { - if (is_null($this->getPointer())) { + if (is_null($this->getFileObject())) { // Pointer not initialized throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); - } elseif (!is_resource($this->getPointer())) { + } elseif (!is_object($this->getFileObject())) { // Pointer is not a valid resource! - throw new InvalidResourceException($this, self::EXCEPTION_INVALID_RESOURCE); + throw new LogicException(sprintf('this->fileObject[]=%s is no object', gettype($this->getFileObject()))); } // Read data from the file pointer and return it @@ -132,7 +130,7 @@ class FrameworkRawFileInputPointer extends BaseFileIo implements InputPointer { assert(is_int($bytes)); // Try to read given characters - $data = fread($this->getPointer(), $bytes); + $data = $this->getFileObject()->fread($bytes); // Then return it return $data;