|
6 | 6 |
|
7 | 7 | use Interop\Queue\Impl\MessageTrait; |
8 | 8 | use Interop\Queue\Message; |
| 9 | +use Psr\Http\Message\StreamInterface; |
9 | 10 |
|
10 | 11 | class SnsMessage implements Message |
11 | 12 | { |
12 | 13 | use MessageTrait; |
13 | 14 |
|
| 15 | + /** |
| 16 | + * @var string|null |
| 17 | + */ |
14 | 18 | private $snsMessageId; |
15 | 19 |
|
16 | | - public function __construct(string $body = '', array $properties = [], array $headers = []) |
17 | | - { |
| 20 | + /** |
| 21 | + * @var string|null |
| 22 | + */ |
| 23 | + private $messageStructure; |
| 24 | + |
| 25 | + /** |
| 26 | + * @var string|null |
| 27 | + */ |
| 28 | + private $phoneNumber; |
| 29 | + |
| 30 | + /** |
| 31 | + * @var string|null |
| 32 | + */ |
| 33 | + private $subject; |
| 34 | + |
| 35 | + /** |
| 36 | + * @var array|null |
| 37 | + */ |
| 38 | + private $messageAttributes; |
| 39 | + |
| 40 | + /** |
| 41 | + * @var string|null |
| 42 | + */ |
| 43 | + private $targetArn; |
| 44 | + |
| 45 | + /** |
| 46 | + * SnsMessage constructor. |
| 47 | + * |
| 48 | + * See AWS documentation for message attribute structure. |
| 49 | + * |
| 50 | + * @see https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-sns-2010-03-31.html#shape-messageattributevalue |
| 51 | + * |
| 52 | + * @param string $body |
| 53 | + * @param array $properties |
| 54 | + * @param array $headers |
| 55 | + * @param array|null $messageAttributes |
| 56 | + * @param string|null $messageStructure |
| 57 | + * @param string|null $phoneNumber |
| 58 | + * @param string|null $subject |
| 59 | + * @param string|null $targetArn |
| 60 | + */ |
| 61 | + public function __construct( |
| 62 | + string $body = '', |
| 63 | + array $properties = [], |
| 64 | + array $headers = [], |
| 65 | + array $messageAttributes = null, |
| 66 | + string $messageStructure = null, |
| 67 | + string $phoneNumber = null, |
| 68 | + string $subject = null, |
| 69 | + string $targetArn = null |
| 70 | + ) { |
18 | 71 | $this->body = $body; |
19 | 72 | $this->properties = $properties; |
20 | 73 | $this->headers = $headers; |
| 74 | + $this->messageAttributes = $messageAttributes; |
| 75 | + $this->messageStructure = $messageStructure; |
| 76 | + $this->phoneNumber = $phoneNumber; |
| 77 | + $this->subject = $subject; |
| 78 | + $this->targetArn = $targetArn; |
21 | 79 | $this->redelivered = false; |
22 | 80 | } |
23 | 81 |
|
| 82 | + /** |
| 83 | + * @return string|null |
| 84 | + */ |
24 | 85 | public function getSnsMessageId(): ?string |
25 | 86 | { |
26 | 87 | return $this->snsMessageId; |
27 | 88 | } |
28 | 89 |
|
| 90 | + /** |
| 91 | + * @param string|null $snsMessageId |
| 92 | + */ |
29 | 93 | public function setSnsMessageId(?string $snsMessageId): void |
30 | 94 | { |
31 | 95 | $this->snsMessageId = $snsMessageId; |
32 | 96 | } |
| 97 | + |
| 98 | + /** |
| 99 | + * @return string|null |
| 100 | + */ |
| 101 | + public function getMessageStructure(): ?string |
| 102 | + { |
| 103 | + return $this->messageStructure; |
| 104 | + } |
| 105 | + |
| 106 | + /** |
| 107 | + * @param string|null $messageStructure |
| 108 | + */ |
| 109 | + public function setMessageStructure(?string $messageStructure): void |
| 110 | + { |
| 111 | + $this->messageStructure = $messageStructure; |
| 112 | + } |
| 113 | + |
| 114 | + /** |
| 115 | + * @return string|null |
| 116 | + */ |
| 117 | + public function getPhoneNumber(): ?string |
| 118 | + { |
| 119 | + return $this->phoneNumber; |
| 120 | + } |
| 121 | + |
| 122 | + /** |
| 123 | + * @param string|null $phoneNumber |
| 124 | + */ |
| 125 | + public function setPhoneNumber(?string $phoneNumber): void |
| 126 | + { |
| 127 | + $this->phoneNumber = $phoneNumber; |
| 128 | + } |
| 129 | + |
| 130 | + /** |
| 131 | + * @return string|null |
| 132 | + */ |
| 133 | + public function getSubject(): ?string |
| 134 | + { |
| 135 | + return $this->subject; |
| 136 | + } |
| 137 | + |
| 138 | + /** |
| 139 | + * @param string|null $subject |
| 140 | + */ |
| 141 | + public function setSubject(?string $subject): void |
| 142 | + { |
| 143 | + $this->subject = $subject; |
| 144 | + } |
| 145 | + |
| 146 | + /** |
| 147 | + * @return array|null |
| 148 | + */ |
| 149 | + public function getMessageAttributes(): ?array |
| 150 | + { |
| 151 | + return $this->messageAttributes; |
| 152 | + } |
| 153 | + |
| 154 | + /** |
| 155 | + * @param array|null $messageAttributes |
| 156 | + */ |
| 157 | + public function setMessageAttributes(?array $messageAttributes): void |
| 158 | + { |
| 159 | + $this->messageAttributes = $messageAttributes; |
| 160 | + } |
| 161 | + |
| 162 | + /** |
| 163 | + * @param string $name |
| 164 | + * @param null $default |
| 165 | + * |
| 166 | + * @return array|null |
| 167 | + */ |
| 168 | + public function getAttribute(string $name, $default = null) |
| 169 | + { |
| 170 | + return array_key_exists($name, $this->messageAttributes) ? $this->messageAttributes[$name] : $default; |
| 171 | + } |
| 172 | + |
| 173 | + /** |
| 174 | + * Attribute array format: |
| 175 | + * [ |
| 176 | + * 'BinaryValue' => <string || resource || Psr\Http\Message\StreamInterface>, |
| 177 | + * 'DataType' => '<string>', // REQUIRED |
| 178 | + * 'StringValue' => '<string>', |
| 179 | + * ]. |
| 180 | + * |
| 181 | + * @param string $name |
| 182 | + * @param array|null $attribute |
| 183 | + */ |
| 184 | + public function setAttribute(string $name, ?array $attribute): void |
| 185 | + { |
| 186 | + if (null === $attribute) { |
| 187 | + unset($this->messageAttributes[$name]); |
| 188 | + } else { |
| 189 | + $this->messageAttributes[$name] = $attribute; |
| 190 | + } |
| 191 | + } |
| 192 | + |
| 193 | + /** |
| 194 | + * @param string $name |
| 195 | + * @param string $dataType String, String.Array, Number, or Binary |
| 196 | + * @param string|resource|StreamInterface $value |
| 197 | + */ |
| 198 | + public function addAttribute(string $name, string $dataType, $value): void |
| 199 | + { |
| 200 | + $valueKey = 'Binary' === $dataType ? 'BinaryValue' : 'StringValue'; |
| 201 | + |
| 202 | + $this->messageAttributes[$name] = [ |
| 203 | + 'DataType' => $dataType, |
| 204 | + $valueKey => $value, |
| 205 | + ]; |
| 206 | + } |
| 207 | + |
| 208 | + /** |
| 209 | + * @return string|null |
| 210 | + */ |
| 211 | + public function getTargetArn(): ?string |
| 212 | + { |
| 213 | + return $this->targetArn; |
| 214 | + } |
| 215 | + |
| 216 | + /** |
| 217 | + * @param string|null $targetArn |
| 218 | + */ |
| 219 | + public function setTargetArn(?string $targetArn): void |
| 220 | + { |
| 221 | + $this->targetArn = $targetArn; |
| 222 | + } |
33 | 223 | } |
0 commit comments