]> git.mxchange.org Git - core.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Fri, 24 Feb 2023 10:01:39 +0000 (11:01 +0100)
committerRoland Häder <roland@mxchange.org>
Fri, 24 Feb 2023 10:01:39 +0000 (11:01 +0100)
- rather check for extension being loaded than found functions
- checks on resource or object is no longer needed

framework/main/classes/compressor/class_Bzip2Compressor.php
framework/main/classes/compressor/class_GzipCompressor.php
framework/main/classes/compressor/class_ZlibCompressor.php

index 2606c13c0f03aca94395956f13690c7f857d7dfc..66c5ab0211a42616b393d373eabc3862de1521ce 100644 (file)
@@ -6,9 +6,6 @@ namespace Org\Mxchange\CoreFramework\Compressor\Bzip2;
 use Org\Mxchange\CoreFramework\Compressor\Compressor;
 use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
 
-// Load SPL stuff
-use \InvalidArgumentException;
-
 /**
  * BZIP2 compression and decompression class
  *
@@ -52,7 +49,7 @@ class Bzip2Compressor extends BaseFrameworkSystem implements Compressor {
                $compressorInstance = NULL;
 
                // Get new instance
-               if ((function_exists('bzcompress')) && (function_exists('bzdecompress'))) {
+               if (extension_loaded('bzip2')) {
                        // Compressor can maybe be used
                        $compressorInstance = new Bzip2Compressor();
                }
@@ -66,17 +63,13 @@ class Bzip2Compressor extends BaseFrameworkSystem implements Compressor {
         *
         * @param       $streamData             Mixed non-object stream data
         * @return      $streamData             The compressed stream data
-        * @throws      InvalidArgumentException        If the stream is not compressable or decompressable
         */
        public function compressStream (string $streamData) {
-               // Validate parameter
-               if (is_object($streamData) || is_resource($streamData)) {
-                       // Throw an exception
-                       throw new InvalidArgumentException(sprintf('streamData[]=%s cannot be compressed/decompressed', gettype($streamData)));
-               }
+               // Compress it
+               $streamData = bzcompress($streamData, 1);
 
                // Return the compressed stream
-               return bzcompress($streamData, 1);
+               return $streamData;
        }
 
        /**
@@ -84,15 +77,8 @@ class Bzip2Compressor extends BaseFrameworkSystem implements Compressor {
         *
         * @param       $streamData             Mixed non-object stream data
         * @return      $streamData             The decompressed stream data
-        * @throws      InvalidArgumentException        If the stream is not compressable or decompressable
         */
        public function decompressStream (string $streamData) {
-               // Validate parameter
-               if (is_object($streamData) || is_resource($streamData)) {
-                       // Throw an exception
-                       throw new InvalidArgumentException(sprintf('streamData[]=%s cannot be compressed/decompressed', gettype($streamData)));
-               }
-
                // Decompress it
                $streamData = bzdecompress($streamData, true);
 
index 3ab0b13f6d6eee455d1790ccd36a273d96a25de6..d8446a8d0d41760aa6bd9d17785e37bfc73cb876 100644 (file)
@@ -6,9 +6,6 @@ namespace Org\Mxchange\CoreFramework\Compressor\Gzip;
 use Org\Mxchange\CoreFramework\Compressor\Compressor;
 use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
 
-// Load SPL stuff
-use \InvalidArgumentException;
-
 /**
  * GZIP compression and decompression class
  *
@@ -66,17 +63,13 @@ class GzipCompressor extends BaseFrameworkSystem implements Compressor {
         *
         * @param       $streamData             Mixed non-object stream data
         * @return      $streamData             The compressed stream data
-        * @throws      InvalidArgumentException        If the stream is not compressable or decompressable
         */
        public function compressStream (string $streamData) {
-               // Validate parameter
-               if (is_object($streamData) || is_resource($streamData)) {
-                       // Throw an exception
-                       throw new InvalidArgumentException(sprintf('streamData[]=%s cannot be compressed/decompressed', gettype($streamData)));
-               }
+               // Compress stream
+               $streamData = gzencode($streamData, 1);
 
-               // Return the compressed stream
-               return gzencode($streamData, 1);
+               // Return it
+               return $streamData;
        }
 
        /**
@@ -84,17 +77,13 @@ class GzipCompressor extends BaseFrameworkSystem implements Compressor {
         *
         * @param       $streamData             Mixed non-object stream data
         * @return      $streamData             The decompressed stream data
-        * @throws      InvalidArgumentException        If the stream is not compressable or decompressable
         */
        public function decompressStream (string $streamData) {
-               // Validate parameter
-               if (is_object($streamData) || is_resource($streamData)) {
-                       // Throw an exception
-                       throw new InvalidArgumentException(sprintf('streamData[]=%s cannot be compressed/decompressed', gettype($streamData)));
-               }
+               // Decompress string
+               $streamData = gzdecode($streamData);
 
-               // Return the decompressed stream
-               return gzdecode($streamData);
+               // Return it
+               return $streamData;
        }
 
        /**
index f8982d5b5fc8fcdaea75c1e6e0222fa14cbddd88..a5db0382cf57d92a72486fe381bd82688972d222 100644 (file)
@@ -6,9 +6,6 @@ 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
  *
@@ -66,17 +63,13 @@ class ZlibCompressor extends BaseFrameworkSystem implements Compressor {
         *
         * @param       $streamData             Mixed non-object stream data
         * @return      $streamData             The compressed stream data
-        * @throws      InvalidArgumentException        If the stream is not compressable or decompressable
         */
        public function compressStream (string $streamData) {
-               // Validate parameter
-               if (is_object($streamData) || is_resource($streamData)) {
-                       // Throw an exception
-                       throw new InvalidArgumentException(sprintf('streamData[]=%s cannot be compressed/decompressed', gettype($streamData)));
-               }
+               // Compress string
+               $streamData = gzcompress($streamData, 1);
 
-               // Return the compressed stream
-               return gzcompress($streamData, 1);
+               // Return it
+               return $streamData;
        }
 
        /**
@@ -84,17 +77,13 @@ class ZlibCompressor extends BaseFrameworkSystem implements Compressor {
         *
         * @param       $streamData             Mixed non-object stream data
         * @return      $streamData             The decompressed stream data
-        * @throws      InvalidArgumentException        If the stream is not compressable or decompressable
         */
        public function decompressStream (string $streamData) {
-               // Validate parameter
-               if (is_object($streamData) || is_resource($streamData)) {
-                       // Throw an exception
-                       throw new InvalidArgumentException(sprintf('streamData[]=%s cannot be compressed/decompressed', gettype($streamData)));
-               }
-
                // Return the decompressed stream
-               return gzuncompress($streamData);
+               $streamData = gzuncompress($streamData);
+
+               // Return it
+               return $streamData;
        }
 
        /**