Debian Codegraph @

lib/3rdParty/composer/web-token/jwt-library/Encryption/Compression/CompressionMethodManagerFactory.php

raw symbols SCIP
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Jose\Component\Encryption\Compression;
6
7 use InvalidArgumentException;
8
9 /**
10 * @deprecated This class is deprecated and will be removed in v4.0. Compression is not recommended for JWE.
11 */
12 class CompressionMethodManagerFactory
13 {
14 /**
15 * @var CompressionMethod[]
16 */
17 private array $compressionMethods = [];
18
19 /**
20 * This method adds a compression method to this factory. The method is uniquely identified by an alias. This allows
21 * the same method to be added twice (or more) using several configuration options.
22 */
23 public function add(string $alias, CompressionMethod $compressionMethod): void
24 {
25 $this->compressionMethods[$alias] = $compressionMethod;
26 }
27
28 /**
29 * Returns the list of compression method aliases supported by the factory.
30 *
31 * @return string[]
32 */
33 public function aliases(): array
34 {
35 return array_keys($this->compressionMethods);
36 }
37
38 /**
39 * Returns all compression methods supported by this factory.
40 *
41 * @return CompressionMethod[]
42 */
43 public function all(): array
44 {
45 return $this->compressionMethods;
46 }
47
48 /**
49 * Creates a compression method manager using the compression methods identified by the given aliases. If one of the
50 * aliases does not exist, an exception is thrown.
51 *
52 * @param string[] $aliases
53 */
54 public function create(array $aliases): CompressionMethodManager
55 {
56 $compressionMethods = [];
57 foreach ($aliases as $alias) {
58 if (! isset($this->compressionMethods[$alias])) {
59 throw new InvalidArgumentException(sprintf(
60 'The compression method with the alias "%s" is not supported.',
61 $alias
62 ));
63 }
64 $compressionMethods[] = $this->compressionMethods[$alias];
65 }
66
67 return new CompressionMethodManager($compressionMethods);
68 }
69 }