Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
a9283c7
Merge pull request #93 from EDSI-Tech/master
richsage Mar 30, 2015
c065be9
Fix use of PHP5.4 array syntax.
richsage Apr 2, 2015
69accec
added logger for Android GCM
Apr 8, 2015
2794d2c
Make symfony optional
davedevelopment Feb 11, 2013
b89badc
Merge pull request #23 from davedevelopment/decouple-symfony
richsage May 14, 2015
31ccbf1
added logger for push errors
antoinemineau May 15, 2015
b789834
Close apn stream in case of shutdown error
tgallice May 29, 2015
87e8038
Merge pull request #100 from antoinemineau/logger
richsage Jun 7, 2015
5383f50
Define constant for shutdown status code
tgallice Jun 8, 2015
b6205fa
Merge pull request #101 from tgallice/close_apns
richsage Jun 8, 2015
5db201a
Add missing cache directory to AppleNotification.
richsage Jun 28, 2015
6bb892e
Add note about Windows Phone (fixes #103).
richsage Jun 28, 2015
98659c6
Merge pull request #105 from richsage/104-cache-dir
richsage Jun 29, 2015
9e3e764
Provide correct method parameters (fixes #108).
richsage Jul 20, 2015
2705528
Merge pull request #110 from richsage/108-apple-notification
richsage Aug 21, 2015
0e0e394
Merge pull request #107 from EDSI-Tech/master
richsage Aug 21, 2015
b033491
Log the actual GCM error messages
rvanlaarhoven Oct 9, 2015
b263392
Add IOS notification category
Oct 26, 2015
ed9fd91
Merge pull request #115 from MatthieuLemoine/master
richsage Oct 27, 2015
67298cb
Remove erroneous clearing of errors array in loop
richsage Mar 9, 2016
021d2ea
Merge pull request #120 from richsage/error-array-reset-fix
richsage Mar 9, 2016
b1d87c1
Assign the count of messages to a variable.
TheFox Mar 9, 2016
c32a5aa
Merge pull request #121 from TheFox/loop-count
richsage Mar 9, 2016
4a32867
Fixed #123
TiMESPLiNTER Mar 24, 2016
df174f8
Remove unnecessary new line
TiMESPLiNTER Mar 24, 2016
2d5a87d
Moves dryRun param to the end of the signature with default value of …
TiMESPLiNTER Mar 24, 2016
f168643
Merge pull request #124 from TiMESPLiNTER/feat/android-gcm-dry-run
richsage Mar 24, 2016
de55bd4
Merge pull request #114 from rvanlaarhoven/master
richsage Mar 24, 2016
b436f71
Fix error logging and use Psr interface.
richsage Mar 24, 2016
25e9d13
Update Apple service to use Psr logger.
richsage Mar 24, 2016
2c80c65
Update Blackberry service to use Psr logger.
richsage Mar 24, 2016
4aa2097
Update Microsoft service to use Psr logger.
richsage Mar 24, 2016
d9f9312
Fix exception class being thrown.
richsage Mar 24, 2016
c19b7c4
Fix dry-run parameter passed to service.
richsage Mar 24, 2016
2050caf
Merge pull request #127 from richsage/111-exception-catch
richsage Mar 24, 2016
0e4cbe4
Merge pull request #125 from richsage/errors
richsage Mar 24, 2016
c40db9d
Fix GCM configuration bug.
richsage Mar 24, 2016
45b90b3
Update branch-alias.
richsage Mar 24, 2016
052b4f9
Add missing null argument to GCM service.
richsage Mar 26, 2016
26840dd
[GCM] Don't use registration_ids for single recipient
aminin Apr 1, 2016
324b294
Merge pull request #129 from aminin/master
richsage Apr 1, 2016
a81560b
Close all APNS streams just after setting PEM as string.
May 10, 2016
d42cc25
Do nothing if the same PEM and passphrase came.
May 12, 2016
ef92c6b
adjust [] to array() in AppleNotification::closeStreams()
Aug 1, 2016
eeeddde
Merge pull request #133 from shpagin/fix-close-apn-streams-after-sett…
richsage Dec 19, 2016
176f196
Update composer.json
EmmanuelVella Jan 6, 2017
6c3e28f
Adds support for mutable-content flag
davedevelopment Feb 13, 2017
0ebb25f
Merge pull request #154 from EmmanuelVella/patch-2
richsage Mar 1, 2017
850363e
Merge pull request #155 from davedevelopment/mutable-content
richsage Mar 1, 2017
ed38999
Add 7.0 and 7.1 to travis PHP versions
Phobetor Apr 4, 2017
38d24f3
Force PHPunit 5.7 for travis builds with PHP 7.*
Phobetor Apr 4, 2017
3432bca
Merge pull request #159 from Phobetor/patch-1
richsage Jun 7, 2017
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
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
language: php

before_install:
# If PHP >= 5.6, download & install PHPunit 5.7 to avoid builds failures
- if php -r "exit( (int)! version_compare( '$TRAVIS_PHP_VERSION', '5.6', '>=' ) );"; then wget -O phpunit https://phar.phpunit.de/phpunit-5.7.phar && chmod +x phpunit && mkdir ~/bin && mv -v phpunit ~/bin; fi

php:
- 5.3
- 5.4
- 5.5
- 5.6
- 7.0
- 7.1
env:
- SYMFONY_VERSION=origin/master

Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/Compiler/AddHandlerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function process(ContainerBuilder $container)
}

$refClass = new \ReflectionClass($class);
} catch (\ReflectionClass $ref) {
} catch (\ReflectionException $ref) {
// Class not found or other reflection error
throw new \RuntimeException(sprintf(
'Can\'t compile notification handler by service id "%s".',
Expand Down
1 change: 1 addition & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ protected function addAndroid()
children()->
scalarNode("api_key")->isRequired()->cannotBeEmpty()->end()->
booleanNode("use_multi_curl")->defaultValue(true)->end()->
booleanNode("dry_run")->defaultFalse()->end()->
end()->
end()->
end()->
Expand Down
1 change: 1 addition & 0 deletions DependencyInjection/RMSPushNotificationsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ protected function setAndroidConfig(array $config)
if (isset($config["android"]["gcm"])) {
$this->container->setParameter("rms_push_notifications.android.gcm.api_key", $config["android"]["gcm"]["api_key"]);
$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"]);
}
}

Expand Down
22 changes: 22 additions & 0 deletions Message/AppleMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,28 @@ public function setAPSContentAvailable($contentAvailable)
$this->apsBody["aps"]["content-available"] = $contentAvailable;
}

/**
* iOS-specific
* Sets the APS category
*
* @param string $category The notification category
*/
public function setCategory($category)
{
$this->apsBody["aps"]["category"] = $category;
}

/**
* iOS-specific
* Sets the APS mutable-content attribute
*
* @param bool $mutableContent
*/
public function setMutableContent($mutableContent)
{
$this->apsBody["aps"]["mutable-content"] = $mutableContent ? 1 : 0;
}

/**
* Set expiry of message
*
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ only be available if you provide configuration respectively for them.
gcm:
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>
ios:
timeout: 60 # Seconds to wait for connection timeout, default is 60
sandbox: <bool_use_apns_sandbox>
Expand Down Expand Up @@ -111,6 +112,10 @@ Here, `$uuids` contains an array of [Feedback](https://github.com/richsage/RMSPu

Apple recommend you poll this service daily.

## Windows Phone - Toast support

The bundle has beta support for Windows Phone, and supports the Toast notification. Use the `WindowsphoneMessage` message class to send accordingly.

# Thanks

Firstly, thanks to all contributors to this bundle!
Expand Down
3 changes: 3 additions & 0 deletions Resources/config/android.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
<argument>%rms_push_notifications.android.gcm.api_key%</argument>
<argument>%rms_push_notifications.android.gcm.use_multi_curl%</argument>
<argument>%rms_push_notifications.android.timeout%</argument>
<argument type="service" id="logger" />
<argument>null</argument>
<argument>%rms_push_notifications.android.gcm.dry_run%</argument>
<tag name="rms_push_notifications.handler" osType="rms_push_notifications.os.android.gcm" />
</service>

Expand Down
1 change: 1 addition & 0 deletions Resources/config/blackberry.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<argument>%rms_push_notifications.blackberry.app_id%</argument>
<argument>%rms_push_notifications.blackberry.password%</argument>
<argument>%rms_push_notifications.blackberry.timeout%</argument>
<argument type="service" id="logger" />
<tag name="rms_push_notifications.handler" osType="rms_push_notifications.os.blackberry" />
</service>

Expand Down
1 change: 1 addition & 0 deletions Resources/config/ios.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<argument>%rms_push_notifications.ios.timeout%</argument>
<argument>%kernel.cache_dir%</argument>
<argument type="service" id="rms_push_notifications.event_listener" />
<argument type="service" id="logger" />
<tag name="rms_push_notifications.handler" osType="rms_push_notifications.os.ios" />
</service>

Expand Down
3 changes: 3 additions & 0 deletions Resources/config/mac.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
<argument>%rms_push_notifications.mac.passphrase%</argument>
<argument>%rms_push_notifications.mac.json_unescaped_unicode%</argument>
<argument>%rms_push_notifications.mac.timeout%</argument>
<argument>%kernel.cache_dir%</argument>
<argument type="service" id="rms_push_notifications.event_listener" />
<argument type="service" id="logger" />
<tag name="rms_push_notifications.handler" osType="rms_push_notifications.os.mac" />
</service>
</services>
Expand Down
1 change: 1 addition & 0 deletions Resources/config/windowsphone.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<!-- Windows Phone -->
<service id="rms_push_notifications.windowsphone" class="%rms_push_notifications.windowsphone.class%" public="false">
<argument>%rms_push_notifications.windowsphone.timeout%</argument>
<argument type="service" id="logger" />
<tag name="rms_push_notifications.handler" osType="rms_push_notifications.os.windowsphone" />
</service>

Expand Down
4 changes: 2 additions & 2 deletions Service/EventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class EventListener {
/**
* @var EventListenerInterface[]
*/
protected $listeners = [];
protected $listeners = array();

/**
* @param EventListenerInterface $listener
Expand All @@ -25,4 +25,4 @@ public function onKernelTerminate () {
$listener->onKernelTerminate();
}
}
}
}
54 changes: 47 additions & 7 deletions Service/OS/AndroidGCMNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace RMS\PushNotificationsBundle\Service\OS;

use Psr\Log\LoggerInterface;
use RMS\PushNotificationsBundle\Exception\InvalidMessageTypeException,
RMS\PushNotificationsBundle\Message\AndroidMessage,
RMS\PushNotificationsBundle\Message\MessageInterface;
Expand All @@ -12,6 +13,14 @@

class AndroidGCMNotification implements OSNotificationServiceInterface
{

/**
* Whether or not to use the dry run GCM
*
* @var bool
*/
protected $useDryRun = false;

/**
* GCM endpoint
*
Expand Down Expand Up @@ -47,16 +56,26 @@ class AndroidGCMNotification implements OSNotificationServiceInterface
*/
protected $responses;

/**
* Monolog logger
*
* @var LoggerInterface
*/
protected $logger;

/**
* Constructor
*
* @param $apiKey
* @param string $apiKey
* @param bool $useMultiCurl
* @param int $timeout
* @param AbstractCurl $client (optional)
* @param LoggerInterface $logger
* @param AbstractCurl $client (optional)
* @param bool $dryRun
*/
public function __construct($apiKey, $useMultiCurl, $timeout, AbstractCurl $client = null)
public function __construct($apiKey, $useMultiCurl, $timeout, $logger, AbstractCurl $client = null, $dryRun = false)
{
$this->useDryRun = $dryRun;
$this->apiKey = $apiKey;
if (!$client) {
$client = ($useMultiCurl ? new MultiCurl() : new Curl());
Expand All @@ -65,6 +84,7 @@ public function __construct($apiKey, $useMultiCurl, $timeout, AbstractCurl $clie

$this->browser = new Browser($client);
$this->browser->getClient()->setVerifyPeer(false);
$this->logger = $logger;
}

/**
Expand Down Expand Up @@ -92,14 +112,25 @@ public function send(MessageInterface $message)
array("data" => $message->getData())
);

// Chunk number of registration IDs according to the maximum allowed by GCM
$chunks = array_chunk($message->getGCMIdentifiers(), $this->registrationIdMaxCount);
if ($this->useDryRun) {
$data['dry_run'] = true;
}

// Perform the calls (in parallel)
$this->responses = array();
foreach ($chunks as $registrationIDs) {
$data["registration_ids"] = $registrationIDs;
$gcmIdentifiers = $message->getGCMIdentifiers();

if (count($message->getGCMIdentifiers()) == 1) {
$data['to'] = $gcmIdentifiers[0];
$this->responses[] = $this->browser->post($this->apiURL, $headers, json_encode($data));
} else {
// Chunk number of registration IDs according to the maximum allowed by GCM
$chunks = array_chunk($message->getGCMIdentifiers(), $this->registrationIdMaxCount);

foreach ($chunks as $registrationIDs) {
$data['registration_ids'] = $registrationIDs;
$this->responses[] = $this->browser->post($this->apiURL, $headers, json_encode($data));
}
}

// If we're using multiple concurrent connections via MultiCurl
Expand All @@ -112,6 +143,15 @@ public function send(MessageInterface $message)
foreach ($this->responses as $response) {
$message = json_decode($response->getContent());
if ($message === null || $message->success == 0 || $message->failure > 0) {
if ($message == null) {
$this->logger->error($response->getContent());
} else {
foreach ($message->results as $result) {
if (isset($result->error)) {
$this->logger->error($result->error);
}
}
}
return false;
}
}
Expand Down
Loading