Commit dbcb4da7 authored by Richard Weinhold's avatar Richard Weinhold 🔨
Browse files

adds composer.json

- fixes missing curl_close() in WNSHandler if an error appeared
- replaces Exceptions with more specific Runtime and UnexceptedValue
  Exceptions
parent ba7e6c44
#### joe made this: http://goel.io/joe
#### linux ####
*~
# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*
# KDE directory preferences
.directory
# Linux trash folder which might appear on any partition or disk
.Trash-*
# .nfs files are created when an open file is removed but is still being accessed
.nfs*
#### macos ####
*.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
......@@ -10,8 +10,8 @@ Examples:
```php
<?php
use PushNotification\PushNotification;
use PushNotification\Handler\GCMHandler;
use ricwein\PushNotification\PushNotification;
use ricwein\PushNotification\Handler\GCMHandler;
$push = new PushNotification(new GCMHandler());
$push->setServerToken('ExampleGooglePushToken12345678987654321');
......@@ -27,8 +27,8 @@ $push->send('message', ['payload' => 'data']);
```php
<?php
use PushNotification\PushNotification;
use PushNotification\Handler\APNSHandler;
use ricwein\PushNotification\PushNotification;
use ricwein\PushNotification\Handler\APNSHandler;
$push = new PushNotification(new APNSHandler());
$push->setServer([
......@@ -47,8 +47,8 @@ $push->send('message', ['payload' => 'data']);
```php
<?php
use PushNotification\PushNotification;
use PushNotification\Handler\WNSHandler;
use ricwein\PushNotification\PushNotification;
use ricwein\PushNotification\Handler\WNSHandler;
$push = new PushNotification(new WNSHandler());
$push->setServer([
......@@ -77,8 +77,8 @@ It's possible to init the PushNotification class with a specific push-handler:
```php
<?php
use PushNotification\PushNotification;
use PushNotification\Handler\GCMHandler;
use ricwein\PushNotification\PushNotification;
use ricwein\PushNotification\Handler\GCMHandler;
$push = new PushNotification(new GCMHandler());
......@@ -90,8 +90,8 @@ or without, and adding the push-handler later:
```php
<?php
use PushNotification\PushNotification;
use PushNotification\Handler\GCMHandler;
use ricwein\PushNotification\PushNotification;
use ricwein\PushNotification\Handler\GCMHandler;
$push = new PushNotification();
$pushHandler = new GCMHandler();
......
{
"name": "ricwein/push-notifications",
"description": "Push Notifications for iOS (APNS), Android (GCM) and Windows (WNS)",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Richard Weinhold",
"email": "git@ricwein.com"
}
]
}
<?php
/**
* @author Richard Weinhold
* @package PushNotification
* @author Richard Weinhold
*/
namespace PushNotification\Handler;
namespace ricwein\PushNotification\Handler;
use PushNotification\PushHandler;
use ricwein\PushNotification\PushHandler;
class APNSHandler extends PushHandler {
......@@ -53,7 +52,7 @@ class APNSHandler extends PushHandler {
// check and set cert-path
$certpath = realpath($this->_server['token']);
if (empty($certpath) || $certpath === DIRECTORY_SEPARATOR || !is_file($certpath)) {
throw new \Exception('Invalid cert-file: ' . $certpath, 500);
throw new \UnexpectedValueException('Invalid cert-file: ' . $certpath, 500);
}
stream_context_set_option($ctx, 'ssl', 'local_cert', $certpath);
......@@ -66,7 +65,7 @@ class APNSHandler extends PushHandler {
$stream = @stream_socket_client($this->_server['url'], $errno, $errstr, 60, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT, $ctx);
if (!$stream) {
throw new \Exception('Error connecting to APNS-Server [' . $errno . ']: ' . $errstr, 500);
throw new \RuntimeException('Error connecting to APNS-Server [' . $errno . ']: ' . $errstr, 500);
}
$payload = json_encode($payload);
......@@ -134,7 +133,7 @@ class APNSHandler extends PushHandler {
return $frame;
}
throw new \Exception('Unknown Command Version', 500);
throw new \UnexpectedValueException('Unknown Command Version', 500);
}
}
<?php
/**
* @author Richard Weinhold
* @package PushNotification
* @author Richard Weinhold
*/
namespace PushNotification\Handler;
namespace ricwein\PushNotification\Handler;
use PushNotification\PushHandler;
use ricwein\PushNotification\PushHandler;
class GCMHandler extends PushHandler {
......@@ -67,7 +66,7 @@ class GCMHandler extends PushHandler {
if ($result === false) {
$error = curl_error($curl);
curl_close($curl);
throw new \Exception('error processing GCM: ' . $error, 500);
throw new \RuntimeException('error processing GCM: ' . $error, 500);
}
// remeber to close the connection when finished
......
<?php
/**
* @author Richard Weinhold
* @package PushNotification
* @author Richard Weinhold
*/
namespace PushNotification\Handler;
namespace ricwein\PushNotification\Handler;
use PushNotification\PushHandler;
use ricwein\PushNotification\PushHandler;
class WNSHandler extends PushHandler {
......@@ -181,7 +180,9 @@ class WNSHandler extends PushHandler {
// send request
if (curl_exec($curl) === false) {
throw new \Exception('error processing WPN: ' . curl_error($curl), 500);
$error = curl_error($curl);
curl_close($curl);
throw new \RuntimeException('error processing WPN: ' . $error, 500);
}
$response = curl_getinfo($curl);
......
<?php
/**
* @author Richard Weinhold
* @package PushNotification
* @author Richard Weinhold
*/
namespace PushNotification;
namespace ricwein\PushNotification;
abstract class PushHandler {
......@@ -56,9 +55,9 @@ abstract class PushHandler {
public function prepare() {
if (empty($this->_server['token'])) {
throw new \Exception('server token not set', 500);
throw new \UnexpectedValueException('server token not set', 500);
} elseif (empty($this->_server['url'])) {
throw new \Exception('server url not set', 500);
throw new \UnexpectedValueException('server url not set', 500);
}
return true;
......
<?php
/**
* @author Richard Weinhold
* @package PushNotification
* @author Richard Weinhold
*/
namespace PushNotification;
namespace ricwein\PushNotification;
use PushNotification\PushHandler;
use ricwein\PushNotification\PushHandler;
class PushNotification {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment