| 1 | <?php |
||
| 19 | final class Recipient |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * @var array |
||
| 23 | */ |
||
| 24 | private $header = []; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @var null|string |
||
| 28 | */ |
||
| 29 | private $encryptedKey = null; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Recipient constructor. |
||
| 33 | * |
||
| 34 | * @param array $header |
||
| 35 | * @param null|string $encryptedKey |
||
| 36 | */ |
||
| 37 | private function __construct(array $header, ?string $encryptedKey) |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @param array $header |
||
| 45 | * @param null|string $encryptedKey |
||
| 46 | * |
||
| 47 | * @return Recipient |
||
| 48 | */ |
||
| 49 | public static function create(array $header = [], ?string $encryptedKey): self |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @return array |
||
| 56 | */ |
||
| 57 | public function getHeader(): array |
||
| 58 | { |
||
| 59 | return $this->header; |
||
| 60 | } |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Returns the value of the unprotected header of the specified key. |
||
| 64 | * |
||
| 65 | * @param string $key The key |
||
| 66 | * |
||
| 67 | * @return mixed|null Header value |
||
| 68 | */ |
||
| 69 | public function getHeaderParameter(string $key) |
||
| 70 | { |
||
| 71 | if ($this->hasHeaderParameter($key)) { |
||
| 72 | return $this->header[$key]; |
||
| 73 | } |
||
| 74 | |||
| 75 | throw new \InvalidArgumentException(sprintf('The header "%s" does not exist.', $key)); |
||
| 76 | } |
||
| 77 | |||
| 78 | /** |
||
| 79 | * @param string $key The key |
||
| 80 | * |
||
| 81 | * @return bool |
||
| 82 | */ |
||
| 83 | public function hasHeaderParameter(string $key): bool |
||
| 84 | { |
||
| 85 | return array_key_exists($key, $this->header); |
||
| 86 | } |
||
| 87 | |||
| 88 | /** |
||
| 89 | * @return null|string |
||
| 90 | */ |
||
| 91 | public function getEncryptedKey(): ?string |
||
| 95 | } |
||
| 96 |