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 9dea76f0789d9baec399a8e3e9d3c1990bf7eca8..85744cbcc2bf855bab640ba498aa3af965ac9778 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 3ea5bcf5d49cda30bbfa8d5f3ce1bd1096b90c13..85aeda63bfdf301cf09e5cf423314417ce47d7b4 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 0d269417f53539e02828be09dea0366416c9675a..7b690ef53ece33b4843a5b701336bce465381c2f 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 a81dd3cb3555143dcd3c367e7b5e6a0fbec8b3c3..935cf27fe1a53ea87c033e8bd3ec4a9f67508bfe 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 a3b3702004fbbabd44113024a3af059aba84050e..9fb6e1db819bb2a5398ec1197319308099788d97 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 f51884fd04f9a6244c736004e3b130ca3eb9eb98..d0ff549078ded20e66400723d7c6e58aaa1b0feb 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 3e37de7d232e19e6cc59f5997477694b0be4001d..7bb97e169a27674ddfb3f9d3c31dc4ac54d75cf3 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 a447eb578b58bbc842d3dc51b87e90e2e11a7fdf..68511ad143380df67820e706012fa5178d4a1edf 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 51eb50ef9341ef86cdff5c5f4a9b4023502e5024..0a3ef741158afd0be661a3d36b0c1b63d8e4c89b 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());
                        }