]> git.mxchange.org Git - core.git/blobdiff - framework/main/classes/compressor/class_ZlibCompressor.php
Continued:
[core.git] / framework / main / classes / compressor / class_ZlibCompressor.php
index 79b88d5d09dd2280e9b2561bad322efd9b6f3c44..6e120a47d6f2d32b6caadac8c3f93eb6604dfc14 100644 (file)
@@ -6,6 +6,9 @@ namespace Org\Mxchange\CoreFramework\Compressor\Zlib;
 use Org\Mxchange\CoreFramework\Compressor\Compressor;
 use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
 
+// Load SPL stuff
+use \InvalidArgumentException;
+
 /**
  * ZLIB compression and decompression class
  *
@@ -52,7 +55,7 @@ class ZlibCompressor extends BaseFrameworkSystem implements Compressor {
                if ((function_exists('gzcompress')) && (function_exists('gzuncompress'))) {
                        // Compressor can maybe be used
                        $compressorInstance = new ZlibCompressor();
-               } // END - if
+               }
 
                // Return the compressor instance
                return $compressorInstance;
@@ -63,13 +66,14 @@ class ZlibCompressor extends BaseFrameworkSystem implements Compressor {
         *
         * @param       $streamData             Mixed non-object stream data
         * @return      $streamData             The compressed stream data
-        * @throws      InvalidObjectException  If the stream is an object
+        * @throws      InvalidArgumentException        If the stream is not compressable or decompressable
         */
        public function compressStream ($streamData) {
-               if (is_object($streamData)) {
+               // Validate parameter
+               if (is_object($streamData) || is_resource($streamData)) {
                        // Throw an exception
-                       throw new InvalidObjectException($streamData, self::EXCEPTION_UNEXPECTED_OBJECT);
-               } // END - if
+                       throw new InvalidArgumentException(sprintf('streamData[]=%s cannot be compressed/decompressed', gettype($streamData)));
+               }
 
                // Return the compressed stream
                return gzcompress($streamData, 1);
@@ -80,13 +84,14 @@ class ZlibCompressor extends BaseFrameworkSystem implements Compressor {
         *
         * @param       $streamData             Mixed non-object stream data
         * @return      $streamData             The decompressed stream data
-        * @throws      InvalidObjectException  If the stream is an object
+        * @throws      InvalidArgumentException        If the stream is not compressable or decompressable
         */
        public function decompressStream ($streamData) {
-               if (is_object($streamData)) {
+               // Validate parameter
+               if (is_object($streamData) || is_resource($streamData)) {
                        // Throw an exception
-                       throw new InvalidObjectException($streamData, self::EXCEPTION_UNEXPECTED_OBJECT);
-               } // END - if
+                       throw new InvalidArgumentException(sprintf('streamData[]=%s cannot be compressed/decompressed', gettype($streamData)));
+               }
 
                // Return the decompressed stream
                return gzuncompress($streamData);