X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=inc%2Fclasses%2Fmain%2Fdatabase%2Fclasses%2Fclass_LocalFileDatabase.php;h=dbe55ac36d4690125e36dfa9f74569cfaca4ccf9;hb=838cbd34450e0b29c5b749d86a526871dac461ac;hp=ff5f1dde0448456a437cb528aee8e4c3759f5ddd;hpb=ff66822b5fb6a92f5dc8af55290ecb89ec7f1aaf;p=shipsimu.git diff --git a/inc/classes/main/database/classes/class_LocalFileDatabase.php b/inc/classes/main/database/classes/class_LocalFileDatabase.php index ff5f1dd..dbe55ac 100644 --- a/inc/classes/main/database/classes/class_LocalFileDatabase.php +++ b/inc/classes/main/database/classes/class_LocalFileDatabase.php @@ -4,11 +4,11 @@ * * This class serializes objects and saves them to local files. * - * - * @author Roland Haeder - * @version 0.1 + * @author Roland Haeder + * @version 0.0.0 * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.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 @@ -21,7 +21,7 @@ * 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 . + * along with this program. If not, see . */ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontendInterface { /** @@ -34,11 +34,6 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend */ private $fileExtension = "serialized"; - /** - * The IO handler for file handling which should be FileIOHandler. - */ - private $ioInstance = null; - /** * The last read file's name */ @@ -55,12 +50,12 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend * * @return void */ - private function __construct() { + protected function __construct() { // Call parent constructor - parent::constructor(__CLASS__); + parent::__construct(__CLASS__); // Set description - $this->setPartDescr("Dateidatenbankschicht"); + $this->setObjectDescription("Class for local file databases"); // Create unique ID $this->createUniqueID(); @@ -75,7 +70,7 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend * * @param $savePath The local file path string * @param $ioInstance The input/output handler. This - * should be FileIOHandler + * should be FileIoHandler * @return $dbInstance An instance of LocalFileDatabase * @throws SavePathIsEmptyException If the given save path is an * empty string @@ -86,7 +81,7 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend * @throws SavePathWriteProtectedException If the save path is write- * protected */ - public final static function createLocalFileDatabase ($savePath, FileIOHandler $ioInstance) { + public final static function createLocalFileDatabase ($savePath, FileIoHandler $ioInstance) { // Get an instance $dbInstance = new LocalFileDatabase(); @@ -104,14 +99,9 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend throw new SavePathWriteProtectedException($savePath, self::EXCEPTION_WRITE_PROTECED_PATH); } - // Debug output - if (defined('DEBUG_DATABASE')) $dbInstance->getDebugInstance()->output(sprintf("[%s:] Es werden lokale Dateien zum Speichern von Objekten verwendet.
\n", - $dbInstance->__toString() - )); - // Set save path and IO instance $dbInstance->setSavePath($savePath); - $dbInstance->setIOInstance($ioInstance); + $dbInstance->setFileIoInstance($ioInstance); // Return database instance return $dbInstance; @@ -127,12 +117,6 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend // Secure string $savePath = (string) $savePath; - // Debug message - if ((defined('DEBUG_DATABASE')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:] Lokaler Speicherpfad %s wird verwendet.
\n", - $this->__toString(), - $savePath - )); - // Set save path $this->savePath = $savePath; } @@ -146,15 +130,6 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend return $this->savePath; } - /** - * Getter for file extension - * - * @return $fileExtension The file extension for all file names - */ - public final function getFileExtension () { - return $this->fileExtension; - } - /** * Saves a given object to the local file system by serializing and * transparently compressing it @@ -178,30 +153,17 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend throw new MissingMethodException(array($object, '__toString'), self::EXCEPTION_MISSING_METHOD); } - // Debug message - if ((defined('DEBUG_DATABASE')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:] Das Objekt %s soll in eine lokale Datei gespeichert werden.
\n", - $this->__toString(), - $object->__toString() - )); - // Get a string containing the serialized object. We cannot exchange // $this and $object here because $object does not need to worry // about it's limitations... ;-) $serialized = $this->serializeObject($object); - // Debug message - if ((defined('DEBUG_DATABASE')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:] Das Objekt %s ist nach der Serialisierung %s Byte gross.
\n", - $this->__toString(), - $object->__toString(), - strlen($serialized) - )); - // Get a path name plus file name and append the extension $fqfn = $this->getSavePath() . $object->getPathFileNameFromObject() . "." . $this->getFileExtension(); // Save the file to disc we don't care here if the path is there, // this must be done in later methods. - $this->getIOInstance()->saveFile($fqfn, array($this->getCompressorChannel()->getCompressorExtension(), $serialized)); + $this->getFileIoInstance()->saveFile($fqfn, array($this->getCompressorChannel()->getCompressorExtension(), $serialized)); } /** @@ -301,7 +263,7 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend $this->setLastFile($fqfn); // Get instance for file handler - $inputHandler = $this->getIOInstance(); + $inputHandler = $this->getFileIoInstance(); // Try to read from it. This makes it sure that the file is // readable and a valid database file @@ -324,34 +286,13 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend return $isUsed; } - /** - * Getter for the file IO instance - * - *�@return $ioInstance An instance for IO operations - * @see FileIOHandler The concrete handler for IO operations - */ - public final function getIOInstance () { - return $this->ioInstance; - } - - /** - * Setter for the file IO instance - * - * @param $ioInstance An instance for IO operations (should be - * FileIOHandler) - * @return void - */ - public final function setIOInstance (FileIOHandler $ioInstance) { - $this->ioInstance = $ioInstance; - } - /** * Setter for the last read file * * @param $fqfn The FQFN of the last read file * @return void */ - private function setLastFile ($fqfn) { + private final function setLastFile ($fqfn) { // Cast string $fqfn = (string) $fqfn; $this->lastFile = $fqfn; @@ -372,7 +313,7 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend * @param $contents An array with header and data elements * @return void */ - private function setLastFileContents ($contents) { + private final function setLastFileContents ($contents) { // Cast array $contents = (array) $contents; $this->lastContents = $contents; @@ -387,6 +328,15 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend return $this->lastContents; } + /** + * Getter for file extension + * + * @return $fileExtension The array with elements 'header' and 'data'. + */ + public final function getFileExtension () { + return $this->fileExtension; + } + /** * Get cached (last fetched) data from the local file database * @@ -404,9 +354,9 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend * @throws MissingMethodException If the required method * toString() is missing */ - public function getObjectFromCachedData ($uniqueID) { + public final function getObjectFromCachedData ($uniqueID) { // Get instance for file handler - $inputHandler = $this->getIOInstance(); + $inputHandler = $this->getFileIoInstance(); // Get last file's name and contents $fqfn = $this->repairFQFN($this->getLastFile(), $uniqueID);