-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathMercuriusServiceProvider.php
More file actions
executable file
·129 lines (109 loc) · 3.68 KB
/
MercuriusServiceProvider.php
File metadata and controls
executable file
·129 lines (109 loc) · 3.68 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
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
<?php
namespace Launcher\Mercurius;
use Carbon\Carbon;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Routing\Router;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\ServiceProvider;
use Launcher\Mercurius\Commands\InstallCommand;
class MercuriusServiceProvider extends ServiceProvider
{
use EventMap;
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot(Router $router)
{
$this->loadRoutesFrom(__DIR__.'/../routes/web.php');
$this->loadViewsFrom(__DIR__.'/../publishable/views', 'mercurius');
$this->loadTranslationsFrom(__DIR__.'/../publishable/lang', 'mercurius');
$this->registerEvents();
require __DIR__.'/../routes/channels.php';
}
/**
* Register the application services.
*
* @return void
*/
public function register()
{
$this->registerPublishable();
$this->mergeConfigFrom(__DIR__.'/../publishable/config/mercurius.php', 'mercurius');
$this->loadHelpers();
if ($this->app->runningInConsole()) {
$this->registerConsoleCommands();
}
$this->app->singleton('mercurius', function () {
return new Mercurius();
});
}
/**
* Register publishable files.
*
* @return void
*/
protected function registerPublishable()
{
$path = __DIR__.'/../publishable/';
$publishable = [
'mercurius-config' => ["{$path}config/mercurius.php" => config_path('mercurius.php')],
'mercurius-public' => ["{$path}public" => public_path('vendor/mercurius')],
'mercurius-sass' => [__DIR__.'/../resources/sass/' => resource_path('sass/vendor/mercurius')],
'mercurius-js' => [__DIR__.'/../resources/js/' => resource_path('js/vendor/mercurius')],
'mercurius-seeds' => ["{$path}database/seeds/" => database_path('seeds')],
'mercurius-lang' => ["{$path}lang/" => resource_path('lang')],
'mercurius-views' => ["{$path}views/" => resource_path('views/vendor/mercurius')],
];
foreach ($publishable as $group => $paths) {
$this->publishes($paths, $group);
}
$this->registerPublishableMigrations();
}
/**
* Register publishable migration files.
*/
private function registerPublishableMigrations()
{
//if (!Schema::hasTable('mercurius_messages')) {
$date = Carbon::now()->format('Y_m_d_His');
$path = __DIR__ . '/../publishable/database/migrations/';
$_migrations = [
"${path}add_mercurius_user_fields.php" => database_path("migrations/${date}_add_mercurius_user_fields.php"),
"${path}create_mercurius_messages_table.php" => database_path("migrations/${date}_create_mercurius_messages_table.php"),
];
$this->publishes($_migrations, 'mercurius-migrations');
//}
}
/**
* Register the commands accessible from the Console.
*/
private function registerConsoleCommands()
{
$this->commands(InstallCommand::class);
}
/**
* Load helpers.
*/
protected function loadHelpers()
{
foreach (glob(__DIR__.'/Helpers/*.php') as $filename) {
require_once $filename;
}
}
/**
* Register job events.
*
* @return void
*/
protected function registerEvents()
{
$events = $this->app->make(Dispatcher::class);
foreach ($this->events as $event => $listeners) {
foreach ($listeners as $listener) {
$events->listen($event, $listener);
}
}
}
}