1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Cortex\Contacts\Providers; |
6
|
|
|
|
7
|
|
|
use Illuminate\Routing\Router; |
8
|
|
|
use Illuminate\Support\ServiceProvider; |
9
|
|
|
use Rinvex\Contacts\Contracts\ContactContract; |
10
|
|
|
use Cortex\Contacts\Console\Commands\SeedCommand; |
11
|
|
|
use Cortex\Contacts\Console\Commands\InstallCommand; |
12
|
|
|
use Cortex\Contacts\Console\Commands\MigrateCommand; |
13
|
|
|
use Cortex\Contacts\Console\Commands\PublishCommand; |
14
|
|
|
use Illuminate\Database\Eloquent\Relations\Relation; |
15
|
|
|
use Cortex\Contacts\Console\Commands\RollbackCommand; |
16
|
|
|
|
17
|
|
|
class ContactsServiceProvider extends ServiceProvider |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* The commands to be registered. |
21
|
|
|
* |
22
|
|
|
* @var array |
23
|
|
|
*/ |
24
|
|
|
protected $commands = [ |
25
|
|
|
SeedCommand::class => 'command.cortex.contacts.seed', |
26
|
|
|
InstallCommand::class => 'command.cortex.contacts.install', |
27
|
|
|
MigrateCommand::class => 'command.cortex.contacts.migrate', |
28
|
|
|
PublishCommand::class => 'command.cortex.contacts.publish', |
29
|
|
|
RollbackCommand::class => 'command.cortex.contacts.rollback', |
30
|
|
|
]; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Register any application services. |
34
|
|
|
* |
35
|
|
|
* This service provider is a great spot to register your various container |
36
|
|
|
* bindings with the application. As you can see, we are registering our |
37
|
|
|
* "Registrar" implementation here. You can add your own bindings too! |
38
|
|
|
* |
39
|
|
|
* @return void |
40
|
|
|
*/ |
41
|
|
|
public function register() |
42
|
|
|
{ |
43
|
|
|
// Register console commands |
44
|
|
|
! $this->app->runningInConsole() || $this->registerCommands(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Bootstrap any application services. |
49
|
|
|
* |
50
|
|
|
* @return void |
51
|
|
|
*/ |
52
|
|
|
public function boot(Router $router) |
53
|
|
|
{ |
54
|
|
|
// Bind route models and constrains |
55
|
|
|
$router->pattern('contact', '[0-9]+'); |
56
|
|
|
$router->model('contact', ContactContract::class); |
57
|
|
|
|
58
|
|
|
// Map relations |
59
|
|
|
Relation::morphMap([ |
60
|
|
|
'contact' => config('rinvex.contacts.models.contact'), |
61
|
|
|
]); |
62
|
|
|
|
63
|
|
|
// Load resources |
64
|
|
|
require __DIR__.'/../../routes/breadcrumbs.php'; |
65
|
|
|
$this->loadRoutesFrom(__DIR__.'/../../routes/web.php'); |
66
|
|
|
$this->loadViewsFrom(__DIR__.'/../../resources/views', 'cortex/contacts'); |
67
|
|
|
$this->loadTranslationsFrom(__DIR__.'/../../resources/lang', 'cortex/contacts'); |
68
|
|
|
$this->app->afterResolving('blade.compiler', function () { |
69
|
|
|
require __DIR__.'/../../routes/menus.php'; |
70
|
|
|
}); |
71
|
|
|
|
72
|
|
|
// Publish Resources |
73
|
|
|
! $this->app->runningInConsole() || $this->publishResources(); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Publish resources. |
78
|
|
|
* |
79
|
|
|
* @return void |
80
|
|
|
*/ |
81
|
|
|
protected function publishResources() |
82
|
|
|
{ |
83
|
|
|
$this->publishes([realpath(__DIR__.'/../../resources/lang') => resource_path('lang/vendor/cortex/contacts')], 'cortex-contacts-lang'); |
|
|
|
|
84
|
|
|
$this->publishes([realpath(__DIR__.'/../../resources/views') => resource_path('views/vendor/cortex/contacts')], 'cortex-contacts-views'); |
|
|
|
|
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Register console commands. |
89
|
|
|
* |
90
|
|
|
* @return void |
91
|
|
|
*/ |
92
|
|
|
protected function registerCommands() |
93
|
|
|
{ |
94
|
|
|
// Register artisan commands |
95
|
|
|
foreach ($this->commands as $key => $value) { |
96
|
|
|
$this->app->singleton($value, function ($app) use ($key) { |
|
|
|
|
97
|
|
|
return new $key(); |
98
|
|
|
}); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
$this->commands(array_values($this->commands)); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
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.