Skip to content

Commit fc21ed7

Browse files
authored
Merge pull request #2 from arnebr/feat-notification-channel
Adding notification
2 parents 0ed2ce0 + 6160f41 commit fc21ed7

File tree

4 files changed

+64
-0
lines changed

4 files changed

+64
-0
lines changed

composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
],
1818
"require": {
1919
"php": "^8.1",
20+
"carbon-cli/carbon-cli": "^1.2",
2021
"guzzlehttp/guzzle": "^7.5",
2122
"illuminate/contracts": "^9.0||^10.0",
2223
"spatie/laravel-package-tools": "^1.14.0"

src/Channels/TibberChannel.php

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Arnebr\Tibber\Channels;
4+
5+
use Arnebr\Tibber\Facades\Tibber;
6+
use Illuminate\Notifications\Notification;
7+
8+
class TibberChannel
9+
{
10+
/**
11+
* Send the given notification.
12+
*/
13+
public function send(object $notifiable, Notification $notification): void
14+
{
15+
$payload = $notification->toTibber($notifiable);
16+
Tibber::sendPushNotification($payload->title, $payload->message, $payload->screenToOpen);
17+
18+
// Send notification to the $notifiable instance...
19+
}
20+
}

src/Message/TibberMessage.php

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Arnebr\Tibber\Message;
4+
5+
use Arnebr\Tibber\Tibber;
6+
7+
class TibberMessage
8+
{
9+
public ?string $title = null;
10+
11+
public ?string $message = null;
12+
13+
public ?string $screenToOpen = Tibber::APP_HOME;
14+
15+
public function title(string $title): self
16+
{
17+
$this->title = $title;
18+
19+
return $this;
20+
}
21+
22+
public function message(string $message): self
23+
{
24+
$this->message = $message;
25+
26+
return $this;
27+
}
28+
29+
public function screenToOpen(string $screenToOpen): self
30+
{
31+
$this->screenToOpen = $screenToOpen;
32+
33+
return $this;
34+
}
35+
}

src/TibberServiceProvider.php

+8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace Arnebr\Tibber;
44

55
use Arnebr\Tibber\Commands\TibberCommand;
6+
use Illuminate\Notifications\ChannelManager;
7+
use Illuminate\Support\Facades\Notification;
68
use Spatie\LaravelPackageTools\Package;
79
use Spatie\LaravelPackageTools\PackageServiceProvider;
810

@@ -21,5 +23,11 @@ public function configurePackage(Package $package): void
2123
//->hasViews()
2224
//->hasMigration('create_laravel-tibber_table')
2325
->hasCommand(TibberCommand::class);
26+
27+
Notification::resolved(function (ChannelManager $service) {
28+
$service->extend('tibber', function ($app) {
29+
return new Channels\TibberChannel();
30+
});
31+
});
2432
}
2533
}

0 commit comments

Comments
 (0)