Skip to content
This repository has been archived by the owner on Dec 7, 2019. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
mwillbanks committed Dec 9, 2015
2 parents aa0fcd8 + 7157c7e commit 66e7778
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 11 deletions.
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,28 @@

All notable changes to this project will be documented in this file, in reverse chronological order by release.

## 1.2.0 - TBD

### Added

- [#36](https://github.com/zendframework/ZendService_Apple_Apns/pull/36)
Conection failures now raise a ```RuntimeException``` to allow you to catch
stream_socket_client(): SSL: Connection reset by peer warnings.
- [#39](https://github.com/zendframework/ZendService_Apple_Apns/pull/39) Add
safari push support

### Deprecated

- Nothing.

### Removed

- Nothing.

### Fixed

- Nothing.

## 1.1.2 - 2015-12-09

### Added
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@
},
"require-dev": {
"phpunit/phpunit": "3.7.*"
}
}
}
38 changes: 28 additions & 10 deletions library/ZendService/Apple/Apns/Client/AbstractClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace ZendService\Apple\Apns\Client;

use ZendService\Apple\Exception;
use ZendService\Apple\Exception\StreamSocketClientException;

/**
* Apple Push Notification Abstract Client
Expand Down Expand Up @@ -90,16 +91,33 @@ public function open($environment, $certificate, $passPhrase = null)
*/
protected function connect($host, array $ssl)
{
$this->socket = stream_socket_client(
$host,
$errno,
$errstr,
ini_get('default_socket_timeout'),
STREAM_CLIENT_CONNECT,
stream_context_create(array(
'ssl' => $ssl,
))
);
set_error_handler(function ($errno, $errstr, $errfile, $errline) {
throw new StreamSocketClientException($errstr, $errno, 1, $errfile, $errline);
});

try {
$this->socket = stream_socket_client(
$host,
$errno,
$errstr,
ini_get('default_socket_timeout'),
STREAM_CLIENT_CONNECT,
stream_context_create(
array(
'ssl' => $ssl,
)
)
);
} catch (StreamSocketClientException $e) {
throw new Exception\RuntimeException(sprintf(
'Unable to connect: %s: %d (%s)',
$host,
$e->getCode(),
$e->getMessage()
));
}

restore_error_handler();

if (!$this->socket) {
throw new Exception\RuntimeException(sprintf(
Expand Down
32 changes: 32 additions & 0 deletions library/ZendService/Apple/Apns/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ class Message
*/
protected $category;

/**
* URL Arguments
* @var array|null
*/
protected $urlArgs;

/**
* Custom Attributes
* @var array|null
Expand Down Expand Up @@ -301,6 +307,29 @@ public function setCategory($category)
return $this;
}

/**
* Get URL arguments
*
* @return array|null
*/
public function getUrlArgs()
{
return $this->urlArgs;
}

/**
* Set URL arguments
*
* @param array|null $urlArgs
* @return Message
*/
public function setUrlArgs(array $urlArgs)
{
$this->urlArgs = $urlArgs;

return $this;
}

/**
* Get Custom Data
*
Expand Down Expand Up @@ -354,6 +383,9 @@ public function getPayload()
if (!is_null($this->category)) {
$aps['category'] = $this->category;
}
if (!is_null($this->urlArgs)) {
$aps['url-args'] = $this->urlArgs;
}
if (!empty($this->custom)) {
$message = array_merge($this->custom, $message);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
/**
* Exception for creating stream_socket_client
* @author Soshnikov Artem <[email protected]>
*/

namespace ZendService\Apple\Exception;

use ErrorException;

class StreamSocketClientException extends ErrorException
{
}
7 changes: 7 additions & 0 deletions tests/ZendService/Apple/Apns/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@ public function testSetCategoryThrowsExceptionOnNonString()
$this->message->setCategory(12345);
}

public function testSetUrlArgsReturnsString()
{
$urlArgs = array('path/to/somewhere');
$this->message->setUrlArgs($urlArgs);
$this->assertEquals($urlArgs, $this->message->getUrlArgs());
}

public function testSetCustomData()
{
$data = array('key' => 'val', 'key2' => array(1, 2, 3, 4, 5));
Expand Down

0 comments on commit 66e7778

Please sign in to comment.