Skip to content

Commit be39cf2

Browse files
Documentation
1 parent bce79ba commit be39cf2

File tree

2 files changed

+85
-19
lines changed

2 files changed

+85
-19
lines changed

config/androidfcm.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@
2525
|
2626
*/
2727

28-
$config['fcm_url'] = 'https://fcm.googleapis.com/fcm/send';
28+
$config['fcm_url'] = 'https://fcm.googleapis.com/fcm/send';

library/Fcm.php

+84-18
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,93 @@
11
<?php
22
defined('BASEPATH') or exit('No direct script access allowed');
33

4+
/**
5+
* FCM simple server side implementation in PHP
6+
*
7+
* @author Abhishek
8+
*/
49
class Fcm
510
{
611

7-
// push message title
12+
/** @var string push message title */
813
private $title;
14+
15+
/** @var string message */
916
private $message;
17+
18+
/** @var string URL String */
1019
private $image;
11-
// push message payload
20+
21+
/** @var array Custom payload */
1222
private $data;
13-
// flag indicating whether to show the push
14-
// notification or not
15-
// this flag will be useful when perform some opertation
16-
// in background when push is recevied
17-
private $is_background;
1823

19-
public function __construct()
20-
{
24+
/**
25+
* flag indicating whether to show the push notification or not
26+
* this flag will be useful when perform some opertation
27+
* in background when push is recevied
28+
*/
2129

22-
}
30+
/** @var bool set background or not */
31+
private $is_background;
2332

33+
/**
34+
* Function to set the title
35+
*
36+
* @param string $title The title of the push message
37+
*/
2438
public function setTitle($title)
2539
{
2640
$this->title = $title;
2741
}
2842

43+
/**
44+
* Function to set the message
45+
*
46+
* @param string $message Message
47+
*/
2948
public function setMessage($message)
3049
{
3150
$this->message = $message;
3251
}
3352

53+
/**
54+
* Function to set the image (optional)
55+
*
56+
* @param string $imageUrl URI string of image
57+
*/
3458
public function setImage($imageUrl)
3559
{
3660
$this->image = $imageUrl;
3761
}
3862

63+
/**
64+
* Function to set the custom payload (optional)
65+
*
66+
* eg:
67+
* $payload = array('user' => 'user1');
68+
*
69+
* @param array $data Custom data array
70+
*/
3971
public function setPayload($data)
4072
{
4173
$this->data = $data;
4274
}
4375

76+
/**
77+
* Function to specify if is set background (optional)
78+
*
79+
* @param bool $is_background
80+
*/
4481
public function setIsBackground($is_background)
4582
{
4683
$this->is_background = $is_background;
4784
}
4885

49-
/*
50-
Generating the push message array
51-
*/
86+
/**
87+
* Generating the push message array
88+
*
89+
* @return array array of the push notification data to be send
90+
*/
5291
public function getPush()
5392
{
5493
$res = array();
@@ -61,7 +100,14 @@ public function getPush()
61100
return $res;
62101
}
63102

64-
// sending push message to single user by firebase reg id
103+
/**
104+
* Function to send notification to a single device
105+
*
106+
* @param string $to registration id of device (device token)
107+
* @param array $message push notification array returned from getPush()
108+
*
109+
* @return array array of notification data and to address
110+
*/
65111
public function send($to, $message)
66112
{
67113
$fields = array(
@@ -71,7 +117,14 @@ public function send($to, $message)
71117
return $this->sendPushNotification($fields);
72118
}
73119

74-
// Sending message to a topic by topic name
120+
/**
121+
* Function to send notification to a topic by topic name
122+
*
123+
* @param string $to topic
124+
* @param array $message push notification array returned from getPush()
125+
*
126+
* @return array array of notification data and to address (topic)
127+
*/
75128
public function sendToTopic($to, $message)
76129
{
77130
$fields = array(
@@ -81,7 +134,14 @@ public function sendToTopic($to, $message)
81134
return $this->sendPushNotification($fields);
82135
}
83136

84-
// sending push message to multiple users by firebase registration ids
137+
/**
138+
* Function to send notification to multiple users by firebase registration ids
139+
*
140+
* @param array $to array of registration ids of devices (device tokens)
141+
* @param array $message push notification array returned from getPush()
142+
*
143+
* @return array array of notification data and to addresses
144+
*/
85145
public function sendMultiple($registration_ids, $message)
86146
{
87147
$fields = array(
@@ -92,11 +152,17 @@ public function sendMultiple($registration_ids, $message)
92152
return $this->sendPushNotification($fields);
93153
}
94154

95-
// function makes curl request to firebase servers
155+
/**
156+
* Function makes curl request to firebase servers
157+
*
158+
* @param array $fields array of registration ids of devices (device tokens)
159+
*
160+
* @return string returns result from FCM server as json
161+
*/
96162
private function sendPushNotification($fields)
97163
{
98164

99-
$CI =& get_instance();
165+
$CI = &get_instance();
100166
$CI->load->config('androidfcm'); //loading of config file
101167

102168
// Set POST variables

0 commit comments

Comments
 (0)