Skip to content

Commit 3a42047

Browse files
committed
Merge pull request #14 from Leenug/add_image_to_attachment
Add image_url to attachment
2 parents b9e6938 + b05f0d8 commit 3a42047

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

src/Attachment.php

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ class Attachment {
1818
*/
1919
protected $text;
2020

21+
/**
22+
* Optional image that should appear within the attachment
23+
*
24+
* @var string
25+
*/
26+
protected $image_url;
27+
2128
/**
2229
* Optional text that should appear above the formatted data
2330
*
@@ -59,6 +66,8 @@ public function __construct(array $attributes)
5966

6067
if (isset($attributes['text'])) $this->setText($attributes['text']);
6168

69+
if (isset($attributes['image_url'])) $this->setImageUrl($attributes['image_url']);
70+
6271
if (isset($attributes['pretext'])) $this->setPretext($attributes['pretext']);
6372

6473
if (isset($attributes['color'])) $this->setColor($attributes['color']);
@@ -114,6 +123,29 @@ public function setText($text)
114123
return $this;
115124
}
116125

126+
/**
127+
* Get the optional image to appear within the attachment
128+
*
129+
* @return string
130+
*/
131+
public function getImageUrl()
132+
{
133+
return $this->image_url;
134+
}
135+
136+
/**
137+
* Set the optional image to appear within the attachment
138+
*
139+
* @param string $image_url
140+
* @return $this
141+
*/
142+
public function setImageUrl($image_url)
143+
{
144+
$this->image_url = $image_url;
145+
146+
return $this;
147+
}
148+
117149
/**
118150
* Get the text that should appear above the formatted data
119151
*
@@ -262,7 +294,8 @@ public function toArray()
262294
'text' => $this->getText(),
263295
'pretext' => $this->getPretext(),
264296
'color' => $this->getColor(),
265-
'mrkdwn_in' => $this->getMarkdownFields()
297+
'mrkdwn_in' => $this->getMarkdownFields(),
298+
'image_url' => $this->getImageUrl()
266299
];
267300

268301
$data['fields'] = $this->getFieldsAsArrays();

tests/AttachmentUnitTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public function testAttachmentToArray()
6666
'pretext' => 'Pretext',
6767
'color' => 'bad',
6868
'mrkdwn_in' => ['pretext', 'text'],
69+
'image_url' => 'http://fake.host/image.png',
6970
'fields' => [
7071
[
7172
'title' => 'Title 1',

tests/ClientFunctionalTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public function testMessageWithAttachments()
3535
'pretext' => null,
3636
'color' => 'bad',
3737
'mrkdwn_in' => ['pretext', 'text'],
38+
'image_url' => 'http://fake.host/image.png',
3839
'fields' => []
3940
];
4041

@@ -73,6 +74,7 @@ public function testMessageWithAttachmentsAndFields()
7374
'pretext' => null,
7475
'color' => 'bad',
7576
'mrkdwn_in' => [],
77+
'image_url' => 'http://fake.host/image.png',
7678
'fields' => [
7779
[
7880
'title' => 'Field 1',

0 commit comments

Comments
 (0)