3 declare(strict_types=1);
5 namespace Jose\Component\Encryption\Compression;
7 use InvalidArgumentException;
9 class CompressionMethodManagerFactory
12 * @var CompressionMethod[]
14 private array $compressionMethods = [];
17 * This method adds a compression method to this factory. The method is uniquely identified by an alias. This allows
18 * the same method to be added twice (or more) using several configuration options.
20 public function add(string $alias, CompressionMethod $compressionMethod): void
22 $this->compressionMethods[$alias] = $compressionMethod;
26 * Returns the list of compression method aliases supported by the factory.
30 public function aliases(): array
32 return array_keys($this->compressionMethods);
36 * Returns all compression methods supported by this factory.
38 * @return CompressionMethod[]
40 public function all(): array
42 return $this->compressionMethods;
46 * Creates a compression method manager using the compression methods identified by the given aliases. If one of the
47 * aliases does not exist, an exception is thrown.
49 * @param string[] $aliases
51 public function create(array $aliases): CompressionMethodManager
53 $compressionMethods = [];
54 foreach ($aliases as $alias) {
55 if (! isset($this->compressionMethods[$alias])) {
56 throw new InvalidArgumentException(sprintf(
57 'The compression method with the alias "%s" is not supported.',
61 $compressionMethods[] = $this->compressionMethods[$alias];
64 return new CompressionMethodManager($compressionMethods);