SeoServiceProvider   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 58
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 5 1
A bootConfig() 0 10 1
A bootDirectives() 0 6 1
A register() 0 14 1
A provide() 0 6 1
1
<?php
2
3
namespace LaraComponents\Seo;
4
5
use Illuminate\Support\Facades\Blade;
6
use Illuminate\Support\ServiceProvider;
7
use LaraComponents\Seo\Entities\Description;
8
use LaraComponents\Seo\Entities\Keywords;
9
use LaraComponents\Seo\Entities\Title;
10
11
class SeoServiceProvider extends ServiceProvider
12
{
13
    /**
14
     * Bootstrap any application services.
15
     *
16
     * @return void
17
     */
18
    public function boot()
19
    {
20
        $this->bootConfig();
21
        $this->bootDirectives();
22
    }
23
24
    protected function bootConfig()
25
    {
26
        $configFile = __DIR__.'/../config/seo.php';
27
28
        $this->publishes([
29
            $configFile => config_path('seo.php'),
30
        ]);
31
32
        $this->mergeConfigFrom($configFile, 'seo');
33
    }
34
35
    protected function bootDirectives()
36
    {
37
        Blade::directive('title', function ($expression) {
38
            return "<?php app('seo.title')->add($expression); ?>";
39
        });
40
    }
41
42
    /**
43
     * Register any application services.
44
     *
45
     * @return void
46
     */
47
    public function register()
48
    {
49
        $this->app->singleton('seo.title', function ($app) {
50
            return new Title($app->make('config')->get('seo.title'));
51
        });
52
53
        $this->app->singleton('seo.description', function ($app) {
54
            return new Description($app->make('config')->get('seo.description'));
55
        });
56
57
        $this->app->singleton('seo.keywords', function ($app) {
58
            return new Keywords($app->make('config')->get('seo.keywords'));
59
        });
60
    }
61
62
    public function provide()
63
    {
64
        return [
65
            'seo.title',
66
        ];
67
    }
68
}
69