Skip to content
This repository has been archived by the owner on Jun 6, 2021. It is now read-only.

WIP Separation of Bundle and Library #145

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
7 changes: 6 additions & 1 deletion Command/TestPushCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected function configure()
->setDescription("Sends a push command to a supplied push token'd device")
->addOption("badge", "b", InputOption::VALUE_OPTIONAL, "Badge number (for iOS devices)", 0)
->addOption("text", "t", InputOption::VALUE_OPTIONAL, "Text message")
->addArgument("service", InputArgument::REQUIRED, "One of 'ios', 'c2dm', 'gcm', 'mac', 'blackberry' or 'windowsphone'")
->addArgument("service", InputArgument::REQUIRED, "One of 'ios', 'c2dm', 'gcm', 'fcm', 'mac', 'blackberry' or 'windowsphone'")
->addArgument("token", InputArgument::REQUIRED, "Authentication token for the service")
->addArgument("payload", InputArgument::OPTIONAL, "The payload data to send (JSON)", '{"data": "test"}')
;
Expand Down Expand Up @@ -111,6 +111,11 @@ protected function getMessageClass($service)
$message = new PushMessage\AndroidMessage();
$message->setGCM(true);

return $message;
case "fcm":
$message = new PushMessage\AndroidMessage();
$message->setFCM(true);

return $message;
case "blackberry":
return new PushMessage\BlackberryMessage();
Expand Down
7 changes: 7 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ protected function addAndroid()
booleanNode("dry_run")->defaultFalse()->end()->
end()->
end()->
arrayNode("fcm")->
canBeUnset()->
children()->
scalarNode("api_key")->isRequired()->cannotBeEmpty()->end()->
booleanNode("use_multi_curl")->defaultValue(true)->end()->
end()->
end()->
end()->
end()->
end()
Expand Down
7 changes: 7 additions & 0 deletions DependencyInjection/RMSPushNotificationsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ protected function setAndroidConfig(array $config)
$this->container->setParameter("rms_push_notifications.android.gcm.use_multi_curl", $config["android"]["gcm"]["use_multi_curl"]);
$this->container->setParameter('rms_push_notifications.android.gcm.dry_run', $config["android"]["gcm"]["dry_run"]);
}

// FCM
$this->container->setParameter("rms_push_notifications.android.fcm.enabled", isset($config["android"]["fcm"]));
if (isset($config["android"]["fcm"])) {
$this->container->setParameter("rms_push_notifications.android.fcm.api_key", $config["android"]["fcm"]["api_key"]);
$this->container->setParameter("rms_push_notifications.android.fcm.use_multi_curl", $config["android"]["fcm"]["use_multi_curl"]);
}
}

/**
Expand Down
1 change: 1 addition & 0 deletions Device/Types.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class Types
{
const OS_ANDROID_C2DM = "rms_push_notifications.os.android.c2dm";
const OS_ANDROID_GCM = "rms_push_notifications.os.android.gcm";
const OS_ANDROID_FCM = "rms_push_notifications.os.android.fcm";
const OS_IOS = "rms_push_notifications.os.ios";
const OS_MAC = "rms_push_notifications.os.mac";
const OS_BLACKBERRY = "rms_push_notifications.os.blackberry";
Expand Down
78 changes: 77 additions & 1 deletion Message/AndroidMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ class AndroidMessage implements MessageInterface
*/
protected $isGCM = false;

/**
* Whether this is a FCM message
*
* @var bool
*/
protected $isFCM = false;

/**
* A collection of device identifiers that the message
* is intended for. GCM use only
Expand All @@ -58,6 +65,13 @@ class AndroidMessage implements MessageInterface
*/
protected $gcmOptions = array();

/**
* Options for FCM messages
*
* @var array
*/
protected $fcmOptions = array();

/**
* Sets the string message
*
Expand Down Expand Up @@ -136,7 +150,9 @@ public function setDeviceIdentifier($identifier)
*/
public function getTargetOS()
{
return ($this->isGCM ? Types::OS_ANDROID_GCM : Types::OS_ANDROID_C2DM);
if($this->isGCM) return Types::OS_ANDROID_GCM;
if($this->isFCM) return Types::OS_ANDROID_FCM;
return Types::OS_ANDROID_C2DM;
}

/**
Expand Down Expand Up @@ -192,6 +208,27 @@ public function isGCM()
return $this->isGCM;
}

/**
* Set whether this is a FCM message
* (default false)
*
* @param $fcm
*/
public function setFCM($fcm)
{
$this->isFCM = !!$fcm;
}

/**
* Returns whether this is a FCM message
*
* @return mixed
*/
public function isFCM()
{
return $this->isFCM;
}

/**
* Returns an array of device identifiers
* Not used in C2DM
Expand All @@ -212,6 +249,26 @@ public function addGCMIdentifier($identifier)
$this->allIdentifiers[$identifier] = $identifier;
}

/**
* Returns an array of device identifiers
* Not used in C2DM
*
* @return mixed
*/
public function getFCMIdentifiers()
{
return array_values($this->allIdentifiers);
}

/**
* Adds a device identifier to the FCM list
* @param string $identifier
*/
public function addFCMIdentifier($identifier)
{
$this->allIdentifiers[$identifier] = $identifier;
}

/**
* Sets the GCM list
* @param array $allIdentifiers
Expand All @@ -238,4 +295,23 @@ public function getGCMOptions()
{
return $this->gcmOptions;
}

/**
* Sets FCM options
* @param array $options
*/
public function setFCMOptions($options)
{
$this->fcmOptions = $options;
}

/**
* Returns FCM options
*
* @return array
*/
public function getFCMOptions()
{
return $this->fcmOptions;
}
}
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# RMSPushNotificationsBundle ![](https://secure.travis-ci.org/richsage/RMSPushNotificationsBundle.png)

A bundle to allow sending of push notifications to mobile devices. Currently supports Android (C2DM, GCM), Blackberry and iOS devices.
A bundle to allow sending of push notifications to mobile devices. Currently supports Android (C2DM, GCM, FCM), Blackberry and iOS devices.

## Installation

Expand Down Expand Up @@ -44,6 +44,9 @@ only be available if you provide configuration respectively for them.
api_key: <string_android_gcm_api_key> # This is titled "Server Key" when creating it
use_multi_curl: <boolean_android_gcm_use_multi_curl> # default is true
dry_run: <bool_use_gcm_dry_run>
fcm:
api_key: <string_android_fcm_api_key> # This is titled "Server Key" when creating it
use_multi_curl: <boolean_android_gcm_use_multi_curl> # default is true
ios:
timeout: 60 # Seconds to wait for connection timeout, default is 60
sandbox: <bool_use_apns_sandbox>
Expand All @@ -62,7 +65,7 @@ only be available if you provide configuration respectively for them.
windowsphone:
timeout: 5 # Seconds to wait for connection timeout, default is 5

NOTE: If you are using Windows, you may need to set the Android GCM `use_multi_curl` flag to false for GCM messages to be sent correctly.
NOTE: If you are using Windows, you may need to set the Android GCM/FCM `use_multi_curl` flag to false for GCM/FCM messages to be sent correctly.

Timeout defaults are the defaults from prior to the introduction of this configuration value.

Expand Down Expand Up @@ -96,8 +99,9 @@ Since both C2DM and GCM are still available, the `AndroidMessage` class has a sm

$message = new AndroidMessage();
$message->setGCM(true);
$message->setFCM(true); // Use to Firebase Cloud Messaging

to send as a GCM message rather than C2DM.
to send as a FCM message rather than GCM or C2DM.

## iOS Feedback service

Expand Down
11 changes: 11 additions & 0 deletions Resources/config/android.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<parameters>
<parameter key="rms_push_notifications.android.c2dm.class">RMS\PushNotificationsBundle\Service\OS\AndroidNotification</parameter>
<parameter key="rms_push_notifications.android.gcm.class">RMS\PushNotificationsBundle\Service\OS\AndroidGCMNotification</parameter>
<parameter key="rms_push_notifications.android.fcm.class">RMS\PushNotificationsBundle\Service\OS\AndroidFCMNotification</parameter>
</parameters>

<services>
Expand All @@ -30,6 +31,16 @@
<tag name="rms_push_notifications.handler" osType="rms_push_notifications.os.android.gcm" />
</service>

<!-- Android (FCM) -->
<service id="rms_push_notifications.android.fcm" class="%rms_push_notifications.android.fcm.class%" public="false">
<argument>%rms_push_notifications.android.fcm.api_key%</argument>
<argument>%rms_push_notifications.android.fcm.use_multi_curl%</argument>
<argument>%rms_push_notifications.android.timeout%</argument>
<argument type="service" id="logger" />
<argument>null</argument>
<tag name="rms_push_notifications.handler" osType="rms_push_notifications.os.android.fcm" />
</service>

</services>

</container>
2 changes: 2 additions & 0 deletions Service/Notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public function send(MessageInterface $message)
throw new \RuntimeException("OS type {$message->getTargetOS()} not supported");
}

dump($this->handlers, $message->getTargetOS());
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's this doing here?


return $this->handlers[$message->getTargetOS()]->send($message);
}

Expand Down
Loading