|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Alive2212\LaravelMessageService; |
|
4
|
|
|
|
|
5
|
|
|
use Alive2212\LaravelMessageService\Console\InstallCommand; |
|
6
|
|
|
use Alive2212\LaravelMessageService\Providers\AliveLaravelMessageServiceRouteServiceProvider; |
|
7
|
|
|
use Illuminate\Support\ServiceProvider; |
|
8
|
|
|
|
|
9
|
|
|
class LaravelMessageServiceServiceProvider extends ServiceProvider |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* Perform post-registration booting of services. |
|
13
|
|
|
* |
|
14
|
|
|
* @return void |
|
15
|
|
|
*/ |
|
16
|
|
|
public function boot() |
|
17
|
|
|
{ |
|
18
|
|
|
$this->app->register(AliveLaravelMessageServiceRouteServiceProvider::class); |
|
19
|
|
|
|
|
20
|
|
|
if ($this->app->runningInConsole()) { |
|
21
|
|
|
|
|
22
|
|
|
// register jobs |
|
23
|
|
|
$this->registerJobs(); |
|
24
|
|
|
|
|
25
|
|
|
// register migrations |
|
26
|
|
|
$this->registerMigrations(); |
|
27
|
|
|
|
|
28
|
|
|
// register all commands into 'Console' folder |
|
29
|
|
|
$this->registerCommands(); |
|
30
|
|
|
} |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Register any package services. |
|
35
|
|
|
* |
|
36
|
|
|
* @return void |
|
37
|
|
|
*/ |
|
38
|
|
|
public function register() |
|
39
|
|
|
{ |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Register Package's migration files. |
|
44
|
|
|
* |
|
45
|
|
|
* @return void |
|
46
|
|
|
*/ |
|
47
|
|
|
protected function registerMigrations() |
|
48
|
|
|
{ |
|
49
|
|
|
if (LaravelMessageService::$runsMigrations) { |
|
|
|
|
|
|
50
|
|
|
$this->loadMigrationsFrom(__DIR__ . '/../database/migrations'); |
|
51
|
|
|
return; |
|
52
|
|
|
} |
|
53
|
|
|
$this->publishes([ |
|
54
|
|
|
__DIR__ . '/../database/migrations' => database_path('migrations'), |
|
55
|
|
|
], 'message-service'); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Register a database migration path. |
|
60
|
|
|
* |
|
61
|
|
|
* @param array|string $paths |
|
62
|
|
|
* @return void |
|
63
|
|
|
*/ |
|
64
|
|
|
protected function loadMigrationsFrom($paths) |
|
65
|
|
|
{ |
|
66
|
|
|
$this->app->afterResolving('migrator', function ($migrator) use ($paths) { |
|
67
|
|
|
foreach ((array)$paths as $path) { |
|
68
|
|
|
$migrator->path($path); |
|
69
|
|
|
} |
|
70
|
|
|
}); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function registerCommands() |
|
74
|
|
|
{ |
|
75
|
|
|
$consoles = scandir(__DIR__ . '/Console'); |
|
76
|
|
|
$commands = []; |
|
77
|
|
|
unset($consoles[0], $consoles[1]); |
|
78
|
|
|
foreach ($consoles as $console) { |
|
79
|
|
|
$dir = __NAMESPACE__ . '\\Console\\' . str_replace(".php", "", $console); |
|
80
|
|
|
array_push($commands, $dir); |
|
81
|
|
|
} |
|
82
|
|
|
$this->commands($commands); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* |
|
87
|
|
|
*/ |
|
88
|
|
|
public function registerJobs() |
|
89
|
|
|
{ |
|
90
|
|
|
$this->publishes([ |
|
91
|
|
|
__DIR__ . '/Jobs' => app_path('Jobs'), |
|
92
|
|
|
], "message-service"); |
|
93
|
|
|
} |
|
94
|
|
|
} |
This check looks for access to properties that are not accessible from the current context.
If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.