1 | <?php |
||
9 | class MessageBuilder implements BuilderInterface |
||
10 | { |
||
11 | private $data = []; |
||
12 | private $attachments; |
||
13 | private $attachmentBuilder; |
||
14 | |||
15 | /** |
||
16 | * Constructor. |
||
17 | */ |
||
18 | 9 | public function __construct() |
|
22 | |||
23 | /** |
||
24 | * @throws \LogicException When create is called before text has been set |
||
25 | */ |
||
26 | 4 | public function create() |
|
27 | { |
||
28 | 4 | $message = new Message( |
|
29 | 4 | isset($this->data['text']) ? $this->data['text'] : null, |
|
30 | 4 | isset($this->data['channel']) ? $this->data['channel'] : null, |
|
31 | 4 | isset($this->data['username']) ? $this->data['username'] : null, |
|
32 | 4 | isset($this->data['icon_emoji']) ? $this->data['icon_emoji'] : null |
|
33 | ); |
||
34 | |||
35 | 4 | $message['attachments'] = clone $this->attachments; |
|
36 | |||
37 | 4 | $this->refresh(); |
|
38 | |||
39 | 4 | return $message; |
|
40 | } |
||
41 | |||
42 | /** |
||
43 | * @param string $text |
||
44 | * |
||
45 | * @return $this |
||
46 | */ |
||
47 | 5 | public function setText($text) |
|
53 | |||
54 | /** |
||
55 | * @param $channel |
||
56 | * |
||
57 | * @return $this |
||
58 | */ |
||
59 | 2 | public function setChannel($channel) |
|
65 | |||
66 | /** |
||
67 | * @param $iconEmoji |
||
68 | * |
||
69 | * @return $this |
||
70 | */ |
||
71 | 1 | public function setIconEmoji($iconEmoji) |
|
77 | |||
78 | /** |
||
79 | * @param $username |
||
80 | * |
||
81 | * @return $this |
||
82 | */ |
||
83 | 1 | public function setUsername($username) |
|
89 | |||
90 | /** |
||
91 | * Reset data to an empty message. |
||
92 | */ |
||
93 | 4 | protected function refresh() |
|
98 | |||
99 | /** |
||
100 | * @param AttachmentInterface $attachment |
||
101 | * |
||
102 | * @return $this |
||
103 | */ |
||
104 | 2 | public function addAttachment(AttachmentInterface $attachment) |
|
110 | |||
111 | /** |
||
112 | * @return AttachmentBuilder |
||
113 | */ |
||
114 | 1 | public function createAttachment() |
|
122 | } |
||
123 |