blob: 15d634f3652b350088c729a61e897465d3368012 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
<?php
declare(strict_types=1);
/*
* This file is part of the WebPush library.
*
* (c) Louis Lagrange <lagrange.louis@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Minishlink\WebPush;
class Notification
{
/** @var SubscriptionInterface */
private $subscription;
/** @var null|string */
private $payload;
/** @var array Options : TTL, urgency, topic */
private $options;
/** @var array Auth details : GCM, VAPID */
private $auth;
/**
* Notification constructor.
*
* @param SubscriptionInterface $subscription
* @param null|string $payload
* @param array $options
* @param array $auth
*/
public function __construct(SubscriptionInterface $subscription, ?string $payload, array $options, array $auth)
{
$this->subscription = $subscription;
$this->payload = $payload;
$this->options = $options;
$this->auth = $auth;
}
/**
* @return SubscriptionInterface
*/
public function getSubscription(): SubscriptionInterface
{
return $this->subscription;
}
/**
* @return null|string
*/
public function getPayload(): ?string
{
return $this->payload;
}
/**
* @param array $defaultOptions
*
* @return array
*/
public function getOptions(array $defaultOptions = []): array
{
$options = $this->options;
$options['TTL'] = array_key_exists('TTL', $options) ? $options['TTL'] : $defaultOptions['TTL'];
$options['urgency'] = array_key_exists('urgency', $options) ? $options['urgency'] : $defaultOptions['urgency'];
$options['topic'] = array_key_exists('topic', $options) ? $options['topic'] : $defaultOptions['topic'];
return $options;
}
/**
* @param array $defaultAuth
*
* @return array
*/
public function getAuth(array $defaultAuth): array
{
return count($this->auth) > 0 ? $this->auth : $defaultAuth;
}
}
|