level = $level; $this->threshold = $minCompressionSize; $this->maxDecompressionSize = $maxDecompressionSize; } public function willCompress(string $data) : bool{ return $this->threshold > -1 and strlen($data) >= $this->threshold; } /** * @throws DecompressionException */ public function decompress(string $payload) : string{ $result = @zlib_decode($payload, $this->maxDecompressionSize); if($result === false){ throw new DecompressionException("Failed to decompress data"); } return $result; } public function compress(string $payload) : string{ return zlib_encode($payload, ZLIB_ENCODING_DEFLATE, $this->willCompress($payload) ? $this->level : 0); } }