1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Rinvex\Contacts\Providers; |
6
|
|
|
|
7
|
|
|
use Illuminate\Support\ServiceProvider; |
8
|
|
|
use Rinvex\Contacts\Contracts\ContactContract; |
9
|
|
|
use Rinvex\Contacts\Console\Commands\MigrateCommand; |
10
|
|
|
|
11
|
|
|
class ContactsServiceProvider extends ServiceProvider |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* The commands to be registered. |
15
|
|
|
* |
16
|
|
|
* @var array |
17
|
|
|
*/ |
18
|
|
|
protected $commands = [ |
19
|
|
|
MigrateCommand::class => 'command.rinvex.contacts.migrate', |
20
|
|
|
]; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* {@inheritdoc} |
24
|
|
|
*/ |
25
|
|
|
public function register() |
26
|
|
|
{ |
27
|
|
|
// Merge config |
28
|
|
|
$this->mergeConfigFrom(realpath(__DIR__.'/../../config/config.php'), 'rinvex.contacts'); |
29
|
|
|
|
30
|
|
|
// Bind eloquent models to IoC container |
31
|
|
|
$this->app->singleton('rinvex.contacts.contact', function ($app) { |
32
|
|
|
return new $app['config']['rinvex.contacts.models.contact'](); |
33
|
|
|
}); |
34
|
|
|
$this->app->alias('rinvex.contacts.contact', ContactContract::class); |
35
|
|
|
|
36
|
|
|
// Register console commands |
37
|
|
|
! $this->app->runningInConsole() || $this->registerCommands(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* {@inheritdoc} |
42
|
|
|
*/ |
43
|
|
|
public function boot() |
44
|
|
|
{ |
45
|
|
|
// Load migrations |
46
|
|
|
! $this->app->runningInConsole() || $this->loadMigrationsFrom(__DIR__.'/../../database/migrations'); |
47
|
|
|
|
48
|
|
|
// Publish Resources |
49
|
|
|
! $this->app->runningInConsole() || $this->publishResources(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Publish resources. |
54
|
|
|
* |
55
|
|
|
* @return void |
56
|
|
|
*/ |
57
|
|
|
protected function publishResources() |
58
|
|
|
{ |
59
|
|
|
$this->publishes([realpath(__DIR__.'/../../config/config.php') => config_path('rinvex.contacts.php')], 'rinvex-contacts-config'); |
|
|
|
|
60
|
|
|
$this->publishes([realpath(__DIR__.'/../../database/migrations') => database_path('migrations')], 'rinvex-contacts-migrations'); |
|
|
|
|
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Register console commands. |
65
|
|
|
* |
66
|
|
|
* @return void |
67
|
|
|
*/ |
68
|
|
|
protected function registerCommands() |
69
|
|
|
{ |
70
|
|
|
// Register artisan commands |
71
|
|
|
foreach ($this->commands as $key => $value) { |
72
|
|
|
$this->app->singleton($value, function ($app) use ($key) { |
|
|
|
|
73
|
|
|
return new $key(); |
74
|
|
|
}); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
$this->commands(array_values($this->commands)); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.