1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* T3Bot. |
4
|
|
|
* |
5
|
|
|
* @author Frank Nägler <[email protected]> |
6
|
|
|
* |
7
|
|
|
* @link http://www.t3bot.de |
8
|
|
|
* @link http://wiki.typo3.org/T3Bot |
9
|
|
|
*/ |
10
|
|
|
namespace T3Bot\Slack; |
11
|
|
|
|
12
|
|
|
use T3Bot\Slack\Message\Attachment; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class Message. |
16
|
|
|
*/ |
17
|
|
|
class Message |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* The text so be send. |
21
|
|
|
* |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
protected $text; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* The URL for the avatar image. |
28
|
|
|
* |
29
|
|
|
* @var string |
30
|
|
|
*/ |
31
|
|
|
protected $icon_emoji = ''; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var array<T3Bot\Slack\Message\Attachment> |
35
|
|
|
*/ |
36
|
|
|
protected $attachments = []; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Constructor for a message. |
40
|
|
|
* |
41
|
|
|
* @param array $data |
42
|
|
|
*/ |
43
|
28 |
|
public function __construct(array $data = []) |
44
|
|
|
{ |
45
|
28 |
|
foreach ($data as $property => $value) { |
46
|
1 |
|
if (property_exists($this, $property)) { |
47
|
1 |
|
$this->$property = $value; |
48
|
|
|
} |
49
|
|
|
} |
50
|
28 |
|
if ($this->icon_emoji === '') { |
51
|
27 |
|
$this->icon_emoji = $GLOBALS['config']['slack']['botAvatar']; |
52
|
|
|
} |
53
|
28 |
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @return string |
57
|
|
|
*/ |
58
|
5 |
|
public function getText() : string |
59
|
|
|
{ |
60
|
5 |
|
return $this->text; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param string $text |
65
|
|
|
*/ |
66
|
28 |
|
public function setText($text) |
67
|
|
|
{ |
68
|
28 |
|
$this->text = $text; |
69
|
28 |
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return string |
73
|
|
|
*/ |
74
|
1 |
|
public function getIconEmoji() : string |
75
|
|
|
{ |
76
|
1 |
|
return $this->icon_emoji; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param string $icon_emoji |
81
|
|
|
*/ |
82
|
1 |
|
public function setIconEmoji($icon_emoji) |
83
|
|
|
{ |
84
|
1 |
|
$this->icon_emoji = $icon_emoji; |
85
|
1 |
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return array |
89
|
|
|
*/ |
90
|
15 |
|
public function getAttachments() : array |
91
|
|
|
{ |
92
|
15 |
|
return $this->attachments; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @param array $attachments |
97
|
|
|
*/ |
98
|
1 |
|
public function setAttachments($attachments) |
99
|
|
|
{ |
100
|
1 |
|
$this->attachments = $attachments; |
101
|
1 |
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @param Attachment $attachment |
105
|
|
|
*/ |
106
|
27 |
|
public function addAttachment(Attachment $attachment) |
107
|
|
|
{ |
108
|
27 |
|
$this->attachments[] = $attachment; |
109
|
27 |
|
} |
110
|
|
|
} |
111
|
|
|
|