Skip to content

Commit f907bf1

Browse files
committed
Add support for dismissal-date also
1 parent 31b9283 commit f907bf1

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/Payload.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class Payload implements \JsonSerializable
4747
const PAYLOAD_RELEVANCE_SCORE_KEY = 'relevance-score';
4848
const PAYLOAD_STALE_DATE_KEY = 'stale-date';
4949
const PAYLOAD_CONTENT_STATE_KEY = 'content-state';
50+
const PAYLOAD_DISMISSAL_DATE_KEY = 'dismissal-date';
5051
const PAYLOAD_ATTRIBUTES_TYPE_KEY = 'attributes-type';
5152
const PAYLOAD_ATTRIBUTES_KEY = 'attributes';
5253

@@ -185,6 +186,13 @@ class Payload implements \JsonSerializable
185186
*/
186187
private $attributes = [];
187188

189+
/**
190+
* Dismissal date
191+
*
192+
* @var int|null
193+
*/
194+
private $dismissalDate;
195+
188196
protected function __construct()
189197
{
190198
}
@@ -672,6 +680,18 @@ public function getAttributes(): array
672680
return $this->attributes;
673681
}
674682

683+
public function setDismissalDate(int $value): Payload
684+
{
685+
$this->dismissalDate = $value;
686+
687+
return $this;
688+
}
689+
690+
public function getDismissalDate(): int|null
691+
{
692+
return $this->dismissalDate;
693+
}
694+
675695
/**
676696
* Convert Payload to JSON.
677697
*
@@ -765,6 +785,10 @@ public function jsonSerialize(): array
765785
$payload[self::PAYLOAD_ROOT_KEY]->{self::PAYLOAD_RELEVANCE_SCORE_KEY} = $this->relevanceScore;
766786
}
767787

788+
if ($this->dismissalDate) {
789+
$payload[self::PAYLOAD_ROOT_KEY]->{self::PAYLOAD_DISMISSAL_DATE_KEY} = (int) $this->getDismissalDate();
790+
}
791+
768792
if ($this->attributesType) {
769793
$payload[self::PAYLOAD_ROOT_KEY]->{self::PAYLOAD_ATTRIBUTES_TYPE_KEY} = $this->attributesType;
770794
$payload[self::PAYLOAD_ROOT_KEY]->{self::PAYLOAD_ATTRIBUTES_KEY} = $this->attributes;

tests/PayloadTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,23 @@ public function testGetCustomValueOfNotExistingKey()
103103
->getCustomValue('notExistingKey', 'value');
104104
}
105105

106+
public function testSetDismissalDate()
107+
{
108+
$payload = Payload::create()->setDismissalDate(123456789);
109+
110+
$this->assertEquals(123456789, $payload->getDismissalDate());
111+
}
112+
113+
public function testDismissalDateJson()
114+
{
115+
$payload = Payload::create()
116+
->setDismissalDate(123456789);
117+
$this->assertJsonStringEqualsJsonString(
118+
'{"aps":{"dismissal-date":123456789}}',
119+
$payload->toJson()
120+
);
121+
}
122+
106123
public function testSetAttributesType()
107124
{
108125
$payload = Payload::create()->setAttributesType('attributesType');

0 commit comments

Comments
 (0)