Skip to content

Commit

Permalink
Create a certificate system. Fix connection for use certificate object.
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhukV committed Nov 9, 2015
1 parent 6b166e0 commit 62035c0
Show file tree
Hide file tree
Showing 70 changed files with 432 additions and 291 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@ composer.phar
composer.lock

# Other files
/.idea/
/demo/config.php
/atlassian-ide-plugin.xml
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
},

"autoload": {
"psr-0": { "Apple\\ApnPush": "src/" }
"psr-4": { "Apple\\ApnPush\\": "src/" }
}
}
4 changes: 3 additions & 1 deletion demo/notification/notification_event_dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
}

use Symfony\Component\EventDispatcher\EventDispatcher;
use Apple\ApnPush\Certificate\Certificate;
use Apple\ApnPush\Notification\Notification;
use Apple\ApnPush\Notification\NotificationEvents;
use Apple\ApnPush\Notification\SendException;
Expand All @@ -26,7 +27,8 @@
});

// Create connection
$connection = new Connection(CERTIFICATE_FILE, PASS_PHRASE, SANDBOX_MODE);
$certificate = new Certificate(CERTIFICATE_FILE, PASS_PHRASE);
$connection = new Connection($certificate, SANDBOX_MODE);

// Create notification
$notification = new Notification($connection);
Expand Down
4 changes: 3 additions & 1 deletion demo/notification/notification_logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@

include_once __DIR__ . '/CustomLogger.php';

use Apple\ApnPush\Certificate\Certificate;
use Apple\ApnPush\Notification\Notification;
use Apple\ApnPush\Notification\Connection;
use Apple\ApnPush\Notification\SendException;

// Create connection
$connection = new Connection(CERTIFICATE_FILE, PASS_PHRASE, SANDBOX_MODE);
$certificate = new Certificate(CERTIFICATE_FILE, PASS_PHRASE);
$connection = new Connection($certificate, SANDBOX_MODE);

// Create custom logger
$logger = new CustomLogger();
Expand Down
4 changes: 3 additions & 1 deletion demo/queue/amqp_receiver.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
\Demo::error('Please install PHP Amqp Extension for run this demo (AMQP Queue).');
}

use Apple\ApnPush\Certificate\Certificate;
use Apple\ApnPush\Notification\Notification;
use Apple\ApnPush\Queue\Amqp;
use Apple\ApnPush\Notification\Connection;

// Create connection
$connection = new Connection(CERTIFICATE_FILE, PASS_PHRASE, SANDBOX_MODE);
$certificate = new Certificate(CERTIFICATE_FILE, PASS_PHRASE);
$connection = new Connection($certificate, SANDBOX_MODE);

// Create notification
$notification = new Notification($connection);
Expand Down
4 changes: 3 additions & 1 deletion demo/queue/amqp_sender.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
\Demo::error('Please install PHP Amqp Extension for run this demo (AMQP Queue).');
}

use Apple\ApnPush\Certificate\Certificate;
use Apple\ApnPush\Notification\Notification;
use Apple\ApnPush\Notification\Message;
use Apple\ApnPush\Notification\Connection;
use Apple\ApnPush\Queue\Amqp;

// Create connection
$connection = new Connection(CERTIFICATE_FILE, PASS_PHRASE, SANDBOX_MODE);
$certificate = new Certificate(CERTIFICATE_FILE, PASS_PHRASE);
$connection = new Connection($certificate, SANDBOX_MODE);

// Create notification
$notification = new Notification($connection);
Expand Down
4 changes: 3 additions & 1 deletion demo/queue/array_receiver_sender.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

include_once __DIR__ . '/../autoload.php';

use Apple\ApnPush\Certificate\Certificate;
use Apple\ApnPush\Notification\Notification;
use Apple\ApnPush\Notification\Connection;
use Apple\ApnPush\Notification\Message;
Expand All @@ -12,7 +13,8 @@
$adapter = new ArrayAdapter();

// Create connection
$connection = new Connection(CERTIFICATE_FILE, PASS_PHRASE, SANDBOX_MODE);
$certificate = new Certificate(CERTIFICATE_FILE, PASS_PHRASE);
$connection = new Connection($certificate, SANDBOX_MODE);

// Create notification
$notification = new Notification($connection);
Expand Down
4 changes: 3 additions & 1 deletion demo/queue/queue_notification_error_handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

include_once __DIR__ . '/../autoload.php';

use Apple\ApnPush\Certificate\Certificate;
use Apple\ApnPush\Notification\Notification;
use Apple\ApnPush\Notification\Message;
use Apple\ApnPush\Notification\SendException;
Expand All @@ -13,7 +14,8 @@
$adapter = new ArrayAdapter();

// Create connection
$connection = new Connection(CERTIFICATE_FILE, PASS_PHRASE, SANDBOX_MODE);
$certificate = new Certificate(CERTIFICATE_FILE, PASS_PHRASE);
$connection = new Connection($certificate, SANDBOX_MODE);

// Create notification
$notification = new Notification($connection);
Expand Down
4 changes: 3 additions & 1 deletion demo/queue/redis_receiver.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
\Demo::error('Please install PHP Redis Extension for run this demo (Redis Queue).');
}

use Apple\ApnPush\Certificate\Certificate;
use Apple\ApnPush\Notification\Notification;
use Apple\ApnPush\Notification\Connection;
use Apple\ApnPush\Queue\Redis;

// Create connection
$connection = new Connection(CERTIFICATE_FILE, PASS_PHRASE, SANDBOX_MODE);
$certificate = new Certificate(CERTIFICATE_FILE, PASS_PHRASE);
$connection = new Connection($certificate, SANDBOX_MODE);

// Create notification
$notification = new Notification($connection);
Expand Down
4 changes: 3 additions & 1 deletion demo/queue/redis_sender.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
\Demo::error('Please install PHP Redis Extension for run this demo (Redis Queue).');
}

use Apple\ApnPush\Certificate\Certificate;
use Apple\ApnPush\Notification\Notification;
use Apple\ApnPush\Notification\Message;
use Apple\ApnPush\Notification\Connection;
use Apple\ApnPush\Queue\Redis;

// Create connection
$connection = new Connection(CERTIFICATE_FILE, PASS_PHRASE, SANDBOX_MODE);
$certificate = new Certificate(CERTIFICATE_FILE, PASS_PHRASE);
$connection = new Connection($certificate, SANDBOX_MODE);

// Create notification
$notification = new Notification($connection);
Expand Down
10 changes: 6 additions & 4 deletions doc/feedback.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ print_r($feedback->getInvalidDevices());
Or create feedback connection:

```php
use Apple\ApnPush\Feedback;
use Apple\ApnPush\Certificate\Certificate;
use Apple\ApnPush\Feedback\Feedback;
use Apple\ApnPush\Feedback\Connection;

// Third parameter - sandbox mode
$connection = new Connection('/path/to/your/certificate.pem', 'pass_phrase', false);
$certificate = new Certificate('/path/to/your/certificate.pem', 'pass_phrase');
// Second parameter - sandbox mode
$connection = new Connection($certificate, false);
$feedback = new Feedback($connection);
print_r($feedback->getInvalidDevices());
```
```
6 changes: 4 additions & 2 deletions doc/notification.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ $notification = new Notification('/path/to/your/certificate.pem');
Create notification with connection object:

```php
use Apple\ApnPush\Certificate\Certificate;
use Apple\ApnPush\Notification;
use Apple\ApnPush\Notification\Connection;

// Third argument - sandbox mode
$connection = new Connection('/path/to/your/certificate.pem', 'your_passphrase', false);
$certificate = new Certificate('/path/to/your/certificate.pem', 'your_passphrase');
// Second argument - sandbox mode
$connection = new Connection($certificate, false);
$notification = new Notification($connection);
```

Expand Down
6 changes: 1 addition & 5 deletions doc/queue.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use Apple\ApnPush\Queue\Adapter\ArrayAdapter;
$adapter = new ArrayAdapter();

// Create notification
$notification = new Notification(/** Path to your certificate file **/);
$notification = new Notification('/path/to/you/certificate.pem');

// Create queue
$queue = new Queue($adapter, $notification);
Expand Down Expand Up @@ -55,7 +55,3 @@ $handler = function (SendException $e) {
$queue->setNotificationErrorHandler($handler);
$queue->runReceiver();
```




71 changes: 71 additions & 0 deletions src/Certificate/Certificate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

/*
* This file is part of the AppleApnPush package
*
* (c) Vitaliy Zhuk <zhuk2205@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code
*/

namespace Apple\ApnPush\Certificate;

use Apple\ApnPush\Exception\CertificateFileNotFoundException;

/**
* Base certificate
*/
class Certificate implements CertificateInterface
{
/**
* @var string
*/
private $path;

/**
* @var string
*/
private $passPhrase;

/**
* Construct
*
* @param string $path
* @param string $passPhrase
*
* @throws CertificateFileNotFoundException
*/
public function __construct($path, $passPhrase)
{
if (!file_exists($path) || !is_file($path)) {
throw new CertificateFileNotFoundException(sprintf(
'The certificate file "%s" was not found.',
$path
));
}

$this->path = $path;
$this->passPhrase = $passPhrase;
}

/**
* Get path
*
* @return string
*/
public function getPath()
{
return $this->path;
}

/**
* Get pass phrase
*
* @return string
*/
public function getPassPhrase()
{
return $this->passPhrase;
}
}
32 changes: 32 additions & 0 deletions src/Certificate/CertificateInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/*
* This file is part of the AppleApnPush package
*
* (c) Vitaliy Zhuk <zhuk2205@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code
*/

namespace Apple\ApnPush\Certificate;

/**
* All certificate should implement this interface
*/
interface CertificateInterface
{
/**
* Get path
*
* @return string
*/
public function getPath();

/**
* Get pass phrase
*
* @return string
*/
public function getPassPhrase();
}
Loading

0 comments on commit 62035c0

Please sign in to comment.