Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions GCMPushMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,28 @@
http://stackoverflow.com/questions/11242743/gcm-with-php-google-cloud-messaging

*/
class GCMPushMessage {
class GCMPushMessage
{

var $url = 'https://android.googleapis.com/gcm/send';
var $serverApiKey = "";
var $devices = array();
private $url = 'https://android.googleapis.com/gcm/send';
private $serverApiKey = "";
private $devices = array();

/*
Constructor
@param $apiKeyIn the server API key
*/
function GCMPushMessage($apiKeyIn){
public function __construct($apiKeyIn)
{
$this->serverApiKey = $apiKeyIn;
}

/*
Set the devices to send to
@param $deviceIds array of device tokens to send to
*/
function setDevices($deviceIds){
public function setDevices($deviceIds)
{

if(is_array($deviceIds)){
$this->devices = $deviceIds;
Expand All @@ -52,7 +55,8 @@ function setDevices($deviceIds){
@param $message The message to send
@param $data Array of data to accompany the message
*/
function send($message, $data = false){
public function send($message, $data = false)
{

if(!is_array($this->devices) || count($this->devices) == 0){
$this->error("No devices set");
Expand Down Expand Up @@ -103,7 +107,8 @@ function send($message, $data = false){
return $result;
}

function error($msg){
private function error($msg)
{
echo "Android send notification failed with error:";
echo "\t" . $msg;
exit(1);
Expand Down