forked from immobiliare/ApnsPHP
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d2d8f33
commit 5d4e384
Showing
5 changed files
with
75 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
<?php | ||
|
||
/** | ||
* Push demo | ||
* | ||
* phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols, PSR1.Classes.ClassDeclaration.MissingNamespace | ||
* | ||
* SPDX-FileCopyrightText: Copyright 2010 Aldo Armiento ([email protected]) | ||
* SPDX-FileCopyrightText: Copyright 2021 M2mobi B.V., Amsterdam, The Netherlands | ||
* SPDX-FileCopyrightText: Copyright 2022 Move Agency Group B.V., Zwolle, The Netherlands | ||
|
@@ -19,17 +22,17 @@ | |
|
||
class SampleLogger extends \Psr\Log\AbstractLogger | ||
{ | ||
public function log($level, $message, array $context = array()): void | ||
{ | ||
printf("%s: %s ApnsPHP[%d]: %s\n", date('r'), strtoupper($level), getmypid(), trim($message)); | ||
} | ||
public function log($level, $message, array $context = []): void | ||
{ | ||
printf("%s: %s ApnsPHP[%d]: %s\n", date('r'), strtoupper($level), getmypid(), trim($message)); | ||
} | ||
} | ||
|
||
// Instantiate a new ApnsPHP_Push object | ||
$push = new \ApnsPHP\Push( | ||
\ApnsPHP\Push::ENVIRONMENT_SANDBOX, | ||
'server_certificates_bundle_sandbox.pem', | ||
new SampleLogger(), | ||
\ApnsPHP\Push::ENVIRONMENT_SANDBOX, | ||
'server_certificates_bundle_sandbox.pem', | ||
new SampleLogger(), | ||
); | ||
|
||
// Set the Provider Certificate passphrase | ||
|
@@ -55,10 +58,10 @@ public function log($level, $message, array $context = array()): void | |
$message->setSound(); | ||
|
||
// Set a custom property | ||
$message->setCustomProperty('acme2', array('bang', 'whiz')); | ||
$message->setCustomProperty('acme2', ['bang', 'whiz']); | ||
|
||
// Set another custom property | ||
$message->setCustomProperty('acme3', array('bing', 'bong')); | ||
$message->setCustomProperty('acme3', ['bing', 'bong']); | ||
|
||
// Set the expiry value to 30 seconds | ||
$message->setExpiry(30); | ||
|
@@ -75,5 +78,5 @@ public function log($level, $message, array $context = array()): void | |
// Examine the error message container | ||
$aErrorQueue = $push->getErrors(); | ||
if (!empty($aErrorQueue)) { | ||
var_dump($aErrorQueue); | ||
var_dump($aErrorQueue); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
<?php | ||
|
||
/** | ||
* CustomMessage Push demo | ||
* | ||
* phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols, PSR1.Classes.ClassDeclaration.MissingNamespace | ||
* | ||
* SPDX-FileCopyrightText: Copyright 2010 Aldo Armiento ([email protected]) | ||
* SPDX-FileCopyrightText: Copyright 2021 M2mobi B.V., Amsterdam, The Netherlands | ||
* SPDX-FileCopyrightText: Copyright 2022 Move Agency Group B.V., Zwolle, The Netherlands | ||
|
@@ -19,17 +22,17 @@ | |
|
||
class SampleLogger extends \Psr\Log\AbstractLogger | ||
{ | ||
public function log($level, $message, array $context = array()): void | ||
{ | ||
printf("%s: %s ApnsPHP[%d]: %s\n", date('r'), strtoupper($level), getmypid(), trim($message)); | ||
} | ||
public function log($level, $message, array $context = []): void | ||
{ | ||
printf("%s: %s ApnsPHP[%d]: %s\n", date('r'), strtoupper($level), getmypid(), trim($message)); | ||
} | ||
} | ||
|
||
// Instanciate a new ApnsPHP_Push object | ||
$push = new \ApnsPHP\Push( | ||
\ApnsPHP\Push::ENVIRONMENT_SANDBOX, | ||
'server_certificates_bundle_sandbox.pem', | ||
new SampleLogger(), | ||
\ApnsPHP\Push::ENVIRONMENT_SANDBOX, | ||
'server_certificates_bundle_sandbox.pem', | ||
new SampleLogger(), | ||
); | ||
|
||
// Connect to the Apple Push Notification Service | ||
|
@@ -52,7 +55,7 @@ public function log($level, $message, array $context = array()): void | |
$message->setSound(); | ||
|
||
// Set a custom property | ||
$message->setCustomProperty('acme2', array('bang', 'whiz')); | ||
$message->setCustomProperty('acme2', ['bang', 'whiz']); | ||
|
||
// Set the expiry value to 30 seconds | ||
$message->setExpiry(30); | ||
|
@@ -61,8 +64,9 @@ public function log($level, $message, array $context = array()): void | |
$message->setActionLocKey('Show me!'); | ||
|
||
// Set the alert-message string and variable string values to appear in place of the format specifiers. | ||
$message->setLocKey('Hello %1$@, you have %2$@ new messages!'); // This will overwrite the text specified with setText() method. | ||
$message->setLocArgs(array('Steve', 5)); | ||
// This will overwrite the text specified with setText() method. | ||
$message->setLocKey('Hello %1$@, you have %2$@ new messages!'); | ||
$message->setLocArgs(['Steve', 5]); | ||
|
||
// Set the filename of an image file in the application bundle. | ||
$message->setLaunchImage('DefaultAlert.png'); | ||
|
@@ -79,5 +83,5 @@ public function log($level, $message, array $context = array()): void | |
// Examine the error message container | ||
$aErrorQueue = $push->getErrors(); | ||
if (!empty($aErrorQueue)) { | ||
var_dump($aErrorQueue); | ||
var_dump($aErrorQueue); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
<?php | ||
|
||
/** | ||
* Push demo | ||
* | ||
* phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols, PSR1.Classes.ClassDeclaration.MissingNamespace | ||
* | ||
* SPDX-FileCopyrightText: Copyright 2010 Aldo Armiento ([email protected]) | ||
* SPDX-FileCopyrightText: Copyright 2021 M2mobi B.V., Amsterdam, The Netherlands | ||
* SPDX-FileCopyrightText: Copyright 2022 Move Agency Group B.V., Zwolle, The Netherlands | ||
|
@@ -19,17 +22,17 @@ | |
|
||
class SampleLogger extends \Psr\Log\AbstractLogger | ||
{ | ||
public function log($level, $message, array $context = array()): void | ||
{ | ||
printf("%s: %s ApnsPHP[%d]: %s\n", date('r'), strtoupper($level), getmypid(), trim($message)); | ||
} | ||
public function log($level, $message, array $context = []): void | ||
{ | ||
printf("%s: %s ApnsPHP[%d]: %s\n", date('r'), strtoupper($level), getmypid(), trim($message)); | ||
} | ||
} | ||
|
||
// Instantiate a new ApnsPHP_Push object | ||
$push = new \ApnsPHP\Push( | ||
\ApnsPHP\Push::ENVIRONMENT_SANDBOX, | ||
'UniversalPushNotificationClientSSLCertificate.p8', | ||
new SampleLogger(), | ||
\ApnsPHP\Push::ENVIRONMENT_SANDBOX, | ||
'UniversalPushNotificationClientSSLCertificate.p8', | ||
new SampleLogger(), | ||
); | ||
|
||
$push->setTeamId('sgfdgfdfgd'); | ||
|
@@ -64,10 +67,10 @@ public function log($level, $message, array $context = array()): void | |
$message->setSound(); | ||
|
||
// Set a custom property | ||
$message->setCustomProperty('acme2', array('bang', 'whiz')); | ||
$message->setCustomProperty('acme2', ['bang', 'whiz']); | ||
|
||
// Set another custom property | ||
$message->setCustomProperty('acme3', array('bing', 'bong')); | ||
$message->setCustomProperty('acme3', ['bing', 'bong']); | ||
|
||
// Set the expiry value to 30 seconds | ||
$message->setExpiry(30); | ||
|
@@ -84,5 +87,5 @@ public function log($level, $message, array $context = array()): void | |
// Examine the error message container | ||
$aErrorQueue = $push->getErrors(); | ||
if (!empty($aErrorQueue)) { | ||
var_dump($aErrorQueue); | ||
var_dump($aErrorQueue); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
<?php | ||
|
||
/** | ||
* Push demo | ||
* | ||
* phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols, PSR1.Classes.ClassDeclaration.MissingNamespace | ||
* | ||
* SPDX-FileCopyrightText: Copyright 2010 Aldo Armiento ([email protected]) | ||
* SPDX-FileCopyrightText: Copyright 2021 M2mobi B.V., Amsterdam, The Netherlands | ||
* SPDX-FileCopyrightText: Copyright 2022 Move Agency Group B.V., Zwolle, The Netherlands | ||
|
@@ -22,17 +25,17 @@ | |
|
||
class SampleLogger extends \Psr\Log\AbstractLogger | ||
{ | ||
public function log($level, $message, array $context = array()): void | ||
{ | ||
printf("%s: %s ApnsPHP[%d]: %s\n", date('r'), strtoupper($level), getmypid(), trim($message)); | ||
} | ||
public function log($level, $message, array $context = []): void | ||
{ | ||
printf("%s: %s ApnsPHP[%d]: %s\n", date('r'), strtoupper($level), getmypid(), trim($message)); | ||
} | ||
} | ||
|
||
// Instanciate a new ApnsPHP_Push object | ||
$push = new \ApnsPHP\Push( | ||
\ApnsPHP\Push::ENVIRONMENT_SANDBOX, | ||
'server_certificates_bundle_sandbox.pem', | ||
new SampleLogger(), | ||
\ApnsPHP\Push::ENVIRONMENT_SANDBOX, | ||
'server_certificates_bundle_sandbox.pem', | ||
new SampleLogger(), | ||
); | ||
|
||
// Increase write interval to 100ms (default value is 10ms). | ||
|
@@ -45,18 +48,18 @@ public function log($level, $message, array $context = array()): void | |
$push->connect(); | ||
|
||
for ($i = 1; $i <= 10; $i++) { | ||
// Instantiate a new Message with a single recipient | ||
$message = new \ApnsPHP\Message($i == 5 ? INVALID_TOKEN : VALID_TOKEN); | ||
// Instantiate a new Message with a single recipient | ||
$message = new \ApnsPHP\Message($i == 5 ? INVALID_TOKEN : VALID_TOKEN); | ||
|
||
// Set a custom identifier. To get back this identifier use the getCustomIdentifier() method | ||
// over a ApnsPHP_Message object retrieved with the getErrors() message. | ||
$message->setCustomIdentifier(sprintf("Message-Badge-%03d", $i)); | ||
// Set a custom identifier. To get back this identifier use the getCustomIdentifier() method | ||
// over a ApnsPHP_Message object retrieved with the getErrors() message. | ||
$message->setCustomIdentifier(sprintf("Message-Badge-%03d", $i)); | ||
|
||
// Set badge icon to "3" | ||
$message->setBadge($i); | ||
// Set badge icon to "3" | ||
$message->setBadge($i); | ||
|
||
// Add the message to the message queue | ||
$push->add($message); | ||
// Add the message to the message queue | ||
$push->add($message); | ||
} | ||
|
||
// Send all messages in the message queue | ||
|
@@ -68,5 +71,5 @@ public function log($level, $message, array $context = array()): void | |
// Examine the error message container | ||
$aErrorQueue = $push->getErrors(); | ||
if (!empty($aErrorQueue)) { | ||
var_dump($aErrorQueue); | ||
var_dump($aErrorQueue); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
<?php | ||
|
||
/** | ||
* SafariMessage push demo. | ||
* | ||
* phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols, PSR1.Classes.ClassDeclaration.MissingNamespace | ||
* | ||
* SPDX-FileCopyrightText: Copyright 2017 Marco Rocca ([email protected]) | ||
* SPDX-FileCopyrightText: Copyright 2021 M2mobi B.V., Amsterdam, The Netherlands | ||
* SPDX-FileCopyrightText: Copyright 2022 Move Agency Group B.V., Zwolle, The Netherlands | ||
|
@@ -19,17 +22,17 @@ | |
|
||
class SampleLogger extends \Psr\Log\AbstractLogger | ||
{ | ||
public function log($level, $message, array $context = array()): void | ||
{ | ||
printf("%s: %s ApnsPHP[%d]: %s\n", date('r'), strtoupper($level), getmypid(), trim($message)); | ||
} | ||
public function log($level, $message, array $context = []): void | ||
{ | ||
printf("%s: %s ApnsPHP[%d]: %s\n", date('r'), strtoupper($level), getmypid(), trim($message)); | ||
} | ||
} | ||
|
||
// Instantiate a new ApnsPHP_Push object | ||
$push = new \ApnsPHP\Push( | ||
\ApnsPHP\Push::ENVIRONMENT_SANDBOX, | ||
'server_certificates_bundle_sandbox.pem', | ||
new SampleLogger(), | ||
\ApnsPHP\Push::ENVIRONMENT_SANDBOX, | ||
'server_certificates_bundle_sandbox.pem', | ||
new SampleLogger(), | ||
); | ||
|
||
// Set the Provider Certificate passphrase | ||
|
@@ -51,8 +54,9 @@ public function log($level, $message, array $context = array()): void | |
// This label should be succinct, such as "Details" or "Read more". If omitted, the default value is "Show". | ||
$message->setAction('View'); | ||
|
||
// Set an array of values that are paired with the placeholders inside the urlFormatString value of your website.json file | ||
$message->setUrlArgs(array('boarding', 'A998')); | ||
// Set an array of values that are paired with the placeholders inside the urlFormatString value | ||
// of your website.json file | ||
$message->setUrlArgs(['boarding', 'A998']); | ||
|
||
// Add the message to the message queue | ||
$push->add($message); | ||
|
@@ -66,5 +70,5 @@ public function log($level, $message, array $context = array()): void | |
// Examine the error message container | ||
$aErrorQueue = $push->getErrors(); | ||
if (!empty($aErrorQueue)) { | ||
var_dump($aErrorQueue); | ||
var_dump($aErrorQueue); | ||
} |