Skip to content
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
7 changes: 2 additions & 5 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ jobs:
strategy:
fail-fast: true
matrix:
php: [ 7.4, 8.0 ]
php: [ 7.3, 8.0 ]
laravel: [ 8.* ]
include:
- laravel: 8.*
testbench: 6.*

name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }}

Expand All @@ -35,7 +32,7 @@ jobs:

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update
composer update --prefer-dist --no-interaction --no-progress

- name: Execute tests
Expand Down
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Changelog

All notable changes to `laravel-sns-broadcast-driver` will be documented in this file.
All notable changes to `laravel-sns-broadcaster` will be documented in this file.

## 0.1.0 - 2021-06-30
## 0.1.0 - 2021-07-13

- first release
- First release supporting PHP7.3+ and Laravel 8+
2 changes: 0 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ Before submitting a pull request:

## Requirements

If the project maintainer has any additional requirements, you will find them listed here.

- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](https://pear.php.net/package/PHP_CodeSniffer).

- **Add tests!** - Your patch won't be accepted if it doesn't have tests.
Expand Down
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Laravel SNS Broadcaster
# Laravel 8 SNS Broadcaster

[![Latest Version on Packagist](https://img.shields.io/packagist/v/pod-point/laravel-sns-broadcast-driver.svg?style=flat-square)](https://packagist.org/packages/pod-point/laravel-sns-broadcast-driver)
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/pod-point/laravel-sns-broadcast-driver/run-tests?label=tests)
[![Latest Version on Packagist](https://img.shields.io/packagist/v/pod-point/laravel-sns-broadcaster.svg?style=flat-square)](https://packagist.org/packages/pod-point/laravel-sns-broadcaster)
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/pod-point/laravel-sns-broadcaster/run-tests?label=tests)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
[![Total Downloads](https://img.shields.io/packagist/dt/pod-point/laravel-sns-broadcast-driver.svg?style=flat-square)](https://packagist.org/packages/pod-point/laravel-sns-broadcast-driver)
[![Total Downloads](https://img.shields.io/packagist/dt/pod-point/laravel-sns-broadcaster.svg?style=flat-square)](https://packagist.org/packages/pod-point/laravel-sns-broadcaster)

This package adds support for broadcasting events via SNS (Simple Notification Service).

Expand All @@ -27,7 +27,7 @@ Add the sns driver to `config/broadcasting.php` in the `connections` array:
],
```

Update the `.env` to use the driver and add the AWS values:
Update your `.env` to use the driver and add the AWS values:

```dotenv
BROADCAST_DRIVER=sns
Expand Down Expand Up @@ -74,7 +74,7 @@ public function broadcastOn($event)

By default, the package will publish the default Laravel payload, but you can transform the data that is published by transforming the data using `broadcastWith`.

Here you, can define exactly what payload gets published.
Here you can define exactly what payload gets published.

The `broadcastWith()` method receives an `$event` parameter that specifies the type of action performed, e.g. created.

Expand All @@ -98,11 +98,11 @@ public function broadcastWith($event)

#### Defining which actions are publishable

By default, the following actions performed on a Model will be published:
By default, the following actions performed on a Model will be published:

`created`, `updated`, `deleted` and if soft delete is enabled, `trashed`, `restored`.
`created`, `updated`, `deleted` and if soft delete is enabled: `trashed`, `restored`.

To only publish specific actions from the list above, add a `broadcastEvents` method the model and define an array of the publishable actions:
To only publish specific actions from the list above, add a `broadcastEvents` method to the model and define an array of the publishable actions:

```injectablephp
/**
Expand All @@ -116,7 +116,7 @@ public function broadcastEvents()
}
```

Now, only the created and updated events for this Model will be published.
Now only the created and updated events for this Model will be published.

### Custom Events

Expand Down Expand Up @@ -146,6 +146,7 @@ public function broadcastOn()
```

#### Customizing the published data

By default, all public properties on the Event will be added to the payload that is published.

Unlike a Model Event, you will need to manually set an action as a public property to the Event if you wish to see it in the payload.
Expand Down Expand Up @@ -246,9 +247,9 @@ Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
## Credits

- [laravel-sns-broadcaster](https://github.com/maxgaurav/laravel-sns-broadcaster) for some inspiration
- [Laravel Package Development](https://laravelpackage.com) documentation by [John Braun](https://github.com/Jhnbrn90)
- [Laravel Package Development](https://laravelpackage.com) documentation by [John Braun](https://github.com/Jhnbrn90)
- [Pod Point](https://github.com/pod-point)
- [All Contributors](https://github.com/pod-point/laravel-sns-broadcast-driver/graphs/contributors)
- [All Contributors](https://github.com/pod-point/laravel-sns-broadcaster/graphs/contributors)

## License

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "pod-point/laravel-sns-broadcaster",
"description": "A broadcast driver that allows broadcast events to be published to SNS.",
"keywords": ["laravel", "sns", "broadcast"],
"homepage": "https://github.com/pod-point/laravel-sns-broadcast-driver",
"homepage": "https://github.com/pod-point/laravel-sns-broadcaster",
"license": "MIT",
"authors": [
{
Expand All @@ -11,7 +11,7 @@
}
],
"require": {
"php": "^7.4|^8.0",
"php": "^7.3|^8.0",
"ext-json": "*",
"illuminate/support": "^8.0",
"aws/aws-sdk-php-laravel": "^3.6"
Expand Down
18 changes: 18 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
beStrictAboutTestsThatDoNotTestAnything="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
>
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
2 changes: 1 addition & 1 deletion src/BroadcastableModelEventOccurred.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class BroadcastableModelEventOccurred extends EloquentBroadcastableModelEventOcc
*
* @return array
*/
public function broadcastWith()
public function broadcastWith(): array
{
return method_exists($this->model, 'broadcastWith') ? $this->model->broadcastWith($this->event) : [
'model' => $this->model->toArray(),
Expand Down
13 changes: 7 additions & 6 deletions src/Broadcasters/SnsBroadcaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ class SnsBroadcaster extends Broadcaster
/**
* @var SnsClient
*/
protected SnsClient $snsClient;
protected $snsClient;

/**
* @var string
*/
protected string $arnPrefix;
protected $arnPrefix;

/**
* SnsBroadcaster constructor.
Expand All @@ -31,11 +31,12 @@ public function __construct(string $arnPrefix)

/**
* @inheritDoc
* @param array $channels
* @param $event
* @param array $payload
* @param array $channels
* @param string $event
* @param array $payload
* @return void
*/
public function broadcast(array $channels, $event, array $payload = [])
public function broadcast(array $channels, $event, array $payload = []): void
{
$this->snsClient->publish([
'TopicArn' => $this->topicName($channels),
Expand Down
10 changes: 5 additions & 5 deletions src/BroadcastsEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ public function newBroadcastableModelEvent($event)
/**
* Broadcast the given event instance if channels are configured for the model event.
*
* @param mixed $instance
* @param string $event
* @param mixed $channels
* @param mixed $instance
* @param string $event
* @param mixed $channels
* @return \Illuminate\Broadcasting\PendingBroadcast|null|void
*/
protected function broadcastIfBroadcastChannelsExistForEvent($instance, $event, $channels = null)
protected function broadcastIfBroadcastChannelsExistForEvent($instance, string $event, $channels = null)
{
if (in_array($event, $this->broadcastEvents())) {
return $this->eloquentBroadcastIfBroadcastChannelsExistForEvent($instance, $event, $channels);
Expand All @@ -54,7 +54,7 @@ protected function broadcastIfBroadcastChannelsExistForEvent($instance, $event,
*
* @return array
*/
public function broadcastEvents()
public function broadcastEvents(): array
{
return ['created', 'updated', 'trashed', 'restored', 'deleted'];
}
Expand Down
4 changes: 2 additions & 2 deletions src/SnsBroadcasterServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class SnsBroadcasterServiceProvider extends ServiceProvider
*
* @return void
*/
public function register()
public function register(): void
{
$this->app->bind(EloquentBroadcastableModelEventOccurred::class, BroadcastableModelEventOccurred::class);
}
Expand All @@ -28,7 +28,7 @@ public function register()
* @return void
* @throws BindingResolutionException
*/
public function boot()
public function boot(): void
{
$this->app->singleton(SnsClient::class, function () {
$config = [
Expand Down
6 changes: 3 additions & 3 deletions tests/Dummies/Events/UserRetrieved.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ class UserRetrieved implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;

public string $action = 'RETRIEVED';
public $action = 'RETRIEVED';

public string $foo = 'bar';
public $foo = 'bar';

/**
* @var User
*/
public User $user;
public $user;

/**
* Create a new event instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
use Illuminate\Queue\SerializesModels;
use PodPoint\SnsBroadcaster\Tests\Dummies\Models\User;

class UserRetrievedWithBroadcastWith implements ShouldBroadcast
class UserRetrievedWithCustomPayload implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;

public string $action = 'RETRIEVED';
public $action = 'RETRIEVED';

/**
* @var User
*/
public User $user;
public $user;

/**
* Create a new event instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Illuminate\Database\Eloquent\Model;
use PodPoint\SnsBroadcaster\BroadcastsEvents;

class UserWithBroadcastingEventsWithBroadcastEvents extends Model
class UserWithBroadcastingEventsForSpecificEvents extends Model
{
use BroadcastsEvents;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Illuminate\Database\Eloquent\Model;
use PodPoint\SnsBroadcaster\BroadcastsEvents;

class UserWithBroadcastingEventsWithBroadcastWith extends Model
class UserWithBroadcastingEventsWithCustomPayload extends Model
{
use BroadcastsEvents;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Illuminate\Database\Eloquent\Model;
use PodPoint\SnsBroadcaster\BroadcastsEvents;

class UserWithBroadcastingEventsWithBroadcastWithAndBroadcastEvents extends Model
class UserWithBroadcastingEventsWithCustomPayloadForSpecificEvents extends Model
{
use BroadcastsEvents;

Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/CustomEventsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Aws\Sns\SnsClient;
use Mockery;
use PodPoint\SnsBroadcaster\Tests\Dummies\Events\UserRetrieved;
use PodPoint\SnsBroadcaster\Tests\Dummies\Events\UserRetrievedWithBroadcastWith;
use PodPoint\SnsBroadcaster\Tests\Dummies\Events\UserRetrievedWithCustomPayload;
use PodPoint\SnsBroadcaster\Tests\Dummies\Models\User;
use PodPoint\SnsBroadcaster\Tests\TestCase;

Expand Down Expand Up @@ -63,6 +63,6 @@ public function test_broadcasts_custom_event_with_custom_payload()
&& $message['data']['foo'] == 'baz';
}));

event(new UserRetrievedWithBroadcastWith($user));
event(new UserRetrievedWithCustomPayload($user));
}
}
14 changes: 7 additions & 7 deletions tests/Unit/ModelEventsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
use Aws\Sns\SnsClient;
use Mockery;
use PodPoint\SnsBroadcaster\Tests\Dummies\Models\UserWithBroadcastingEvents;
use PodPoint\SnsBroadcaster\Tests\Dummies\Models\UserWithBroadcastingEventsWithBroadcastEvents;
use PodPoint\SnsBroadcaster\Tests\Dummies\Models\UserWithBroadcastingEventsWithBroadcastWith;
use PodPoint\SnsBroadcaster\Tests\Dummies\Models\UserWithBroadcastingEventsWithBroadcastWithAndBroadcastEvents;
use PodPoint\SnsBroadcaster\Tests\Dummies\Models\UserWithBroadcastingEventsForSpecificEvents;
use PodPoint\SnsBroadcaster\Tests\Dummies\Models\UserWithBroadcastingEventsWithCustomPayload;
use PodPoint\SnsBroadcaster\Tests\Dummies\Models\UserWithBroadcastingEventsWithCustomPayloadForSpecificEvents;
use PodPoint\SnsBroadcaster\Tests\TestCase;

class ModelEventsTest extends TestCase
Expand Down Expand Up @@ -60,7 +60,7 @@ public function test_broadcasts_model_event_with_custom_payload()
&& $message['data']['foo'] == 'bar';
}));

UserWithBroadcastingEventsWithBroadcastWith::create($userData);
UserWithBroadcastingEventsWithCustomPayload::create($userData);
}

/** @test */
Expand All @@ -70,7 +70,7 @@ public function test_broadcasts_model_event_with_specified_event()

$this->app->instance(SnsClient::class, $mocked);

$user = UserWithBroadcastingEventsWithBroadcastEvents::create([
$user = UserWithBroadcastingEventsForSpecificEvents::create([
'name' => 'Foo Bar',
'email' => 'model-event-3@email.com',
'password' => 'password',
Expand All @@ -96,7 +96,7 @@ public function test_does_not_broadcast_model_event_without_specified_event()

$mocked->shouldNotHaveReceived('publish');

$user = UserWithBroadcastingEventsWithBroadcastEvents::create([
$user = UserWithBroadcastingEventsForSpecificEvents::create([
'name' => 'Foo Bar',
'email' => 'model-event-4@email.com',
'password' => 'password',
Expand All @@ -112,7 +112,7 @@ public function test_broadcasts_model_event_with_specified_event_and_custom_payl

$this->app->instance(SnsClient::class, $mocked);

$user = UserWithBroadcastingEventsWithBroadcastWithAndBroadcastEvents::create([
$user = UserWithBroadcastingEventsWithCustomPayloadForSpecificEvents::create([
'name' => 'Foo Bar',
'email' => 'model-event-5@email.com',
'password' => 'password',
Expand Down