1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Modules\Notification\Providers; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\ServiceProvider; |
6
|
|
|
use Modules\Core\Events\BuildingSidebar; |
7
|
|
|
use Modules\Core\Traits\CanGetSidebarClassForModule; |
8
|
|
|
use Modules\Core\Traits\CanPublishConfiguration; |
9
|
|
|
use Modules\Notification\Composers\NotificationViewComposer; |
10
|
|
|
use Modules\Notification\Entities\Notification; |
11
|
|
|
use Modules\Notification\Events\Handlers\RegisterNotificationSidebar; |
12
|
|
|
use Modules\Notification\Repositories\Cache\CacheNotificationDecorator; |
13
|
|
|
use Modules\Notification\Repositories\Eloquent\EloquentNotificationRepository; |
14
|
|
|
use Modules\Notification\Repositories\NotificationRepository; |
15
|
|
|
use Modules\Notification\Services\AsgardNotification; |
16
|
|
|
use Modules\User\Contracts\Authentication; |
17
|
|
|
|
18
|
|
|
class NotificationServiceProvider extends ServiceProvider |
19
|
|
|
{ |
20
|
|
|
use CanPublishConfiguration, CanGetSidebarClassForModule; |
21
|
|
|
/** |
22
|
|
|
* Indicates if loading of the provider is deferred. |
23
|
|
|
* |
24
|
|
|
* @var bool |
25
|
|
|
*/ |
26
|
|
|
protected $defer = false; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Register the service provider. |
30
|
|
|
* |
31
|
|
|
* @return void |
32
|
|
|
*/ |
33
|
|
|
public function register() |
34
|
|
|
{ |
35
|
|
|
$this->registerBindings(); |
36
|
|
|
$this->registerViewComposers(); |
37
|
|
|
|
38
|
|
|
$this->app['events']->listen( |
39
|
|
|
BuildingSidebar::class, |
40
|
|
|
$this->getSidebarClassForModule('blog', RegisterNotificationSidebar::class) |
41
|
|
|
); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function boot() |
45
|
|
|
{ |
46
|
|
|
$this->publishConfig('notification', 'config'); |
47
|
|
|
$this->publishConfig('notification', 'permissions'); |
48
|
|
|
$this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations'); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Get the services provided by the provider. |
53
|
|
|
* |
54
|
|
|
* @return array |
55
|
|
|
*/ |
56
|
|
|
public function provides() |
57
|
|
|
{ |
58
|
|
|
return array(); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
private function registerBindings() |
62
|
|
|
{ |
63
|
|
|
$this->app->bind( |
64
|
|
|
NotificationRepository::class, |
65
|
|
|
function () { |
66
|
|
|
$repository = new EloquentNotificationRepository(new Notification()); |
67
|
|
|
|
68
|
|
|
if (! config('app.cache')) { |
69
|
|
|
return $repository; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
return new CacheNotificationDecorator($repository); |
73
|
|
|
} |
74
|
|
|
); |
75
|
|
|
|
76
|
|
|
$this->app->bind(\Modules\Notification\Services\Notification::class, function ($app) { |
77
|
|
|
return new AsgardNotification($app[NotificationRepository::class], $app[Authentication::class]); |
78
|
|
|
}); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
private function registerViewComposers() |
82
|
|
|
{ |
83
|
|
|
view()->composer('partials.top-nav', NotificationViewComposer::class); |
|
|
|
|
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: