-
Notifications
You must be signed in to change notification settings - Fork 15
/
APNSBase.php
112 lines (99 loc) · 2.77 KB
/
APNSBase.php
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
/**
* APNSBase
* Basic Settings and Commands for Feedback and Push Service
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @author Sebastian Borggrewe <me@sebastianborggrewe.de>
* @since 2010/01/14
* @package APNP
*/
class APNSBase {
/**
* Defines wether Push Notification should be send
* in test mode while developing or in production
* mode when the app is released.
* Possible values:
* $_ENVIROMENT['development'] or $_ENVIROMENT['production']
*
* @var string
*/
protected $_enviroment = 'development';
/**
* Path to the private key file
*
* @var string
*/
protected $_privateKey = '';
/**
* Passphrase for the private key
* If you set a passphrase when you generated
* the private key you need to set it.
* Otherwise leave the passphrase blank.
*
* @var string
*/
protected $_privateKeyPassphrase = '';
/**
* Initializes a Push Notification with an
* enviroment.
* Valid values: development, production
*
* @param string $enviroment (production or developement)
*/
public function __construct($enviroment)
{
if($enviroment !== 'development' && $enviroment !== 'production')
throw new Exception('The Enviroment needs to be set to either development oder production');
$this->_enviroment = $enviroment;
}
/**
* Path to the private key file generated by
* Apple
*
* @param string $privateKey
*/
public function setPrivateKey($privateKey)
{
# Only accepts valid files
if($this->_checkPrivateKey($privateKey) === false)
throw new Exception('The Path to the private key is invalid.');
$this->_privateKey = $privateKey;
}
/**
* Passphrase for the specified private key
*
* @param string $privateKeyPassphrase
*/
public function setPrivateKeyPassphrase($privateKeyPassphrase)
{
$this->_privateKeyPassphrase = $privateKeyPassphrase;
}
/**
* Checks wether the private Key
* is a valid file
*
* @param string $privateKey
* @return bool
*/
protected function _checkPrivateKey($privateKey)
{
if(trim($privateKey) !== '' && file_exists($privateKey))
return true;
else
return false;
}
}
?>