]> git.mxchange.org Git - core.git/blobdiff - framework/main/classes/database/backend/lfdb_legacy/class_CachedLocalFileDatabase.php
Continued:
[core.git] / framework / main / classes / database / backend / lfdb_legacy / class_CachedLocalFileDatabase.php
index 91aa9ac5548ea150a320228266ffd7fa7817b4b8..7ba7a968b31ddeed72f742697abf7ad053ea390d 100644 (file)
@@ -13,6 +13,7 @@ use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
 use Org\Mxchange\CoreFramework\Filesystem\FileNotFoundException;
 use Org\Mxchange\CoreFramework\Generic\FrameworkException;
 use Org\Mxchange\CoreFramework\Handler\Stream\IoHandler;
+use Org\Mxchange\CoreFramework\Middleware\Compressor\CompressorChannel;
 
 // Import SPL stuff
 use \SplFileInfo;
@@ -81,6 +82,11 @@ class CachedLocalFileDatabase extends BaseDatabaseBackend implements DatabaseBac
         */
        private $fileIoInstance = NULL;
 
+       /**
+        * A Compressor instance
+        */
+       private $compressorChannelInstance = NULL;
+
        /**
         * The protected constructor. Do never instance from outside! You need to
         * set a local file path. The class will then validate it.
@@ -103,10 +109,10 @@ class CachedLocalFileDatabase extends BaseDatabaseBackend implements DatabaseBac
                $databaseInstance = new CachedLocalFileDatabase();
 
                // Get a new compressor channel instance
-               $compressorInstance = ObjectFactory::createObjectByConfiguredName('compressor_channel_class');
+               $compressorChannelInstance = ObjectFactory::createObjectByConfiguredName('compressor_channel_class');
 
                // Set the compressor channel
-               $databaseInstance->setCompressorChannel($compressorInstance);
+               $databaseInstance->setCompressorChannelInstance($compressorChannelInstance);
 
                // Get a file IO handler
                $fileIoInstance = ObjectFactory::createObjectByConfiguredName('file_io_class');
@@ -197,6 +203,25 @@ class CachedLocalFileDatabase extends BaseDatabaseBackend implements DatabaseBac
                $this->fileIoInstance = $fileIoInstance;
        }
 
+       /**
+        * Setter for compressor channel
+        *
+        * @param       $compressorChannelInstance      An instance of a CompressorChannel class
+        * @return      void
+        */
+       protected final function setCompressorChannelInstance (CompressorChannel $compressorChannelInstance) {
+               $this->compressorChannelInstance = $compressorChannelInstance;
+       }
+
+       /**
+        * Getter for compressor channel
+        *
+        * @return      $compressorChannelInstance      An instance of a CompressorChannel class
+        */
+       protected final function getCompressorChannelInstance () {
+               return $this->compressorChannelInstance;
+       }
+
        /**
         * Reads a local data file  and returns it's contents in an array
         *
@@ -210,7 +235,7 @@ class CachedLocalFileDatabase extends BaseDatabaseBackend implements DatabaseBac
                $compressedData = $compressedData['data'];
 
                // Decompress it
-               $serializedData = $this->getCompressorChannel()->getCompressor()->decompressStream($compressedData);
+               $serializedData = $this->getCompressorChannelInstance()->getCompressor()->decompressStream($compressedData);
 
                // Unserialize it
                $dataArray = json_decode($serializedData, true);
@@ -232,7 +257,7 @@ class CachedLocalFileDatabase extends BaseDatabaseBackend implements DatabaseBac
                // Serialize and compress it
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CACHED-LFDB: Flushing ' . count($dataArray) . ' elements to database file ' . $infoInstance . ' ...');
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CACHED-LFDB: dataArray=' . print_r($dataArray, true));
-               $compressedData = $this->getCompressorChannel()->getCompressor()->compressStream(json_encode($dataArray));
+               $compressedData = $this->getCompressorChannelInstance()->getCompressor()->compressStream(json_encode($dataArray));
 
                // Write this data BASE64 encoded to the file
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CACHED-LFDB: Writing ' . strlen($compressedData) . ' bytes ...');