<?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
--- /dev/null
+<?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]
+?>
$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;
// 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
// Get the file contents
try {
$infoArray = $this->getDataArrayFromFile($fqfn);
- } catch (FileIoException $e) {
+ } catch (FileNotFoundException $e) {
// Not found, so ignore it here
}
* @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');
$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()]);
}
/**
* @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) {
// 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
// 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());
}
// 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());
}
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
// 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);
}
// 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]);
}
// 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());
}