1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* (c) Alexander Zhukov <[email protected]> |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Zbox\UnifiedPush\NotificationService; |
11
|
|
|
|
12
|
|
|
use Zbox\UnifiedPush\Exception\InvalidArgumentException; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class ServiceClientBase |
16
|
|
|
* @package Zbox\UnifiedPush\NotificationService |
17
|
|
|
*/ |
18
|
|
|
abstract class ServiceClientBase implements ServiceClientInterface |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var array |
22
|
|
|
*/ |
23
|
|
|
protected $serviceURL; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var CredentialsInterface |
27
|
|
|
*/ |
28
|
|
|
protected $credentials; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var array |
32
|
|
|
*/ |
33
|
|
|
protected $notification; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var mixed |
37
|
|
|
*/ |
38
|
|
|
protected $serviceClient; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param array $serviceUrl |
42
|
|
|
* @param CredentialsInterface $credentials |
43
|
|
|
*/ |
44
|
|
|
public function __construct($serviceUrl, CredentialsInterface $credentials) |
45
|
|
|
{ |
46
|
|
|
$this->setServiceURL($serviceUrl); |
47
|
|
|
$this->setCredentials($credentials); |
48
|
|
|
|
49
|
|
|
$this->createClient(); |
50
|
|
|
|
51
|
|
|
return $this; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
abstract protected function createClient(); |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param array $serviceURL |
58
|
|
|
* @return $this |
59
|
|
|
*/ |
60
|
|
|
public function setServiceURL($serviceURL) |
61
|
|
|
{ |
62
|
|
|
$this->serviceURL = $serviceURL; |
63
|
|
|
return $this; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return array |
68
|
|
|
*/ |
69
|
|
|
public function getServiceURL() |
70
|
|
|
{ |
71
|
|
|
return $this->serviceURL; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @param CredentialsInterface $credentials |
76
|
|
|
* @return $this |
77
|
|
|
*/ |
78
|
|
|
public function setCredentials(CredentialsInterface $credentials) |
79
|
|
|
{ |
80
|
|
|
$this->credentials = $credentials; |
81
|
|
|
return $this; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @return CredentialsInterface |
86
|
|
|
*/ |
87
|
|
|
public function getCredentials() |
88
|
|
|
{ |
89
|
|
|
return $this->credentials; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @param array $notification |
94
|
|
|
* @return $this |
95
|
|
|
*/ |
96
|
|
|
public function setNotification($notification) |
97
|
|
|
{ |
98
|
|
|
$this->notification = $notification; |
99
|
|
|
return $this; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @return array |
104
|
|
|
*/ |
105
|
|
|
public function getNotificationOrThrowException() |
106
|
|
|
{ |
107
|
|
|
if (empty($this->notification)) { |
108
|
|
|
throw new InvalidArgumentException('Missing notification'); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
return $this->notification; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @return mixed |
116
|
|
|
*/ |
117
|
|
|
public function getClientConnection() |
118
|
|
|
{ |
119
|
|
|
return $this->serviceClient; |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|