X-Git-Url: https://git.mxchange.org/?p=shipsimu.git;a=blobdiff_plain;f=inc%2Fclasses%2Fmiddleware%2Fcompressor%2Fclass_CompressorChannel.php;h=346538024f1b8d6ac3f8ff8e6f615bba785bfe9a;hp=5d5017c6e65b846b34c2ddd233bea283ae5d194e;hb=55b327a3f5f2fe1d244532e07be7444e94b2a768;hpb=6a235495afbc92d4116f94be590d40feb1ad7905 diff --git a/inc/classes/middleware/compressor/class_CompressorChannel.php b/inc/classes/middleware/compressor/class_CompressorChannel.php index 5d5017c..3465380 100644 --- a/inc/classes/middleware/compressor/class_CompressorChannel.php +++ b/inc/classes/middleware/compressor/class_CompressorChannel.php @@ -2,11 +2,11 @@ /** * Middleware class for selecting the right compressor channel * - * @author Roland Haeder - * @version 0.3.0 + * @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.mxchange.org + * @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 @@ -19,25 +19,37 @@ * 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 CompressorChannel extends BaseMiddleware { - // Output handler instance +class CompressorChannel extends BaseMiddleware implements Registerable { + /** + * Real compressor instance + */ private $compressor = null; - // Public constructor - private function __construct () { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { // Call parent constructor! - parent::constructor(__CLASS__); + parent::__construct(__CLASS__); // Set description - $this->setPartDescr("Komprimierungshandler"); + $this->setObjectDescription("Komprimierungshandler"); // Create an unique ID - $this->createUniqueID(); + $this->generateUniqueId(); } - // Create a new compressor channel based a given compression handler + /** + * Create a new compressor channel based a given base directory where + * we shall look for compressor classes + * + * @param $baseDir Directory which holds our compressor classes + * @return $cInstance A prepared instance of this class + */ public final static function createCompressorChannel ($baseDir) { // Get new instance $cInstance = new CompressorChannel(); @@ -53,43 +65,28 @@ class CompressorChannel extends BaseMiddleware { $dirPointer = FrameworkDirectoryPointer::createFrameworkDirectoryPointer($baseDir); // Read all directories but no sub directories - while ($dir = $dirPointer->readDirectoryExcept(array("..", ".", ".htaccess"))) { + while ($dir = $dirPointer->readDirectoryExcept(array("..", ".", ".htaccess", ".svn"))) { // Is this a class file? - if ((substr($dir, 0, 6) == "class_") && (substr($dir, -4, 4) == $cInstance->getConfigInstance()->readConfig("php_extension"))) { + if ((substr($dir, 0, 6) == "class_") && (substr($dir, -4, 4) == FrameworkConfiguration::getInstance()->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:
%s

\n", - $cInstance->__toString(), - htmlentities($eval) - )); - - // Run it. This will create an instance to the current class - eval($eval); + // Get an instance from our object factory + $tempInstance = ObjectFactory::createObjectByName($class); - // 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); + // Set the compressor + $cInstance->setCompressor($tempInstance); - // No more searches required because we have found a valid compressor stream - break; - } - } - } + // No more searches required because we have found a valid compressor stream + break; + } // END - if + } // END - while // Close the directory $dirPointer->closeDirectory(); - } + } // END - if // Check again if there is a compressor if ( @@ -98,9 +95,9 @@ class CompressorChannel extends BaseMiddleware { || (!method_exists($cInstance->getCompressor(), 'compressStream')) || (!method_exists($cInstance->getCompressor(), 'decompressStream')) ) { - // Set the null compressor handler - $cInstance->setCompressor(NullCompressor::createNullCompressor()); - } + // Set the null compressor handler. This should not be configureable! + $cInstance->setCompressor(ObjectFactory::createObjectByName('NullCompressor')); + } // END - if // Return the compressor instance return $cInstance;