3 namespace Org\Mxchange\CoreFramework\Middleware\Compressor;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Compressor\Compressor;
7 use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
8 use Org\Mxchange\CoreFramework\Middleware\BaseMiddleware;
9 use Org\Mxchange\CoreFramework\Registry\Registerable;
12 * Middleware class for selecting the right compressor channel
14 * @author Roland Haeder <webmaster@shipsimu.org>
16 <<<<<<< HEAD:framework/main/middleware/compressor/class_CompressorChannel.php
17 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
19 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2016 Core Developer Team
20 >>>>>>> Some updates::inc/main/middleware/compressor/class_CompressorChannel.php
21 * @license GNU GPL 3.0 or any newer version
22 * @link http://www.shipsimu.org
24 * This program is free software: you can redistribute it and/or modify
25 * it under the terms of the GNU General Public License as published by
26 * the Free Software Foundation, either version 3 of the License, or
27 * (at your option) any later version.
29 * This program is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU General Public License for more details.
34 * You should have received a copy of the GNU General Public License
35 * along with this program. If not, see <http://www.gnu.org/licenses/>.
37 class CompressorChannel extends BaseMiddleware implements Registerable {
39 * Real compressor instance
41 private $compressor = NULL;
44 * Protected constructor
48 protected function __construct () {
49 // Call parent constructor!
50 parent::__construct(__CLASS__);
54 * Create a new compressor channel.
56 * @return $compressorInstance A prepared instance of this class
58 public static final function createCompressorChannel () {
60 $compressorInstance = new CompressorChannel();
62 // Is the compressor handler set?
64 (is_null($compressorInstance->getCompressor()))
65 || (!$compressorInstance->getCompressor() instanceof Compressor)
67 // Init base directory
69 $compressorInstance->getConfigInstance()->getConfigEntry('framework_base_path') .
70 $compressorInstance->getConfigInstance()->getConfigEntry('compressor_base_path');
72 // Get a directory pointer
73 $directoryInstance = ObjectFactory::createObjectByConfiguredName('directory_class', array($baseDir));
75 // Read all directories but no sub directories, .htaccess files and NullCompressor class
76 while ($directoryEntry = $directoryInstance->readDirectoryExcept(array('.htaccess', 'class_NullCompressor.php'))) {
78 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('COMPRESSOR[' . __METHOD__ . ':' . __LINE__ . ']: directoryEntry=' . $directoryEntry);
80 // Is this a class file?
81 if ((substr($directoryEntry, 0, 6) == 'class_') && (substr($directoryEntry, -4, 4) == '.php')) {
82 /* Get the compressor's name. That's why you must name
83 * your files like your classes and also that's why you
84 * must keep on class in one file.
87 // Base name of compressor class
88 $baseClassName = substr($directoryEntry, 6, -4);
90 // Create full class name (with namespace
91 $fullClassName = sprintf(
92 'Org\Mxchange\CoreFramework\Compressor\%s\%s',
93 str_replace('Compressor', '', $baseClassName),
97 // Get an instance from our object factory
98 $tempInstance = ObjectFactory::createObjectByName($fullClassName);
101 if (is_null($tempInstance)) {
102 // Then skip to the next one
106 // Set the compressor
107 $compressorInstance->setCompressor($tempInstance);
109 // No more searches required because we have found a valid compressor stream
114 // Close the directory
115 $directoryInstance->closeDirectory();
118 // Check again if there is a compressor
120 (is_null($compressorInstance->getCompressor()))
121 || (!is_object($compressorInstance->getCompressor()))
122 || (!$compressorInstance instanceof Compressor)
124 // Set the null compressor handler. This should not be configureable!
125 // @TODO Is there a configurable fall-back compressor needed, or is NullCompressor okay?
126 $compressorInstance->setCompressor(ObjectFactory::createObjectByName('Org\Mxchange\CoreFramework\Compressor\Null\NullCompressor'));
129 // Return the compressor instance
130 return $compressorInstance;
134 * Getter for compressor instance
136 * @return $compressor The compressor instance
138 public final function getCompressor () {
139 return $this->compressor;
143 * Setter for compressor
145 * @param $compressorInstance The compressor instance we shall use
148 public final function setCompressor (Compressor $compressorInstance = NULL) {
149 $this->compressor = $compressorInstance;
153 * Getter for the file extension of the current compressor
155 public final function getCompressorExtension () {
156 // Get compressor extension from current compressor
157 return $this->getCompressor()->getCompressorExtension();