| @@ 30-104 (lines=75) @@ | ||
| 27 | /** |
|
| 28 | * @author Keith Kirk <[email protected]> |
|
| 29 | */ |
|
| 30 | class Message |
|
| 31 | { |
|
| 32 | /** |
|
| 33 | * Message Id |
|
| 34 | * |
|
| 35 | * @var int|string |
|
| 36 | */ |
|
| 37 | protected $id; |
|
| 38 | ||
| 39 | /** |
|
| 40 | * Message Body |
|
| 41 | * |
|
| 42 | * @var string|array |
|
| 43 | */ |
|
| 44 | protected $body; |
|
| 45 | ||
| 46 | /** |
|
| 47 | * Message Metadata |
|
| 48 | * |
|
| 49 | * @var ArrayCollection |
|
| 50 | */ |
|
| 51 | protected $metadata; |
|
| 52 | ||
| 53 | /** |
|
| 54 | * Constructor. |
|
| 55 | * |
|
| 56 | * Sets the Message Id, Message Body, and any Message Metadata |
|
| 57 | * |
|
| 58 | * @param int|string $id The Message Id |
|
| 59 | * @param string|array $body The Message Message |
|
| 60 | * @param array $metadata The Message Metadata |
|
| 61 | */ |
|
| 62 | public function __construct($id, $body, array $metadata) |
|
| 63 | { |
|
| 64 | $this->id = $id; |
|
| 65 | $this->metadata = new ArrayCollection($metadata); |
|
| 66 | ||
| 67 | $message = is_string($body) ? json_decode($body, true) : $body; |
|
| 68 | if (json_last_error() !== JSON_ERROR_NONE) { |
|
| 69 | $message = $body; |
|
| 70 | } |
|
| 71 | ||
| 72 | $this->body = $message; |
|
| 73 | } |
|
| 74 | ||
| 75 | /** |
|
| 76 | * Returns the Message Id |
|
| 77 | * |
|
| 78 | * @return int|string |
|
| 79 | */ |
|
| 80 | public function getId() |
|
| 81 | { |
|
| 82 | return $this->id; |
|
| 83 | } |
|
| 84 | ||
| 85 | /** |
|
| 86 | * Returns the Message Body |
|
| 87 | * |
|
| 88 | * @return string|array |
|
| 89 | */ |
|
| 90 | public function getBody() |
|
| 91 | { |
|
| 92 | return $this->body; |
|
| 93 | } |
|
| 94 | ||
| 95 | /** |
|
| 96 | * Returns the Message Metadata |
|
| 97 | * |
|
| 98 | * @return ArrayCollection |
|
| 99 | */ |
|
| 100 | public function getMetadata() |
|
| 101 | { |
|
| 102 | return $this->metadata; |
|
| 103 | } |
|
| 104 | } |
|
| 105 | ||
| @@ 30-104 (lines=75) @@ | ||
| 27 | /** |
|
| 28 | * @author Keith Kirk <[email protected]> |
|
| 29 | */ |
|
| 30 | class Notification |
|
| 31 | { |
|
| 32 | /** |
|
| 33 | * Notification Id |
|
| 34 | * |
|
| 35 | * @var int|string |
|
| 36 | */ |
|
| 37 | protected $id; |
|
| 38 | ||
| 39 | /** |
|
| 40 | * Notification Body |
|
| 41 | * |
|
| 42 | * @var string|array |
|
| 43 | */ |
|
| 44 | protected $body; |
|
| 45 | ||
| 46 | /** |
|
| 47 | * Notification Metadata |
|
| 48 | * |
|
| 49 | * @var ArrayCollection |
|
| 50 | */ |
|
| 51 | protected $metadata; |
|
| 52 | ||
| 53 | /** |
|
| 54 | * Constructor. |
|
| 55 | * |
|
| 56 | * Sets the Notification Id, Notification Body, and any Notification Metadata |
|
| 57 | * |
|
| 58 | * @param int|string $id The Notification Id |
|
| 59 | * @param string|array $body The Notification Message |
|
| 60 | * @param array $metadata The Notification Metadata |
|
| 61 | */ |
|
| 62 | public function __construct($id, $body, array $metadata) |
|
| 63 | { |
|
| 64 | $this->id = $id; |
|
| 65 | $this->metadata = new ArrayCollection($metadata); |
|
| 66 | ||
| 67 | $message = is_string($body) ? json_decode($body, true) : $body; |
|
| 68 | if (json_last_error() !== JSON_ERROR_NONE) { |
|
| 69 | $message = $body; |
|
| 70 | } |
|
| 71 | ||
| 72 | $this->body = $message; |
|
| 73 | } |
|
| 74 | ||
| 75 | /** |
|
| 76 | * Returns the Notification Id |
|
| 77 | * |
|
| 78 | * @return int|string |
|
| 79 | */ |
|
| 80 | public function getId() |
|
| 81 | { |
|
| 82 | return $this->id; |
|
| 83 | } |
|
| 84 | ||
| 85 | /** |
|
| 86 | * Returns the Notification Body |
|
| 87 | * |
|
| 88 | * @return string|array |
|
| 89 | */ |
|
| 90 | public function getBody() |
|
| 91 | { |
|
| 92 | return $this->body; |
|
| 93 | } |
|
| 94 | ||
| 95 | /** |
|
| 96 | * Returns the Notification Metadata |
|
| 97 | * |
|
| 98 | * @return ArrayCollection |
|
| 99 | */ |
|
| 100 | public function getMetadata() |
|
| 101 | { |
|
| 102 | return $this->metadata; |
|
| 103 | } |
|
| 104 | } |
|
| 105 | ||