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\Utils\ClientCredentials\CredentialsInterface; |
13
|
|
|
use Zbox\UnifiedPush\Utils\ClientCredentials\DTO\AuthToken; |
14
|
|
|
use Zbox\UnifiedPush\Utils\ClientCredentials\DTO\SSLCertificate; |
15
|
|
|
use Zbox\UnifiedPush\Exception\DomainException; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class NotificationServices |
19
|
|
|
* @package Zbox\UnifiedPush\NotificationService |
20
|
|
|
*/ |
21
|
|
|
class NotificationServices |
22
|
|
|
{ |
23
|
|
|
const APPLE_PUSH_NOTIFICATIONS_SERVICE = 'APNS'; |
24
|
|
|
const GOOGLE_CLOUD_MESSAGING = 'GCM'; |
25
|
|
|
const MICROSOFT_PUSH_NOTIFICATIONS_SERVICE = 'MPNS'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Checks if notification service is supported |
29
|
|
|
* |
30
|
|
|
* @param string $serviceName |
31
|
|
|
* @return string |
32
|
|
|
* @throws DomainException |
33
|
|
|
*/ |
34
|
|
|
public static function validateServiceName($serviceName) |
35
|
|
|
{ |
36
|
|
|
if (!in_array($serviceName, array( |
37
|
|
|
self::APPLE_PUSH_NOTIFICATIONS_SERVICE, |
38
|
|
|
self::GOOGLE_CLOUD_MESSAGING, |
39
|
|
|
self::MICROSOFT_PUSH_NOTIFICATIONS_SERVICE, |
40
|
|
|
))) { |
41
|
|
|
throw new DomainException(sprintf("Notification service '%s' is not supported.", $serviceName)); |
42
|
|
|
} |
43
|
|
|
return $serviceName; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param string $serviceName |
48
|
|
|
* @return CredentialsInterface |
49
|
|
|
*/ |
50
|
|
|
public static function getCredentialsTypeByService($serviceName) |
51
|
|
|
{ |
52
|
|
|
self::validateServiceName($serviceName); |
53
|
|
|
|
54
|
|
|
$credentials = array( |
55
|
|
|
self::APPLE_PUSH_NOTIFICATIONS_SERVICE => new SSLCertificate(), |
56
|
|
|
self::GOOGLE_CLOUD_MESSAGING => new AuthToken(), |
57
|
|
|
self::MICROSOFT_PUSH_NOTIFICATIONS_SERVICE => new SSLCertificate() |
58
|
|
|
); |
59
|
|
|
|
60
|
|
|
return $credentials[$serviceName]; |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|