LaravelDomainRedirectServiceProvider::boot()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace Devfaysal\LaravelDomainRedirect;
4
5
use Illuminate\Support\ServiceProvider;
6
use Devfaysal\LaravelDomainRedirect\Middleware\DomainRedirect;
7
8
class LaravelDomainRedirectServiceProvider extends ServiceProvider
9
{
10
    /**
11
     * Bootstrap the application services.
12
     */
13
    public function boot()
14
    {
15
        if ($this->app->runningInConsole()) {
16
            $this->publishes([__DIR__.'/../config/laravel-domain-redirect.php' => config_path('laravel-domain-redirect.php')], 'domainRedirect');
17
        }
18
    }
19
20
    /**
21
     * Register the application services.
22
     */
23
    public function register()
24
    {
25
26
        // Automatically apply the package configuration
27
        $this->mergeConfigFrom(__DIR__.'/../config/laravel-domain-redirect.php', 'laravel-domain-redirect');
28
29
        $router = $this->app['router'];
30
31
        if (method_exists($router, 'middleware')) {
32
            $registerMethod = 'middleware';
33
        } elseif (method_exists($router, 'aliasMiddleware')) {
34
            $registerMethod = 'aliasMiddleware';
35
        } else {
36
            return;
37
        }
38
39
        $router->$registerMethod('domainRedirect', \Devfaysal\LaravelDomainRedirect\Middleware\DomainRedirect::class);
40
    }
41
}
42