-
-
Notifications
You must be signed in to change notification settings - Fork 273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Zend dependencies are abandoned #197
Comments
@risototh yes this is known. Do you have time to contribute? |
@seyfer not sure, if I have the time. Depends, on how much it will require. I only went around, when updating this library from the 2.0.0 version in our code ;D Maybe I can spent some hours on that, but I don't even know, what this library is for and how to test it... |
We are running out of time here. Apple just wrote:
|
To get the ball rolling, here is a quick implementation of an HTTP based adapter. It uses apple/apn-push. It’s probably not complete, probably has bugs and so on but it works for simple cases in my testing. class ApnsHttp extends BaseAdapter
{
public function push(PushInterface $push): DeviceCollection
{
$certificate = new Certificate($this->getParameter('certificate'), $this->getParameter('passPhrase'));
$authenticator = new CertificateAuthenticator($certificate);
$builder = new Http20Builder($authenticator);
$sender = $builder->build();
$pushedDevices = new DeviceCollection();
/** @var DeviceInterface $device */
foreach ($push->getDevices() as $device) {
$receiver = new Receiver(new DeviceToken($device->getToken()), $this->getParameter('bundleId'));
try {
$sender->send($receiver, $this->toNotification($device, $push->getMessage()), $this->isDevelopmentEnvironment());
$push->addResponse($device, ['success' => true]);
$push->pushed();
$pushedDevices->add($device);
} catch (SendNotificationException $e) {
throw new PushException($e->getMessage(), null, $e);
}
}
return $pushedDevices;
}
private function toNotification(DeviceInterface $device, Message $message): Notification
{
$alert = (new Alert())
->withBody($message->getText())
->withTitle($message->getOption('title') ?? '')
->withLaunchImage($message->getOption('launchImage') ?? '');
if ($message->getOption('locKey')) {
$alert = $alert->withBodyLocalized(
new Localized($message->getOption('locKey'), $message->getOption('locArgs', []))
);
}
if ($message->getOption('actionLocKey')) {
$alert = $alert->withActionLocalized(
new Localized($message->getOption('actionLocKey'), $message->getOption('actionLocKeyArgs', []))
);
}
if ($message->getOption('titleLocKey')) {
$alert = $alert->withLocalizedTitle(
new Localized($message->getOption('titleLocKey'), $message->getOption('titleLocArgs', []))
);
}
$aps = (new Aps($alert))
->withSound($message->getOption('sound') ?? '')
->withContentAvailable($message->getOption('content-available', false))
->withMutableContent($message->getOption('mutable-content', false))
->withCategory($message->getOption('category') ?? '');
if ($message->hasOption('badge')) {
$aps = $aps->withBadge($message->getOption('badge') + $device->getParameter('badge', 0));
}
$payload = (new Payload($aps));
foreach ($message->getOption('custom', []) as $key => $value) {
$payload = $payload->withCustomData($key, $value);
}
return (new Notification($payload))
->withExpiration(
$message->getOption('expire') ? new Expiration(new DateTime($message->getOption('expire'))) : null
);
}
public function supports($token): bool
{
return ctype_xdigit($token);
}
public function getDefinedParameters(): array
{
return [];
}
public function getDefaultParameters(): array
{
return ['passPhrase' => ''];
}
public function getRequiredParameters(): array
{
return ['certificate', 'bundleId'];
}
} |
Composer outputs:
The text was updated successfully, but these errors were encountered: