1 | <?php |
||
2 | defined('BASEPATH') OR exit('No direct script access allowed'); |
||
3 | |||
4 | class Message |
||
5 | { |
||
6 | /** |
||
7 | * [protected description] |
||
8 | * @var [type] |
||
0 ignored issues
–
show
Documentation
Bug
introduced
by
![]() |
|||
9 | */ |
||
10 | protected $message; |
||
11 | |||
12 | public function __construct($jsonString) |
||
13 | { |
||
14 | $this->message = json_decode($jsonString); |
||
15 | } |
||
16 | /** |
||
17 | * [__get description] |
||
18 | * @date 2019-11-23 |
||
19 | * @param string $key [description] |
||
20 | * @return [type] [description] |
||
0 ignored issues
–
show
|
|||
21 | */ |
||
22 | public function __get(string $key):string |
||
23 | { |
||
24 | return $this->message->{$key}; |
||
25 | } |
||
26 | /** |
||
27 | * [header description] |
||
28 | * @date 2019-11-22 |
||
29 | * @param string $key [description] |
||
30 | * @return string|null [description] |
||
31 | */ |
||
32 | public function header(string $key):?string |
||
33 | { |
||
34 | foreach ($this->message->payload->headers as $header) { |
||
35 | if ($header->name == $key) { |
||
36 | return $header->value; |
||
37 | } |
||
38 | } |
||
39 | return null; |
||
40 | } |
||
41 | /** |
||
42 | * [isMultiPart description] |
||
43 | * @date 2019-11-23 |
||
44 | * @return bool [description] |
||
45 | */ |
||
46 | public function isMultiPart():bool |
||
47 | { |
||
48 | return isset($this->message->payload->parts); |
||
49 | } |
||
50 | /** |
||
51 | * [getSize description] |
||
52 | * @date 2019-11-23 |
||
53 | * @return int [description] |
||
54 | */ |
||
55 | public function getSize():int |
||
56 | { |
||
57 | return $this->message->payload->body->size; |
||
58 | } |
||
59 | /** |
||
60 | * [body description] |
||
61 | * @date 2019-11-23 |
||
62 | * @param integer $partId [description] |
||
63 | * @return [type] [description] |
||
0 ignored issues
–
show
|
|||
64 | */ |
||
65 | public function body(int $partId=0) |
||
66 | { |
||
67 | if ($this->isMultiPart()) { |
||
68 | // Set Parent ID. |
||
69 | $this->message->payload->parts[$partId]->id = $this->message->id; |
||
70 | |||
71 | return new MessagePart($this->message->payload->parts[$partId]); |
||
72 | } |
||
73 | |||
74 | return base64url_decode($this->message->payload->body->data); |
||
75 | } |
||
76 | } |
||
77 |