Skip to content

Commit

Permalink
Add sound support for APNS and curl debug mode in both clients
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian committed Jun 14, 2016
1 parent 569b376 commit 777d2f1
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
28 changes: 27 additions & 1 deletion src/Khrizt/PushNotiphications/Client/Apns.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ class Apns
*/
protected $passphrase;

/**
* Debug flag.
*
* @var bool
*/
protected $debug = false;

/**
* Constructor.
*
Expand Down Expand Up @@ -90,13 +97,18 @@ public function send(MessageInterface $message, Collection $deviceCollection) :
curl_setopt($this->handler, CURLOPT_SSLCERTPASSWD, $this->passphrase);
curl_setopt($this->handler, CURLOPT_SSLKEYPASSWD, $this->passphrase);
}
// curl_setopt($this->handler, CURLOPT_VERBOSE, true);
if ($this->debug) {
curl_setopt($this->handler, CURLOPT_VERBOSE, true);
}

$responseCollection = new Collection();
foreach ($deviceCollection as $device) {
if ($device->getBadge() > 0) {
$payload['aps']['badge'] = $device->getBadge();
}
if (!empty($device->getSound())) {
$payload['aps']['sound'] = $device->getSound();
}
curl_setopt($this->handler, CURLOPT_POSTFIELDS, json_encode($payload, JSON_UNESCAPED_UNICODE));
curl_setopt($this->handler, CURLOPT_URL, $this->apnsUrl.$device->getToken());

Expand All @@ -111,4 +123,18 @@ public function send(MessageInterface $message, Collection $deviceCollection) :

return $responseCollection;
}

/**
* Sets the Debug flag.
*
* @param bool $debug the debug
*
* @return self
*/
public function setDebug(bool $debug) : Apns
{
$this->debug = $debug;

return $this;
}
}
25 changes: 24 additions & 1 deletion src/Khrizt/PushNotiphications/Client/Gcm.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ class Gcm extends AbstractClient
*/
protected $handler;

/**
* Debug flag.
*
* @var bool
*/
protected $debug = false;

public function __construct(string $apiKey)
{
$this->apiKey = $apiKey;
Expand Down Expand Up @@ -59,7 +66,9 @@ public function send(MessageInterface $message, Collection $deviceCollection) :
]);
curl_setopt($this->handler, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($this->handler, CURLOPT_URL, self::GCM_URL);
// curl_setopt($this->handler, CURLOPT_VERBOSE, true);
if ($this->debug) {
curl_setopt($this->handler, CURLOPT_VERBOSE, true);
}

$responseCollection = new Collection();
$count = 0;
Expand Down Expand Up @@ -107,4 +116,18 @@ public function send(MessageInterface $message, Collection $deviceCollection) :

return $responseCollection;
}

/**
* Sets the Debug flag.
*
* @param bool $debug the debug
*
* @return self
*/
public function setDebug(bool $debug) : Gcm
{
$this->debug = $debug;

return $this;
}
}

0 comments on commit 777d2f1

Please sign in to comment.