Completed
Push — master ( 7b2d65...ab471b )
by Nikita
55:36 queued 38:17
created

SeoServiceProvider::bootDirectives()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
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 LaraComponents\Seo\Title;
6
use Illuminate\Support\Facades\Blade;
7
use Illuminate\Support\ServiceProvider;
8
9
class SeoServiceProvider extends ServiceProvider
10
{
11
    /**
12
     * Bootstrap any application services.
13
     *
14
     * @return void
15
     */
16
    public function boot()
17
    {
18
        $this->bootConfig();
19
        $this->bootDirectives();
20
    }
21
22
    protected function bootConfig()
23
    {
24
        $configFile = __DIR__.'/../config/seo.php';
25
26
        $this->publishes([
27
            $configFile => config_path('seo.php'),
28
        ]);
29
30
        $this->mergeConfigFrom($configFile, 'seo');
31
    }
32
33
    protected function bootDirectives()
34
    {
35
        Blade::directive('title', function ($expression) {
36
            return "<?php app('seo.title')->append($expression); ?>";
37
        });
38
    }
39
40
    /**
41
     * Register any application services.
42
     *
43
     * @return void
44
     */
45
    public function register()
46
    {
47
        $this->app->singleton('seo.title', function ($app) {
48
            return new Title($app->make('config')->get('seo.title'));
49
        });
50
    }
51
52
    public function provide()
53
    {
54
        return [
55
            'seo.title',
56
        ];
57
    }
58
}
59