Skip to content
This repository was archived by the owner on Jun 28, 2024. It is now read-only.

Commit a00ae76

Browse files
alireza setayeshalireza setayesh
alireza setayesh
authored and
alireza setayesh
committed
add support for images
1 parent 71fad7c commit a00ae76

File tree

3 files changed

+49
-4
lines changed

3 files changed

+49
-4
lines changed

src/Message/PayloadNotification.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ class PayloadNotification implements Arrayable
3737
*/
3838
protected $icon;
3939

40+
/**
41+
* @internal
42+
*
43+
* @var null|string
44+
*/
45+
protected $image;
46+
4047
/**
4148
* @internal
4249
*
@@ -111,6 +118,7 @@ public function __construct(PayloadNotificationBuilder $builder)
111118
$this->body = $builder->getBody();
112119
$this->channelId = $builder->getChannelId();
113120
$this->icon = $builder->getIcon();
121+
$this->image = $builder->getImage();
114122
$this->sound = $builder->getSound();
115123
$this->badge = $builder->getBadge();
116124
$this->tag = $builder->getTag();
@@ -134,6 +142,7 @@ public function toArray()
134142
'body' => $this->body,
135143
'android_channel_id' => $this->channelId,
136144
'icon' => $this->icon,
145+
'image' => $this->image,
137146
'sound' => $this->sound,
138147
'badge' => $this->badge,
139148
'tag' => $this->tag,

src/Message/PayloadNotificationBuilder.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ class PayloadNotificationBuilder
3232
*/
3333
protected $icon;
3434

35+
/**
36+
* @internal
37+
*
38+
* @var null|string
39+
*/
40+
protected $image;
41+
3542
/**
3643
* @internal
3744
*
@@ -170,6 +177,21 @@ public function setIcon($icon)
170177
return $this;
171178
}
172179

180+
/**
181+
* Indicates the image that can be displayed in the notification
182+
* Supports an url or internal image.
183+
*
184+
* @param $image
185+
*
186+
* @return PayloadNotificationBuilder current instance of the builder
187+
*/
188+
public function setImage($image)
189+
{
190+
$this->image = $image;
191+
192+
return $this;
193+
}
194+
173195
/**
174196
* Indicates a sound to play when the device receives a notification.
175197
* Supports default or the filename of a sound resource bundled in the app.
@@ -345,6 +367,16 @@ public function getIcon()
345367
return $this->icon;
346368
}
347369

370+
/**
371+
* Get Image.
372+
*
373+
* @return string|null
374+
*/
375+
public function getImage()
376+
{
377+
return $this->image;
378+
}
379+
348380
/**
349381
* Get Sound.
350382
*

tests/MessageTest.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ public function it_construct_a_valid_json_with_notification()
8585
"title":"test_title",
8686
"body":"test_body",
8787
"badge":"test_badge",
88-
"sound":"test_sound"
88+
"sound":"test_sound",
89+
"image":"test_image"
8990
}';
9091

9192
$targetFull = '{
@@ -101,15 +102,17 @@ public function it_construct_a_valid_json_with_notification()
101102
"body_loc_args":"[ body0, body1 ]",
102103
"title_loc_key":"test_title_key",
103104
"title_loc_args":"[ title0, title1 ]",
104-
"icon":"test_icon"
105+
"icon":"test_icon",
106+
"image":"test_image"
105107
}';
106108

107109
$notificationBuilder = new PayloadNotificationBuilder();
108110

109111
$notificationBuilder->setTitle('test_title')
110112
->setBody('test_body')
111113
->setSound('test_sound')
112-
->setBadge('test_badge');
114+
->setBadge('test_badge')
115+
->setImage('test_image');
113116

114117
$json = json_encode($notificationBuilder->build()->toArray());
115118
$this->assertJsonStringEqualsJsonString($targetPartial, $json);
@@ -123,7 +126,8 @@ public function it_construct_a_valid_json_with_notification()
123126
->setBodyLocationArgs('[ body0, body1 ]')
124127
->setTitleLocationKey('test_title_key')
125128
->setTitleLocationArgs('[ title0, title1 ]')
126-
->setIcon('test_icon');
129+
->setIcon('test_icon')
130+
->setImage('test_image');
127131

128132
$json = json_encode($notificationBuilder->build()->toArray());
129133
$this->assertJsonStringEqualsJsonString($targetFull, $json);

0 commit comments

Comments
 (0)