SeoServiceProvider::boot()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
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