Created
June 14, 2018 07:20
-
-
Save nguyenphuocnhatthanh/7e39c5365aed116aa448a15d5b2fb84a to your computer and use it in GitHub Desktop.
Abstact Notification Firebase
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Services\PushNotification; | |
use App\Services\DeviceToken; | |
use App\Services\FirebaseCloudMessage; | |
abstract class AbstractNotification | |
{ | |
/** | |
* @var FirebaseCloudMessage | |
*/ | |
private $firebase; | |
/** | |
* CommentPost constructor. | |
* @param FirebaseCloudMessage $firebaseCloudMessage | |
*/ | |
public function __construct(FirebaseCloudMessage $firebaseCloudMessage) | |
{ | |
$this->firebase = $firebaseCloudMessage; | |
} | |
/** | |
* Push notification for Android Platform | |
* | |
* @param $tokens | |
* @param array $params | |
*/ | |
protected function pushDeviceAndroid($tokens, array $params) | |
{ | |
/* @Object FireBaseCloudMessage */ | |
$this->setMessage($tokens, $params)->sendMessage(); | |
} | |
/** | |
* Push notification for IOS Platform | |
* | |
* @param $tokens | |
* @param array $params | |
*/ | |
protected function pushDeviceIOS($tokens, array $params) | |
{ | |
/* @Object FireBaseCloudMessage */ | |
$this->setMessage($tokens, $params)->sendMessageIOS(); | |
} | |
/** | |
* Push notification for multi platform | |
* | |
* @param DeviceToken $deviceToken | |
* @param array $params | |
*/ | |
protected function bulkPush($deviceToken, array $params) | |
{ | |
if ($tokens = $deviceToken->getTokenIOS()) { | |
$this->pushDeviceIOS($tokens, $params); | |
} | |
if ($tokens = $deviceToken->getTokenAndroid()) { | |
$this->pushDeviceAndroid($tokens, $params); | |
} | |
} | |
/** | |
* Set device token | |
* | |
* @param array $devices | |
* @return DeviceToken | |
*/ | |
protected function setDeviceToken(array $devices) | |
{ | |
$device = new DeviceToken($devices); | |
return $device->setTokenPlatform(); | |
} | |
/** | |
* @param $tokens | |
* @param array $params | |
* @internal param $notification | |
* @return FirebaseCloudMessage | |
*/ | |
protected function setMessage($tokens, array $params) | |
{ | |
$firebase = $this->firebase->setRegistrationIds($tokens) | |
->setNotification($params['notification']); | |
return $firebase; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment