1 | <?php |
||
19 | final class Deflate implements CompressionMethod |
||
20 | { |
||
21 | /** |
||
22 | * @var int |
||
23 | */ |
||
24 | private $compressionLevel = -1; |
||
25 | |||
26 | /** |
||
27 | * Deflate constructor. |
||
28 | * |
||
29 | * @throws InvalidArgumentException if the compression level is invalid |
||
30 | */ |
||
31 | public function __construct(int $compressionLevel = -1) |
||
32 | { |
||
33 | if ($compressionLevel < -1 || $compressionLevel > 9) { |
||
34 | throw new InvalidArgumentException('The compression level can be given as 0 for no compression up to 9 for maximum compression. If -1 given, the default compression level will be the default compression level of the zlib library.'); |
||
35 | } |
||
36 | $this->compressionLevel = $compressionLevel; |
||
37 | } |
||
38 | |||
39 | public function name(): string |
||
43 | |||
44 | /** |
||
45 | * @throws InvalidArgumentException if the compression failed |
||
46 | */ |
||
47 | public function compress(string $data): string |
||
55 | |||
56 | /** |
||
57 | * @throws InvalidArgumentException if the decompression failed |
||
58 | */ |
||
59 | public function uncompress(string $data): string |
||
67 | |||
68 | private function getCompressionLevel(): int |
||
72 | } |
||
73 |