2 // Kompressor-Auswahl Klasse
3 class CompressorChannel extends BaseMiddleware {
4 // Output handler instance
5 private $compressor = null;
8 private function __construct () {
9 // Call parent constructor!
10 parent::constructor(__CLASS__);
13 $this->setPartDescr("Komprimierungshandler");
15 // Create an unique ID
16 $this->createUniqueID();
19 // Create a new compressor channel based a given compression handler
20 public final static function createCompressorChannel ($baseDir) {
22 $cInstance = new CompressorChannel();
24 // Is the compressor handler set?
26 (is_null($cInstance->getCompressor()))
27 || (!is_object($cInstance->getCompressor()))
28 || (!method_exists($cInstance->getCompressor(), 'compressStream'))
29 || (!method_exists($cInstance->getCompressor(), 'decompressStream'))
31 // Get a directory pointer
32 $dirPointer = FrameworkDirectoryPointer::createFrameworkDirectoryPointer($baseDir);
34 // Read all directories but no sub directories
35 while ($dir = $dirPointer->readDirectoryExcept(array("..", ".", ".htaccess"))) {
36 // Is this a class file?
37 if ((substr($dir, 0, 6) == "class_") && (substr($dir, -4, 4) == $cInstance->getConfigInstance()->readConfig("php_extension"))) {
38 // Get the compressor's name. That's why you must name
39 // your files like your classes and also that's why you
40 // must keep on class in one file.
41 $class = substr($dir, 6, -4);
43 // Create eval command
44 $eval = sprintf("\$tempInstance = %s::create%s();",
50 if ((defined('DEBUG_EVAL')) || (defined('DEBUG_ALL'))) $cInstance->getDebugInstance()->output(sprintf("[%s:] Konstruierte PHP-Anweisung: <pre><em>%s</em></pre><br />\n",
51 $cInstance->__toString(),
55 // Run it. This will create an instance to the current class
58 // Is the instance valid? We have the stream handler here
59 if ((!is_null($tempInstance)) && (method_exists($tempInstance, 'compressStream')) && (method_exists($tempInstance, 'decompressStream'))) {
60 // Okay, this handler is valid
61 $cInstance->setCompressor($tempInstance);
63 // No more searches required because we have found a valid compressor stream
69 // Close the directory
70 $dirPointer->closeDirectory();
73 // Check again if there is a compressor
75 (is_null($cInstance->getCompressor()))
76 || (!is_object($cInstance->getCompressor()))
77 || (!method_exists($cInstance->getCompressor(), 'compressStream'))
78 || (!method_exists($cInstance->getCompressor(), 'decompressStream'))
80 // Set the null compressor handler
81 $cInstance->setCompressor(NullCompressor::createNullCompressor());
84 // Return the compressor instance
89 * Getter for compressor instance
91 * @return $compressor The compressor instance
93 public final function getCompressor () {
94 return $this->compressor;
98 * Setter for compressor
100 * @param $compressorInstance The compressor instance we shall use
103 public final function setCompressor (Compressor $compressorInstance) {
104 $this->compressor = $compressorInstance;
108 * Getter for the file extension of the current compressor
110 public final function getCompressorExtension () {
111 // Get compressor extension from current compressor
112 return $this->getCompressor()->getCompressorExtension();