-
Notifications
You must be signed in to change notification settings - Fork 91
Expand file tree
/
Copy pathNotificationServiceProvider.php
More file actions
97 lines (82 loc) · 3.09 KB
/
Copy pathNotificationServiceProvider.php
File metadata and controls
97 lines (82 loc) · 3.09 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php namespace Krucas\Notification;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Support\ServiceProvider;
use Krucas\Notification\Middleware\NotificationMiddleware;
class NotificationServiceProvider extends ServiceProvider
{
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = false;
/**
* Bootstrap the application events.
*
* @param \Illuminate\Contracts\Events\Dispatcher $dispatcher
* @return void
*/
public function boot(Dispatcher $dispatcher)
{
$this->publishes(array(
__DIR__ . '/../../config/notification.php' => config_path('notification.php'),
), 'config');
$dispatcher->subscribe('Krucas\Notification\Subscriber');
$this->app->afterResolving('blade.compiler', function ($bladeCompiler) {
$bladeCompiler->directive('notification', function ($container = null) {
if (strcasecmp('()', $container) === 0) {
$container = null;
}
return "<?php echo app('notification')->container({$container})->show(); ?>";
});
});
}
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->mergeConfigFrom(__DIR__ . '/../../config/notification.php', 'notification');
$this->app->singleton('notification', function ($app) {
$config = $app['config'];
$notification = new Notification(
$config->get('notification.default_container'),
$config->get('notification.default_types'),
$config->get('notification.types'),
$config->get('notification.laravel_validation_error_type'),
$config->get('notification.default_format'),
$config->get('notification.format'),
$config->get('notification.default_formats'),
$config->get('notification.formats')
);
$notification->setEventDispatcher($app['events']);
return $notification;
});
$this->app->alias('notification', 'Krucas\Notification\Notification');
$this->app->singleton('Krucas\Notification\Subscriber', function ($app) {
return new Subscriber($app['session.store'], $app['config']['notification.session_key']);
});
$this->app->singleton('Krucas\Notification\Middleware\NotificationMiddleware', function ($app) {
return new NotificationMiddleware(
$app['session.store'],
$app['notification'],
$app['config']->get('notification.session_key')
);
});
}
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return array(
'Krucas\Notification\Notification',
'Krucas\Notification\Subscriber',
'notification',
);
}
}