Reverted some last changes + added FrameworkFileInputOutputPointer which allows readi...
[core.git] / inc / classes / main / io / input / class_FrameworkFileInputPointer.php
index b6b9cb3a17c62d375c13fdf9dbc28e77ab06f8ac..f70ef5a12b90596adb19bef552f6e50326c1ff95 100644 (file)
@@ -55,8 +55,8 @@ class FrameworkFileInputPointer extends BaseFileIo {
                }
 
                // Try to open a handler
-               $fileInstance = fopen($fileName, 'rb');
-               if ((is_null($fileInstance)) || ($fileInstance === FALSE)) {
+               $filePointer = fopen($fileName, 'rb');
+               if ((is_null($filePointer)) || ($filePointer === FALSE)) {
                        // Something bad happend
                        throw new FileIoException($fileName, self::EXCEPTION_FILE_POINTER_INVALID);
                } // END - if
@@ -65,7 +65,7 @@ class FrameworkFileInputPointer extends BaseFileIo {
                $pointerInstance = new FrameworkFileInputPointer();
 
                // Set file pointer and file name
-               $pointerInstance->setInstance($fileInstance);
+               $pointerInstance->setPointer($filePointer);
                $pointerInstance->setFileName($fileName);
 
                // Return the instance
@@ -78,15 +78,19 @@ class FrameworkFileInputPointer extends BaseFileIo {
         * @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
         */
        public function readFromFile () {
-               if (!$this->getInstance() instanceof SplFileObject) {
+               if (is_null($this->getPointer())) {
                        // Pointer not initialized
                        throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
+               } elseif (!is_resource($this->getPointer())) {
+                       // Pointer is not a valid resource!
+                       throw new InvalidResourceException($this, self::EXCEPTION_INVALID_RESOURCE);
                }
 
                // Read data from the file pointer and return it
-               return fread($this->getInstance(), 1024);
+               return fread($this->getPointer(), 1024);
        }
 }