Skip to content

Update related Pusher package #73

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ build
composer.phar
composer.lock
.phpunit.result.cache
/.idea
/.vscode
22 changes: 0 additions & 22 deletions .travis.yml

This file was deleted.

26 changes: 10 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Pusher Beams push notifications channel for Laravel 5.5+, 6.x, 7.x & 8.x
# Pusher Beams push notifications channel for Laravel 8.x & 9.x

[![Latest Version on Packagist](https://img.shields.io/packagist/v/laravel-notification-channels/pusher-push-notifications.svg?style=flat-square)](https://packagist.org/packages/laravel-notification-channels/pusher-push-notifications)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
Expand All @@ -17,7 +17,7 @@ Also please note that prior to version 2.0, this package integrated with Pusher'

## Contents

- [Pusher Beams push notifications channel for Laravel 5.5+, 6.x, 7.x & 8.x](#pusher-beams-push-notifications-channel-for-laravel-55-6x-7x--8x)
- [Pusher Beams push notifications channel for Laravel 8.x & 9.x](#pusher-beams-push-notifications-channel-for-laravel-55-6x-7x--8x)
- [Contents](#contents)
- [Installation](#installation)
- [Setting up your Pusher account](#setting-up-your-pusher-account)
Expand All @@ -38,7 +38,7 @@ Also please note that prior to version 2.0, this package integrated with Pusher'

You can install the package via composer:

``` bash
```bash
composer require laravel-notification-channels/pusher-push-notifications
```

Expand All @@ -51,7 +51,7 @@ Before using this package you should set up a Pusher Beams account. Here are the
- Select your instance from the list or create a new instance.
- Click on the "Settings" tab.
- Upload your APNS Certificate and/or add your FCM Server key.
- Now select the "Credentials" tab.
- Now select the "Keys" tab.
- Copy your `Instance Id`, and `Secret Key`.
- Add a new entry to in your `config/services.php` file:
```php
Expand All @@ -66,7 +66,7 @@ Before using this package you should set up a Pusher Beams account. Here are the

Now you can use the channel in your `via()` method inside the Notification class.

``` php
```php
use NotificationChannels\PusherPushNotifications\PusherChannel;
use NotificationChannels\PusherPushNotifications\PusherMessage;
use Illuminate\Notifications\Notification;
Expand Down Expand Up @@ -132,18 +132,12 @@ public function toPushNotification($notifiable)
By default, the pusher "interest" messages will be sent to will be defined using the {notifiable}.{id} convention, for example `App.User.1`,
however you can change this behaviour by including a `routeNotificationFor()` in the notifiable class.

I.e. if you are pushing notification on ``User`` model, you can go to `App\User` class and implement method:
I.e. if you are pushing notification on `User` model, you can go to `App\Models\User` class and implement method:

```
public function routeNotificationFor($channel)
```php
public function routeNotificationForPusherPushNotifications($notification): string
{
if($channel === 'PusherPushNotifications'){
return 'your.custom.interest.string';
}

$class = str_replace('\\', '.', get_class($this));

return $class.'.'.$this->getKey();
return 'your.custom.interest.string';
}
```

Expand All @@ -168,7 +162,7 @@ Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recen

## Testing

``` bash
```bash
$ composer test
```

Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
}
],
"require": {
"php": ">=7.4",
"illuminate/events": "~7.0 || ~8.0 || ~9.0",
"illuminate/notifications": "~7.0 || ~8.0 || ~9.0",
"illuminate/queue": "~7.0 || ~8.0 || ~9.0",
"illuminate/support": "~7.0 || ~8.0 || ~9.0",
"pusher/pusher-push-notifications": "^1.1"
"php": ">=8.0",
"illuminate/events": "~8.0 || ~9.0",
"illuminate/notifications": "~8.0 || ~9.0",
"illuminate/queue": "~8.0 || ~9.0",
"illuminate/support": "~8.0 || ~9.0",
"pusher/pusher-push-notifications": "^2.0"
},
"require-dev": {
"mockery/mockery": "^1.3",
Expand Down
8 changes: 4 additions & 4 deletions src/Exceptions/CouldNotCreateMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
class CouldNotCreateMessage extends Exception
{
/**
* @param string $platform
* @param string $platform
* @return static
*/
public static function invalidPlatformGiven($platform)
public static function invalidPlatformGiven(string $platform): static
{
return new static("Platform `{$platform}` is invalid. It should be either `iOS` or `Android`.");
}

/**
* @param $platform
* @param string $platform
* @return static
*/
public static function platformConflict($platform)
public static function platformConflict(string $platform): static
{
return new static("You are trying to send an extra message to `{$platform}` while the original message is to `{$platform}`.");
}
Expand Down
12 changes: 3 additions & 9 deletions src/PusherChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,8 @@ class PusherChannel
{
public const INTERESTS = 'interests';

protected PushNotifications $beamsClient;

private Dispatcher $events;

public function __construct(PushNotifications $beamsClient, Dispatcher $events)
public function __construct(protected PushNotifications $beamsClient, private Dispatcher $events)
{
$this->beamsClient = $beamsClient;
$this->events = $events;
}

/**
Expand All @@ -49,7 +43,7 @@ public function send($notifiable, Notification $notification): void
);
} catch (Throwable $exception) {
$this->events->dispatch(
new NotificationFailed($notifiable, $notification, 'pusher-push-notifications')
new NotificationFailed($notifiable, $notification, 'pusher-push-notifications', ['exception' => $exception])
);
}
}
Expand All @@ -60,7 +54,7 @@ public function send($notifiable, Notification $notification): void
* @param mixed $notifiable
* @return string
*/
public static function defaultName($notifiable): string
public static function defaultName(mixed $notifiable): string
{
$class = str_replace('\\', '.', get_class($notifiable));

Expand Down
Loading