Skip to content

Commit

Permalink
Samples: Fix codestyle issues
Browse files Browse the repository at this point in the history
  • Loading branch information
pprkut authored and SMillerDev committed Apr 19, 2024
1 parent d2d8f33 commit 5d4e384
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 58 deletions.
23 changes: 13 additions & 10 deletions sample_push.php
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
Expand All @@ -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
Expand All @@ -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);
Expand All @@ -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);
}
26 changes: 15 additions & 11 deletions sample_push_custom.php
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
Expand All @@ -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
Expand All @@ -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);
Expand All @@ -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');
Expand All @@ -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);
}
23 changes: 13 additions & 10 deletions sample_push_http.php
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
Expand All @@ -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');
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
37 changes: 20 additions & 17 deletions sample_push_many.php
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
Expand All @@ -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).
Expand All @@ -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
Expand All @@ -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);
}
24 changes: 14 additions & 10 deletions sample_push_safari.php
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
Expand All @@ -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
Expand All @@ -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);
Expand All @@ -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);
}

0 comments on commit 5d4e384

Please sign in to comment.