- md5
- 1f186593355ecc86ffa0f428b76f24a2
- sha1
- a2a8ca8d8a77f055b22eb7711212f7844263c2cb
- sha256
- 29cc63b30d4d38da15a0c7878d855ac1fa59d1c4011e139c106bb916d092c8a9
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
<?php
declare(strict_types=1);
namespace Jose\Component\Encryption\Compression;
use InvalidArgumentException;
use Throwable;
use function is_string;
/**
* @deprecated This class is deprecated and will be removed in v4.0. Compression is not recommended for JWE.
*/
final class Deflate implements CompressionMethod
{
private int $compressionLevel = -1;
public function __construct(int $compressionLevel = -1)
{
if ($compressionLevel < -1 || $compressionLevel > 9) {
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.'
);
}
$this->compressionLevel = $compressionLevel;
}
public function name(): string
{
return 'DEF';
}
public function compress(string $data): string
{
try {
$bin = gzdeflate($data, $this->getCompressionLevel());
if (! is_string($bin)) {
throw new InvalidArgumentException('Unable to encode the data');
}
return $bin;
} catch (Throwable $throwable) {
throw new InvalidArgumentException('Unable to compress data.', $throwable->getCode(), $throwable);
}
}
public function uncompress(string $data): string
{
try {
$bin = gzinflate($data);
if (! is_string($bin)) {
throw new InvalidArgumentException('Unable to encode the data');
}
return $bin;
} catch (Throwable $throwable) {
throw new InvalidArgumentException('Unable to uncompress data.', $throwable->getCode(), $throwable);
}
}
private function getCompressionLevel(): int
{
return $this->compressionLevel;
}
}
The same content is in 119 releases, Joomla 5.2.0-alpha2 to 6.3.0-alpha1. See them all, or every version of this file.