|
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\Message\Type; |
|
11
|
|
|
|
|
12
|
|
|
use Zbox\UnifiedPush\Exception\InvalidArgumentException; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class MPNSRaw |
|
16
|
|
|
* @package Zbox\UnifiedPush\Message\Type |
|
17
|
|
|
*/ |
|
18
|
|
|
class MPNSRaw extends MPNSBase |
|
19
|
|
|
{ |
|
20
|
|
|
const MESSAGE_TYPE = 'raw'; |
|
21
|
|
|
|
|
22
|
|
|
const DELAY_INTERVAL_IMMEDIATE = 3; |
|
23
|
|
|
const DELAY_INTERVAL_450 = 13; |
|
24
|
|
|
const DELAY_INTERVAL_900 = 23; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Custom payload parameters |
|
28
|
|
|
* |
|
29
|
|
|
* @var array |
|
30
|
|
|
*/ |
|
31
|
|
|
private $_payload; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param array $data |
|
35
|
|
|
*/ |
|
36
|
|
|
public function __construct(array $data = array()) |
|
37
|
|
|
{ |
|
38
|
|
|
$this->setMessageIdentifier(uniqid()); |
|
39
|
|
|
$this->recipientCollection = new \ArrayIterator(); |
|
40
|
|
|
|
|
41
|
|
|
foreach ($data as $key => $value) { |
|
42
|
|
|
$this->$key = $value; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
return $this; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* {@inheritdoc} |
|
50
|
|
|
*/ |
|
51
|
|
|
public function createPayload() |
|
52
|
|
|
{ |
|
53
|
|
|
$message = new \DOMDocument("1.0", "utf-8"); |
|
54
|
|
|
$baseElement = $message->createElement("wp:Notification"); |
|
55
|
|
|
$baseElement->setAttribute("xmlns:wp", "WPNotification"); |
|
56
|
|
|
$message->appendChild($baseElement); |
|
57
|
|
|
|
|
58
|
|
|
$rootElement = $message->createElement("root"); |
|
59
|
|
|
$baseElement->appendChild($rootElement); |
|
60
|
|
|
|
|
61
|
|
|
foreach ($this->_payload as $key => $value) { |
|
62
|
|
|
$element = $message->createElement($key, $value); |
|
63
|
|
|
$rootElement->appendChild($element); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
return $message; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @param string $name |
|
71
|
|
|
*/ |
|
72
|
|
|
public function __get($name) |
|
73
|
|
|
{ |
|
74
|
|
|
if (empty($this->_payload[$name])) { |
|
75
|
|
|
throw new InvalidArgumentException(sprintf("Payload parameter '%s' is not defined", $name)); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
return $this->_payload[$name]; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @param string $name |
|
83
|
|
|
* @param mixed $value |
|
84
|
|
|
*/ |
|
85
|
|
|
public function __set($name, $value) |
|
86
|
|
|
{ |
|
87
|
|
|
$this->_payload[$name] = htmlspecialchars($value); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|