3 declare(strict_types=1);
5 namespace Jose\Component\Encryption\Compression;
7 use InvalidArgumentException;
8 use function array_key_exists;
11 * @deprecated This class is deprecated and will be removed in v4.0. Compression is not recommended for JWE.
13 class CompressionMethodManager
16 * @var CompressionMethod[]
18 private array $compressionMethods = [];
21 * @param CompressionMethod[] $methods
23 public function __construct(iterable $methods = [])
25 foreach ($methods as $method) {
31 * Returns true if the givn compression method is supported.
33 public function has(string $name): bool
35 return array_key_exists($name, $this->compressionMethods);
39 * This method returns the compression method with the given name. Throws an exception if the method is not
42 * @param string $name The name of the compression method
44 public function get(string $name): CompressionMethod
46 if (! $this->has($name)) {
47 throw new InvalidArgumentException(sprintf('The compression method "%s" is not supported.', $name));
50 return $this->compressionMethods[$name];
54 * Returns the list of compression method names supported by the manager.
58 public function list(): array
60 return array_keys($this->compressionMethods);
64 * Add the given compression method to the manager.
66 protected function add(CompressionMethod $compressionMethod): void
68 $name = $compressionMethod->name();
69 $this->compressionMethods[$name] = $compressionMethod;