LaravelTrailingSlashServiceProvider   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 49
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 8 2
A register() 0 37 1
1
<?php
2
3
namespace GNAHotelSolutions\LaravelTrailingSlash\Providers;
4
5
use GNAHotelSolutions\LaravelTrailingSlash\Routing\TrailingSlashUrlGenerator;
6
use Illuminate\Contracts\Routing\UrlGenerator;
7
use Illuminate\Support\ServiceProvider;
8
9
class LaravelTrailingSlashServiceProvider extends ServiceProvider
10
{
11
    public function boot()
12
    {
13
        if ($this->app->runningInConsole()) {
14
            $this->publishes([
15
                __DIR__ . '/../../config/config.php' => config_path('laravel-trailing-slash.php'),
16
            ], 'config');
17
        }
18
    }
19
20
    public function register()
21
    {
22
        $this->mergeConfigFrom(__DIR__ . '/../../config/config.php', 'laravel-trailing-slash');
23
24
        $this->app->singleton('url', function ($app) {
25
            $routes = $app['router']->getRoutes();
26
27
            $app->instance('routes', $routes);
28
29
            return new TrailingSlashUrlGenerator(
30
                $routes, $app->rebinding(
31
                'request',
32
                function ($app, $request) {
33
                    $app['url']->setRequest($request);
34
                }
35
            ), $app['config']['app.asset_url']
36
            );
37
        });
38
39
        $this->app->extend('url', function (UrlGenerator $url, $app) {
40
41
            $url->setSessionResolver(function () {
42
                return $this->app['session'] ?? null;
43
            });
44
45
            $url->setKeyResolver(function () {
46
                return $this->app->make('config')->get('app.key');
47
            });
48
49
            $app->rebinding('routes', function ($app, $routes) {
50
                $app['url']->setRoutes($routes);
51
            });
52
53
            return $url;
54
        });
55
56
    }
57
}
58