Completed
Push — develop ( f6f4f1...44c5cc )
by Abdelrahman
08:42
created

PagesServiceProvider::registerCommands()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 9
rs 9.6666
c 1
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Pages\Providers;
6
7
use Rinvex\Pages\Models\Page;
8
use Illuminate\Routing\Router;
9
use Illuminate\Support\ServiceProvider;
10
use Cortex\Pages\Console\Commands\SeedCommand;
11
use Cortex\Pages\Console\Commands\InstallCommand;
12
use Cortex\Pages\Console\Commands\MigrateCommand;
13
use Cortex\Pages\Console\Commands\PublishCommand;
14
use Cortex\Pages\Console\Commands\RollbackCommand;
15
use Illuminate\Database\Eloquent\Relations\Relation;
16
17
class PagesServiceProvider extends ServiceProvider
18
{
19
    /**
20
     * The commands to be registered.
21
     *
22
     * @var array
23
     */
24
    protected $commands = [
25
        SeedCommand::class => 'command.cortex.pages.seed',
26
        InstallCommand::class => 'command.cortex.pages.install',
27
        MigrateCommand::class => 'command.cortex.pages.migrate',
28
        PublishCommand::class => 'command.cortex.pages.publish',
29
        RollbackCommand::class => 'command.cortex.pages.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
        $this->mergeConfigFrom(realpath(__DIR__.'/../../config/config.php'), 'cortex.pages');
44
45
        // Register console commands
46
        ! $this->app->runningInConsole() || $this->registerCommands();
47
    }
48
49
    /**
50
     * Bootstrap any application services.
51
     *
52
     * @return void
53
     */
54
    public function boot(Router $router): void
55
    {
56
        // Bind route models and constrains
57
        $router->pattern('page', '[0-9a-z\._-]+');
58
        $router->model('page', Page::class);
59
60
        // Map relations
61
        Relation::morphMap([
62
            'page' => config('rinvex.pages.models.page'),
63
        ]);
64
65
        // Load resources
66
        require __DIR__.'/../../routes/breadcrumbs.php';
67
        $this->loadRoutesFrom(__DIR__.'/../../routes/web.php');
68
        $this->loadViewsFrom(__DIR__.'/../../resources/views', 'cortex/pages');
69
        $this->loadTranslationsFrom(__DIR__.'/../../resources/lang', 'cortex/pages');
70
        ! $this->app->runningInConsole() || $this->loadMigrationsFrom(__DIR__.'/../../database/migrations');
71
        $this->app->afterResolving('blade.compiler', function () {
72
            require __DIR__.'/../../routes/menus.php';
73
        });
74
75
        // Publish Resources
76
        ! $this->app->runningInConsole() || $this->publishResources();
77
    }
78
79
    /**
80
     * Publish resources.
81
     *
82
     * @return void
83
     */
84
    protected function publishResources(): void
85
    {
86
        $this->publishes([realpath(__DIR__.'/../../config/config.php') => config_path('cortex.pages.php')], 'cortex-pages-config');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 131 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
        $this->publishes([realpath(__DIR__.'/../../database/migrations') => database_path('migrations')], 'cortex-pages-migrations');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 133 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...
88
        $this->publishes([realpath(__DIR__.'/../../resources/lang') => resource_path('lang/vendor/cortex/pages')], 'cortex-pages-lang');
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...
89
        $this->publishes([realpath(__DIR__.'/../../resources/views') => resource_path('views/vendor/cortex/pages')], 'cortex-pages-views');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 139 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...
90
    }
91
92
    /**
93
     * Register console commands.
94
     *
95
     * @return void
96
     */
97
    protected function registerCommands(): void
98
    {
99
        // Register artisan commands
100
        foreach ($this->commands as $key => $value) {
101
            $this->app->singleton($value, $key);
102
        }
103
104
        $this->commands(array_values($this->commands));
105
    }
106
}
107