PagesServiceProvider   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 9 3
B boot() 0 29 8
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Pages\Providers;
6
7
use Cortex\Pages\Models\Page;
8
use Illuminate\Routing\Router;
9
use Illuminate\Support\ServiceProvider;
10
use Rinvex\Support\Traits\ConsoleTools;
11
use Cortex\Pages\Console\Commands\SeedCommand;
12
use Cortex\Pages\Console\Commands\InstallCommand;
13
use Cortex\Pages\Console\Commands\MigrateCommand;
14
use Cortex\Pages\Console\Commands\PublishCommand;
15
use Cortex\Pages\Console\Commands\RollbackCommand;
16
use Illuminate\Database\Eloquent\Relations\Relation;
17
18
class PagesServiceProvider 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.pages.seed',
29
        InstallCommand::class => 'command.cortex.pages.install',
30
        MigrateCommand::class => 'command.cortex.pages.migrate',
31
        PublishCommand::class => 'command.cortex.pages.publish',
32
        RollbackCommand::class => 'command.cortex.pages.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.pages.models.page'] === Page::class
48
        || $this->app->alias('rinvex.pages.page', Page::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('page', '[a-zA-Z0-9-]+');
63
        $router->model('page', config('rinvex.pages.models.page'));
64
65
        // Map relations
66
        Relation::morphMap([
67
            'page' => config('rinvex.pages.models.page'),
68
        ]);
69
70
        // Load resources
71
        $this->loadRoutesFrom(__DIR__.'/../../routes/web/adminarea.php');
72
        $this->loadRoutesFrom(__DIR__.'/../../routes/web/frontarea.php');
73
        $this->loadRoutesFrom(__DIR__.'/../../routes/web/managerarea.php');
74
        $this->loadViewsFrom(__DIR__.'/../../resources/views', 'cortex/pages');
75
        $this->loadTranslationsFrom(__DIR__.'/../../resources/lang', 'cortex/pages');
76
        $this->app->runningInConsole() || $this->app->afterResolving('blade.compiler', function () {
77
            $accessarea = $this->app['request']->route('accessarea');
78
            ! file_exists($menus = __DIR__."/../../routes/menus/{$accessarea}.php") || require $menus;
79
            ! file_exists($breadcrumbs = __DIR__."/../../routes/breadcrumbs/{$accessarea}.php") || require $breadcrumbs;
80
        });
81
82
        // Publish Resources
83
        ! $this->app->runningInConsole() || $this->publishesLang('cortex/pages', true);
84
        ! $this->app->runningInConsole() || $this->publishesViews('cortex/pages', true);
85
        ! $this->app->runningInConsole() || $this->publishesConfig('cortex/pages', true);
86
        ! $this->app->runningInConsole() || $this->publishesMigrations('cortex/pages', true);
87
    }
88
}
89