-
-
Notifications
You must be signed in to change notification settings - Fork 517
/
CanvasServiceProvider.php
139 lines (123 loc) · 3.35 KB
/
CanvasServiceProvider.php
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
namespace Canvas;
use Canvas\Console\AdminCommand;
use Canvas\Console\DigestCommand;
use Canvas\Console\InstallCommand;
use Canvas\Console\PublishCommand;
use Canvas\Events\PostViewed;
use Canvas\Listeners\CaptureView;
use Canvas\Listeners\CaptureVisit;
use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Events\Dispatcher;
use Illuminate\Support\ServiceProvider;
class CanvasServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
$this->mergeConfigFrom(__DIR__.'/../config/canvas.php', 'canvas');
}
/**
* Bootstrap any application services.
*
* @return void
* @throws BindingResolutionException
*/
public function boot()
{
$this->loadViewsFrom(__DIR__.'/../resources/views', 'canvas');
$this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'canvas');
$this->configurePublishing();
$this->configureRoutes();
$this->configureCommands();
$this->registerMigrations();
$this->registerEvents();
}
/**
* Register the events and listeners.
*
* @return void
* @throws BindingResolutionException
*/
private function registerEvents()
{
$events = $this->app->make(Dispatcher::class);
$mappings = [
PostViewed::class => [
CaptureView::class,
CaptureVisit::class,
],
];
foreach ($mappings as $event => $listeners) {
foreach ($listeners as $listener) {
$events->listen($event, $listener);
}
}
}
/**
* Configure the routes offered by the application.
*
* @return void
*/
private function configureRoutes()
{
$this->loadRoutesFrom(__DIR__.'/Http/routes.php');
}
/**
* Configure the commands offered by the application.
*
* @return void
*/
protected function configureCommands()
{
if (! $this->app->runningInConsole()) {
return;
}
$this->commands([
AdminCommand::class,
DigestCommand::class,
InstallCommand::class,
PublishCommand::class,
]);
}
/**
* Register the package's migrations.
*
* @return void
*/
private function registerMigrations()
{
if ($this->app->runningInConsole()) {
$this->loadMigrationsFrom(__DIR__.'/../database/migrations');
}
}
/**
* Configure publishing for the package.
*
* @return void
*/
private function configurePublishing()
{
if (! $this->app->runningInConsole()) {
return;
}
$this->publishes([
__DIR__.'/../public' => public_path('vendor/canvas'),
], 'canvas-assets');
$this->publishes([
__DIR__.'/../config/canvas.php' => config_path('canvas.php'),
], 'canvas-config');
$this->publishes([
__DIR__.'/../resources/lang' => resource_path('lang/vendor/canvas'),
], 'canvas-lang');
$this->publishes([
__DIR__.'/../resources/stubs/CanvasServiceProvider.stub' => app_path(
'Providers/CanvasServiceProvider.php'
),
], 'canvas-provider');
}
}