Introduced FileNotFoundException
authorRoland Haeder <roland@mxchange.org>
Tue, 26 May 2015 21:51:59 +0000 (23:51 +0200)
committerRoland Haeder <roland@mxchange.org>
Tue, 26 May 2015 21:51:59 +0000 (23:51 +0200)
Signed-off-by: Roland Häder <roland@mxchange.org>
inc/classes/exceptions/file_directory/class_FileIoException.php
inc/classes/exceptions/file_directory/class_FileNotFoundException.php [new file with mode: 0644]
inc/classes/main/class_BaseFrameworkSystem.php
inc/classes/main/console/class_ConsoleTools.php
inc/classes/main/database/backend/class_CachedLocalFileDatabase.php
inc/classes/main/file_directories/input/raw/class_FrameworkRawFileInputPointer.php
inc/classes/main/file_directories/io_stream/class_FileIoStream.php
inc/classes/main/menu/class_BaseMenu.php
inc/classes/main/template/class_BaseTemplateEngine.php
index.php

index 9dea76f..85744cb 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 /**
- * An exception thrown when a file pointer is not opened
+ * An exception thrown when a file pointer is not opened or when the file
+ * cannot be reached.
  *
  * @author             Roland Haeder <webmaster@shipsimu.org>
  * @version            0.0.0
diff --git a/inc/classes/exceptions/file_directory/class_FileNotFoundException.php b/inc/classes/exceptions/file_directory/class_FileNotFoundException.php
new file mode 100644 (file)
index 0000000..3117bfa
--- /dev/null
@@ -0,0 +1,42 @@
+<?php
+/**
+ * An exception thrown when a file was not found (but could be found).
+ *
+ * @author             Roland Haeder <webmaster@shipsimu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Core Developer Team
+ * @license            GNU GPL 3.0 or any newer version
+ * @link               http://www.shipsimu.org
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class FileNotFoundException extends FrameworkException {
+       /**
+        * The constructor
+        *
+        * @param       $fqfn   Full-qualified file name of (maybe) missing file
+        * @param       $code   Code number for the exception
+        * @return      void
+        */
+       public function __construct ($fqfn, $code) {
+               // Add a message around the missing class
+               $message = sprintf('File %s not found.', $fqfn);
+
+               // Call parent constructor
+               parent::__construct($message, $code);
+       }
+}
+
+// [EOF]
+?>
index 3ea5bcf..85aeda6 100644 (file)
@@ -3274,7 +3274,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                $isReadable = FALSE;
 
                // Is within parameters, so check if it is a file and readable
-               $isReadable = ((self::isReachableFilePath($fileName)) && (is_file($fileName)) && (is_readable($fileName)));
+               $isReadable = ((self::isReachableFilePath($fileName)) && (file_exists($fileName)) && (is_file($fileName)) && (is_readable($fileName)));
 
                // Return status
                return $isReadable;
index 0d26941..7b690ef 100644 (file)
@@ -220,7 +220,7 @@ class ConsoleTools extends BaseFrameworkSystem {
 
                        // Resolve the IP number
                        $ip = $helperInstance->resolveIpAddress($hostname);
-               } catch (FileIoException $e) {
+               } catch (FileNotFoundException $e) {
                        // Fall-back to 'SESSION_SVR' which found on my Sun Station
                        if (isset($_SERVER['SESSION_SVR'])) {
                                // Resolve it
index a81dd3c..935cf27 100644 (file)
@@ -228,7 +228,7 @@ class CachedLocalFileDatabase extends BaseDatabaseBackend implements DatabaseBac
                // Get the file contents
                try {
                        $infoArray = $this->getDataArrayFromFile($fqfn);
-               } catch (FileIoException $e) {
+               } catch (FileNotFoundException $e) {
                        // Not found, so ignore it here
                }
 
@@ -279,9 +279,6 @@ class CachedLocalFileDatabase extends BaseDatabaseBackend implements DatabaseBac
         * @return      void
         */
        private function updateTableInfoFile (StoreableCriteria $dataSetInstance) {
-               // "Cache" table name
-               $tableName = $dataSetInstance->getTableName();
-
                // Create FQFN for creating the table information file
                $fqfn = $this->generateFqfnFromDataSet($dataSetInstance, 'info');
 
@@ -290,7 +287,7 @@ class CachedLocalFileDatabase extends BaseDatabaseBackend implements DatabaseBac
                $this->tableInfo[$tableName]['last_updated'] = time();
 
                // Write the data to the file
-               $this->writeDataArrayToFqfn($fqfn, $this->tableInfo[$tableName]);
+               $this->writeDataArrayToFqfn($fqfn, $this->tableInfo[$dataSetInstance->getTableName()]);
        }
 
        /**
index a3b3702..9fb6e1d 100644 (file)
@@ -40,6 +40,7 @@ class FrameworkRawFileInputPointer extends BaseFileIo implements InputPointer {
         * @throws      FileIsEmptyException            If the provided file name is empty.
         * @throws      FileIoException                         If the file is not reachable
         * @throws      FileReadProtectedException      If the file is not found or cannot be read
+        * @throws      FileNotFoundException           If the file does not exist
         * @return      void
         */
        public static final function createFrameworkRawFileInputPointer ($fileName) {
@@ -48,11 +49,14 @@ class FrameworkRawFileInputPointer extends BaseFileIo implements InputPointer {
                        // No filename given
                        throw new FileIsEmptyException(NULL, self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
                } elseif (!BaseFrameworkSystem::isReachableFilePath($fileName)) {
-                       // File does not exist!
+                       // File cannot be accessed (due to open_basedir restriction)
                        throw new FileIoException($fileName, self::EXCEPTION_FILE_NOT_REACHABLE);
-               } elseif (!BaseFrameworkSystem::isReadableFile($fileName)) {
-                       // File does not exist!
+               } elseif ((!BaseFrameworkSystem::isReadableFile($fileName)) && (file_exists($fileName))) {
+                       // File exists but cannot be read from
                        throw new FileReadProtectedException($fileName, self::EXCEPTION_FILE_CANNOT_BE_READ);
+               } elseif ((!BaseFrameworkSystem::isReadableFile($fileName)) && (!file_exists($fileName))) {
+                       // File does not exist
+                       throw new FileNotFoundException($fileName, self::EXCEPTION_FILE_NOT_FOUND);
                }
 
                // Try to open a handler
index f51884f..d0ff549 100644 (file)
@@ -82,7 +82,7 @@ class FileIoStream extends BaseFrameworkSystem implements FileInputStreamer, Fil
                        // Get a file output pointer
                        try {
                                $fileInstance = ObjectFactory::createObjectByConfiguredName('file_raw_output_class', array($fileName, 'wb'));
-                       } catch (FileIoException $e) {
+                       } catch (FileNotFoundException $e) {
                                // Bail out
                                ApplicationEntryPoint::app_exit('The application has made a fatal error. Exception: ' . $e->__toString() . ' with message: ' . $e->getMessage());
                        }
index 3e37de7..7bb97e1 100644 (file)
@@ -61,7 +61,7 @@ class BaseMenu extends BaseFrameworkSystem {
                // Load the menu template for this page
                try {
                        $templateInstance->loadMenuTemplate($command . '_menu_entries');
-               } catch (FileIoException $e) {
+               } catch (FileNotFoundException $e) {
                        // Log exception @TODO Maybe to intrusive?
                        self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: Exception caught: ' . $e->__toString() . ', with message: ' . $e->getMessage());
                }
index a447eb5..68511ad 100644 (file)
@@ -702,7 +702,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
                try {
                        // Load the raw template data
                        $this->loadRawTemplateData($fqfn);
-               } catch (FileIoException $e) {
+               } catch (FileNotFoundException $e) {
                        // If we shall load a code-template we need to switch the file extension
                        if (($this->getTemplateType() != $this->getConfigInstance()->getConfigEntry('html_template_type')) && (empty($extOther))) {
                                // Switch over to the code-template extension and try it again
@@ -846,7 +846,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
                                                // Remember this template for recursion detection
                                                // RECURSIVE PROTECTION!
                                                array_push($this->loadedTemplates, $template);
-                                       } catch (FileIoException $e) {
+                                       } catch (FileNotFoundException $e) {
                                                // Even this is not done... :/
                                                array_push($this->rawTemplates, $template);
                                        }
@@ -945,7 +945,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
                                        // Remember this template for recursion detection
                                        // RECURSIVE PROTECTION!
                                        array_push($this->loadedTemplates, $template);
-                               } catch (FileIoException $e) {
+                               } catch (FileNotFoundException $e) {
                                        // This template was never found. We silently ignore it
                                        unset($this->rawTemplates[$key]);
                                }
index 51eb50e..0a3ef74 100644 (file)
--- a/index.php
+++ b/index.php
@@ -150,7 +150,7 @@ final class ApplicationEntryPoint {
 
                                // Flush the response
                                $responseInstance->flushBuffer();
-                       } catch (FileIoException $e) {
+                       } catch (FileNotFoundException $e) {
                                // Even the template 'emergency_exit' wasn't found so output both message
                                exit($message . ', exception: ' . $e->getMessage());
                        }