ContactsServiceProvider   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 5
dl 0
loc 69
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 9 3
B boot() 0 27 7
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Contacts\Providers;
6
7
use Illuminate\Routing\Router;
8
use Cortex\Contacts\Models\Contact;
9
use Illuminate\Support\ServiceProvider;
10
use Rinvex\Support\Traits\ConsoleTools;
11
use Cortex\Contacts\Console\Commands\SeedCommand;
12
use Cortex\Contacts\Console\Commands\InstallCommand;
13
use Cortex\Contacts\Console\Commands\MigrateCommand;
14
use Cortex\Contacts\Console\Commands\PublishCommand;
15
use Illuminate\Database\Eloquent\Relations\Relation;
16
use Cortex\Contacts\Console\Commands\RollbackCommand;
17
18
class ContactsServiceProvider extends ServiceProvider
19
{
20
    use ConsoleTools;
21
22
    /**
23
     * The commands to be registered.
24
     *
25
     * @var array
26
     */
27
    protected $commands = [
28
        SeedCommand::class => 'command.cortex.contacts.seed',
29
        InstallCommand::class => 'command.cortex.contacts.install',
30
        MigrateCommand::class => 'command.cortex.contacts.migrate',
31
        PublishCommand::class => 'command.cortex.contacts.publish',
32
        RollbackCommand::class => 'command.cortex.contacts.rollback',
33
    ];
34
35
    /**
36
     * Register any application services.
37
     *
38
     * This service provider is a great spot to register your various container
39
     * bindings with the application. As you can see, we are registering our
40
     * "Registrar" implementation here. You can add your own bindings too!
41
     *
42
     * @return void
43
     */
44
    public function register(): void
45
    {
46
        // Bind eloquent models to IoC container
47
        $this->app['config']['rinvex.contacts.models.contact'] === Contact::class
48
        || $this->app->alias('rinvex.contacts.contact', Contact::class);
49
50
        // Register console commands
51
        ! $this->app->runningInConsole() || $this->registerCommands();
52
    }
53
54
    /**
55
     * Bootstrap any application services.
56
     *
57
     * @return void
58
     */
59
    public function boot(Router $router): void
60
    {
61
        // Bind route models and constrains
62
        $router->pattern('contact', '[a-zA-Z0-9-]+');
63
        $router->model('contact', config('rinvex.contacts.models.contact'));
64
65
        // Map relations
66
        Relation::morphMap([
67
            'contact' => config('rinvex.contacts.models.contact'),
68
        ]);
69
70
        // Load resources
71
        $this->loadRoutesFrom(__DIR__.'/../../routes/web/adminarea.php');
72
        $this->loadRoutesFrom(__DIR__.'/../../routes/web/managerarea.php');
73
        $this->loadViewsFrom(__DIR__.'/../../resources/views', 'cortex/contacts');
74
        $this->loadTranslationsFrom(__DIR__.'/../../resources/lang', 'cortex/contacts');
75
        $this->app->runningInConsole() || $this->app->afterResolving('blade.compiler', function () {
76
            $accessarea = $this->app['request']->route('accessarea');
77
            ! file_exists($menus = __DIR__."/../../routes/menus/{$accessarea}.php") || require $menus;
78
            ! file_exists($breadcrumbs = __DIR__."/../../routes/breadcrumbs/{$accessarea}.php") || require $breadcrumbs;
79
        });
80
81
        // Publish Resources
82
        ! $this->app->runningInConsole() || $this->publishesLang('cortex/contacts', true);
83
        ! $this->app->runningInConsole() || $this->publishesViews('cortex/contacts', true);
84
        ! $this->app->runningInConsole() || $this->publishesMigrations('cortex/contacts', true);
85
    }
86
}
87