This repository was archived by the owner on May 30, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlasherLivewireServiceProvider.php
More file actions
64 lines (55 loc) · 1.75 KB
/
FlasherLivewireServiceProvider.php
File metadata and controls
64 lines (55 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
declare(strict_types=1);
namespace Flasher\Livewire;
use Flasher\Prime\Notification\NotificationBuilder;
use Illuminate\Foundation\Application;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
use Livewire\Livewire;
final class FlasherLivewireServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application events.
*/
public function boot()
{
NotificationBuilder::macro('livewire', function (array $context = []) {
return $this->withStamp(new LivewireStamp($context));
});
Livewire::listen('component.dehydrate', function ($component, $response) {
$data = $this->app['flasher.response_manager']->render(array(
'stamps' => LivewireStamp::class,
), 'array');
if (count($data['envelopes']) > 0) {
$data['context']['livewire'] = $response->fingerprint;
$response->effects['dispatches'][] = [
'event' => 'flasher:render',
'data' => $data,
];
}
});
Blade::directive('flasher_livewire_render', function () {
return "<?php echo app('flasher.livewire_response_manager')->render(); ?>";
});
}
/**
* Register the service provider.
*/
public function register()
{
$this->app->singleton('flasher.livewire_response_manager', function (Application $app) {
return new LivewireResponseManager($app['flasher.config']);
});
}
/**
* Get the services provided by the provider.
*
* @return string[]
*/
public function provides()
{
return array(
'flasher.livewire_response_manager',
);
}
}