]> git.mxchange.org Git - shipsimu.git/blobdiff - ship-simu/inc/classes/middleware/compressor/class_CompressorChannel.php
Initial import of current development status
[shipsimu.git] / ship-simu / inc / classes / middleware / compressor / class_CompressorChannel.php
diff --git a/ship-simu/inc/classes/middleware/compressor/class_CompressorChannel.php b/ship-simu/inc/classes/middleware/compressor/class_CompressorChannel.php
new file mode 100644 (file)
index 0000000..858401f
--- /dev/null
@@ -0,0 +1,117 @@
+<?php
+// Kompressor-Auswahl Klasse
+class CompressorChannel extends BaseMiddleware {
+       // Output handler instance
+       private $compressor = null;
+
+       // Public constructor
+       private function __construct () {
+               // Call parent constructor!
+               parent::constructor(__CLASS__);
+
+               // Set description
+               $this->setPartDescr("Komprimierungshandler");
+
+               // Create an unique ID
+               $this->createUniqueID();
+       }
+
+       // Create a new compressor channel based a given compression handler
+       public final static function createCompressorChannel ($baseDir) {
+               // Get new instance
+               $cInstance = new CompressorChannel();
+
+               // Is the compressor handler set?
+               if (
+                          (is_null($cInstance->getCompressor()))
+                       || (!is_object($cInstance->getCompressor()))
+                       || (!method_exists($cInstance->getCompressor(), 'compressStream'))
+                       || (!method_exists($cInstance->getCompressor(), 'decompressStream'))
+               ) {
+                       // Get a directory pointer
+                       $dirPointer = FrameworkDirectoryPointer::createFrameworkDirectoryPointer($baseDir);
+
+                       // Read all directories but no sub directories
+                       while ($dir = $dirPointer->readDirectoryExcept(array("..", ".", ".htaccess"))) {
+                               // Is this a class file?
+                               if ((substr($dir, 0, 6) == "class_") && (substr($dir, -4, 4) == $cInstance->getConfigInstance()->readConfig("php_extension"))) {
+                                       // Get the compressor's name. That's why you must name
+                                       // your files like your classes and also that's why you
+                                       // must keep on class in one file.
+                                       $class = substr($dir, 6, -4);
+
+                                       // Create eval command
+                                       $eval = sprintf("\$tempInstance = %s::create%s();",
+                                               $class,
+                                               $class
+                                       );
+
+                                       // Debug message
+                                       if ((defined('DEBUG_EVAL')) || (defined('DEBUG_ALL'))) $cInstance->getDebugInstance()->output(sprintf("[%s:] Konstruierte PHP-Anweisung: <pre><em>%s</em></pre><br />\n",
+                                               $cInstance->__toString(),
+                                               htmlentities($eval)
+                                       ));
+
+                                       // Run it. This will create an instance to the current class
+                                       eval($eval);
+
+                                       // Is the instance valid? We have the stream handler here
+                                       if ((!is_null($tempInstance)) && (method_exists($tempInstance, 'compressStream')) && (method_exists($tempInstance, 'decompressStream'))) {
+                                               // Okay, this handler is valid
+                                               $cInstance->setCompressor($tempInstance);
+
+                                               // No more searches required because we have found a valid compressor stream
+                                               break;
+                                       }
+                               }
+                       }
+
+                       // Close the directory
+                       $dirPointer->closeDirectory();
+               }
+
+               // Check again if there is a compressor
+               if (
+                          (is_null($cInstance->getCompressor()))
+                       || (!is_object($cInstance->getCompressor()))
+                       || (!method_exists($cInstance->getCompressor(), 'compressStream'))
+                       || (!method_exists($cInstance->getCompressor(), 'decompressStream'))
+               ) {
+                       // Set the null compressor handler
+                       $cInstance->setCompressor(NullCompressor::createNullCompressor());
+               }
+       
+               // Return the compressor instance
+               return $cInstance;
+       }
+
+       /**
+        * Getter for compressor instance
+        *
+        * @return      $compressor     The compressor instance
+        */
+       public final function getCompressor () {
+               return $this->compressor;
+       }
+
+       /**
+        * Setter for compressor
+        *
+        * @param               $compressorInstance     The compressor instance we shall use
+        * @return      void
+        */
+       public final function setCompressor (Compressor $compressorInstance) {
+               $this->compressor = $compressorInstance;
+       }
+
+       /**
+        * Getter for the file extension of the current compressor
+        */
+       public final function getCompressorExtension () {
+               // Get compressor extension from current compressor
+               return $this->getCompressor()->getCompressorExtension();
+       }
+}
+
+// [EOF]
+?>