* @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.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 * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 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 . */ class CompressorChannel extends BaseMiddleware implements Registerable { /** * Real compressor instance */ private $compressor = null; /** * Protected constructor * * @return void */ protected function __construct () { // Call parent constructor! parent::__construct(__CLASS__); } /** * 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(); // 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", ".svn"))) { // Is this a class file? if ((substr($dir, 0, 6) == "class_") && (substr($dir, -4, 4) == ".php")) { // 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. $className = substr($dir, 6, -4); // Get an instance from our object factory $tempInstance = ObjectFactory::createObjectByName($className); // Set the compressor $cInstance->setCompressor($tempInstance); // 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 ( (is_null($cInstance->getCompressor())) || (!is_object($cInstance->getCompressor())) || (!method_exists($cInstance->getCompressor(), 'compressStream')) || (!method_exists($cInstance->getCompressor(), 'decompressStream')) ) { // Set the null compressor handler. This should not be configureable! $cInstance->setCompressor(ObjectFactory::createObjectByName('NullCompressor')); } // END - if // 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] ?>