PrimeraApi improved, some code cosmetics:
[core.git] / inc / classes / main / database / databases / class_LocalFileDatabase.php
index d4c45e972eaa9b04c03f8de6b5e3fcc190597c26..9e7e3f42b7effda605629a42ffd91684c5583db9 100644 (file)
@@ -6,7 +6,7 @@
  *
  * @author             Roland Haeder <webmaster@ship-simu.org>
  * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Core Developer Team
  * @license            GNU GPL 3.0 or any newer version
  * @link               http://www.ship-simu.org
  *
@@ -83,7 +83,7 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend
         *
         * @return      void
         */
-       protected function __construct() {
+       protected function __construct () {
                // Call parent constructor
                parent::__construct(__CLASS__);
        }
@@ -92,24 +92,27 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend
         * Create an object of LocalFileDatabase and set the save path for local files.
         * This method also validates the given file path.
         *
-        * @param               $savePath               The local file path string
-        * @param               $ioInstance             The input/output handler. This
-        *                                                              should be FileIoHandler
-        * @return      $dbInstance                     An instance of LocalFileDatabase
+        * @param       $savePath               The local file path string
+        * @return      $dbInstance             An instance of LocalFileDatabase
         */
-       public final static function createLocalFileDatabase ($savePath, FileIoHandler $ioInstance) {
+       public static final function createLocalFileDatabase ($savePath) {
                // Get an instance
-               $dbInstance = new LocalFileDatabase();
+               $databaseInstance = new LocalFileDatabase();
 
                // Set save path and IO instance
-               $dbInstance->setSavePath($savePath);
-               $dbInstance->setFileIoInstance($ioInstance);
+               $databaseInstance->setSavePath($savePath);
+
+               // Set the compressor channel
+               $databaseInstance->setCompressorChannel(CompressorChannel::createCompressorChannel(
+                       $databaseInstance->getConfigInstance()->getConfigEntry('base_path').
+                       $databaseInstance->getConfigInstance()->getConfigEntry('compressor_base_path')
+               ));
 
                // "Connect" to the database
-               $dbInstance->connectToDatabase();
+               $databaseInstance->connectToDatabase();
 
                // Return database instance
-               return $dbInstance;
+               return $databaseInstance;
        }
 
        /**
@@ -119,11 +122,8 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend
         * @return      void
         */
        public final function setSavePath ($savePath) {
-               // Secure string
-               $savePath = (string) $savePath;
-
                // Set save path
-               $this->savePath = $savePath;
+               $this->savePath = (string) $savePath;
        }
 
        /**
@@ -286,7 +286,7 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend
                // Get the file contents
                try {
                        $infoArray = $this->getDataArrayFromFile($fqfn);
-               } catch (FileNotFoundException $e) {
+               } catch (FileIoException $e) {
                        // Not found, so ignore it here
                }
 
@@ -495,7 +495,7 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend
                } catch (FrameworkException $e) {
                        // Catch all exceptions and store them in last error
                        $this->lastException = $e;
-                       $this->lastError = $e->getMessage();
+                       $this->lastError     = $e->getMessage();
 
                        // Throw an SQL exception
                        throw new SqlException (array($this, sprintf("Cannot write data to table &#39;%s&#39;", $tableName), self::DB_CODE_TABLE_UNWRITEABLE), self::EXCEPTION_SQL_QUERY);