class_CompressorChannel.php

Go to the documentation of this file.
00001 <?php
00024 class CompressorChannel extends BaseMiddleware implements Registerable {
00028         private $compressor = null;
00029 
00035         protected function __construct () {
00036                 // Call parent constructor!
00037                 parent::__construct(__CLASS__);
00038         }
00039 
00047         public final static function createCompressorChannel ($baseDir) {
00048                 // Get new instance
00049                 $cInstance = new CompressorChannel();
00050 
00051                 // Is the compressor handler set?
00052                 if (
00053                            (is_null($cInstance->getCompressor()))
00054                         || (!is_object($cInstance->getCompressor()))
00055                         || (!method_exists($cInstance->getCompressor(), 'compressStream'))
00056                         || (!method_exists($cInstance->getCompressor(), 'decompressStream'))
00057                 ) {
00058                         // Get a directory pointer
00059                         $dirPointer = FrameworkDirectoryPointer::createFrameworkDirectoryPointer($baseDir);
00060 
00061                         // Read all directories but no sub directories
00062                         while ($dir = $dirPointer->readDirectoryExcept(array("..", ".", ".htaccess", ".svn"))) {
00063                                 // Is this a class file?
00064                                 if ((substr($dir, 0, 6) == "class_") && (substr($dir, -4, 4) == ".php")) {
00065                                         // Get the compressor's name. That's why you must name
00066                                         // your files like your classes and also that's why you
00067                                         // must keep on class in one file.
00068                                         $className = substr($dir, 6, -4);
00069 
00070                                         // Get an instance from our object factory
00071                                         $tempInstance = ObjectFactory::createObjectByName($className);
00072 
00073                                         // Set the compressor
00074                                         $cInstance->setCompressor($tempInstance);
00075 
00076                                         // No more searches required because we have found a valid compressor stream
00077                                         break;
00078                                 } // END - if
00079                         } // END - while
00080 
00081                         // Close the directory
00082                         $dirPointer->closeDirectory();
00083                 } // END - if
00084 
00085                 // Check again if there is a compressor
00086                 if (
00087                            (is_null($cInstance->getCompressor()))
00088                         || (!is_object($cInstance->getCompressor()))
00089                         || (!method_exists($cInstance->getCompressor(), 'compressStream'))
00090                         || (!method_exists($cInstance->getCompressor(), 'decompressStream'))
00091                 ) {
00092                         // Set the null compressor handler. This should not be configureable!
00093                         $cInstance->setCompressor(ObjectFactory::createObjectByName('NullCompressor'));
00094                 } // END - if
00095 
00096                 // Return the compressor instance
00097                 return $cInstance;
00098         }
00099 
00105         public final function getCompressor () {
00106                 return $this->compressor;
00107         }
00108 
00115         public final function setCompressor (Compressor $compressorInstance) {
00116                 $this->compressor = $compressorInstance;
00117         }
00118 
00122         public final function getCompressorExtension () {
00123                 // Get compressor extension from current compressor
00124                 return $this->getCompressor()->getCompressorExtension();
00125         }
00126 }
00127 
00128 // [EOF]
00129 ?>

Generated on Mon Dec 8 01:06:46 2008 for Ship-Simulator by  doxygen 1.5.6