Completed
Push — develop ( 3e565f...355715 )
by Abdelrahman
22:37
created

ContactsServiceProvider::boot()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 24
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 9
Bugs 0 Features 0
Metric Value
dl 0
loc 24
rs 8.9713
c 9
b 0
f 0
cc 3
eloc 13
nc 4
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Contacts\Providers;
6
7
use Illuminate\Routing\Router;
8
use Rinvex\Contacts\Models\Contact;
9
use Illuminate\Support\ServiceProvider;
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(): void
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): void
53
    {
54
        // Bind route models and constrains
55
        $router->pattern('contact', '[0-9]+');
56
        $router->model('contact', Contact::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->runningInConsole() || $this->loadMigrationsFrom(__DIR__.'/../../database/migrations');
69
        $this->app->afterResolving('blade.compiler', function () {
70
            require __DIR__.'/../../routes/menus.php';
71
        });
72
73
        // Publish Resources
74
        ! $this->app->runningInConsole() || $this->publishResources();
75
    }
76
77
    /**
78
     * Publish resources.
79
     *
80
     * @return void
81
     */
82
    protected function publishResources(): void
83
    {
84
        $this->publishes([realpath(__DIR__.'/../../database/migrations') => database_path('migrations')], 'cortex-contacts-migrations');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 136 characters

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.

Loading history...
85
        $this->publishes([realpath(__DIR__.'/../../resources/lang') => resource_path('lang/vendor/cortex/contacts')], 'cortex-contacts-lang');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 142 characters

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.

Loading history...
86
        $this->publishes([realpath(__DIR__.'/../../resources/views') => resource_path('views/vendor/cortex/contacts')], 'cortex-contacts-views');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 145 characters

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.

Loading history...
87
    }
88
89
    /**
90
     * Register console commands.
91
     *
92
     * @return void
93
     */
94
    protected function registerCommands(): void
95
    {
96
        // Register artisan commands
97
        foreach ($this->commands as $key => $value) {
98
            $this->app->singleton($value, $key);
99
        }
100
101
        $this->commands(array_values($this->commands));
102
    }
103
}
104