]> git.mxchange.org Git - core.git/blob - framework/main/classes/compressor/class_NullCompressor.php
Continued:
[core.git] / framework / main / classes / compressor / class_NullCompressor.php
1 <?php
2 // Own namespace
3 namespace Org\Mxchange\CoreFramework\Compressor\Null;
4
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Compressor\Compressor;
7 use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
8
9 // Load SPL stuff
10 use \InvalidArgumentException;
11
12 /**
13  * Null compression and decompression class
14  *
15  * @author              Roland Haeder <webmaster@shipsimu.org>
16  * @version             0.0.0
17  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2023 Core Developer Team
18  * @license             GNU GPL 3.0 or any newer version
19  * @link                http://www.shipsimu.org
20  *
21  * This program is free software: you can redistribute it and/or modify
22  * it under the terms of the GNU General Public License as published by
23  * the Free Software Foundation, either version 3 of the License, or
24  * (at your option) any later version.
25  *
26  * This program is distributed in the hope that it will be useful,
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29  * GNU General Public License for more details.
30  *
31  * You should have received a copy of the GNU General Public License
32  * along with this program. If not, see <http://www.gnu.org/licenses/>.
33  */
34 class NullCompressor extends BaseFrameworkSystem implements Compressor {
35         /**
36          * Protected constructor
37          *
38          * @return      void
39          */
40         private function __construct () {
41                 // Call parent constructor!
42                 parent::__construct(__CLASS__);
43         }
44
45         /**
46          * Create a new compressor channel based a given compression handler
47          *
48          * @return      $compressorInstance             An instance of this class
49          */
50         public static final function createNullCompressor () {
51                 // Get new instance
52                 $compressorInstance = new NullCompressor();
53
54                 // Return the compressor instance
55                 return $compressorInstance;
56         }
57
58         /**
59          * Null compression stream
60          *
61          * @param       $streamData             Mixed non-object stream data
62          * @return      $streamData             The compressed stream data
63          * @throws      InvalidArgumentException        If the stream is not compressable or decompressable
64          */
65         public function compressStream (string $streamData) {
66                 // Validate parameter
67                 if (is_object($streamData) || is_resource($streamData)) {
68                         // Throw an exception
69                         throw new InvalidArgumentException(sprintf('streamData[]=%s cannot be compressed/decompressed', gettype($streamData)));
70                 }
71
72                 // Return the compressed stream
73                 return $streamData;
74         }
75
76         /**
77          * Null decompression stream
78          *
79          * @param       $streamData             Mixed non-object stream data
80          * @return      $streamData             The decompressed stream data
81          * @throws      InvalidArgumentException        If the stream is not compressable or decompressable
82          */
83         public function decompressStream (string $streamData) {
84                 // Validate parameter
85                 if (is_object($streamData) || is_resource($streamData)) {
86                         // Throw an exception
87                         throw new InvalidArgumentException(sprintf('streamData[]=%s cannot be compressed/decompressed', gettype($streamData)));
88                 }
89
90                 // Return the decompressed stream
91                 return $streamData;
92         }
93
94         /**
95          * Getter for the file extension of this compressor
96          *
97          * @return      $string         Returns always 'null'
98          */
99         public final function getCompressorExtension () {
100                 return 'null';
101         }
102
103 }