PartialCacheServiceProvider::boot()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.7
c 0
b 0
f 0
cc 2
nc 1
nop 0
1
<?php
2
3
namespace Spatie\PartialCache;
4
5
use Blade;
6
use Illuminate\Support\ServiceProvider;
7
8
class PartialCacheServiceProvider extends ServiceProvider
9
{
10
    /**
11
     * Bootstrap the application services.
12
     */
13
    public function boot()
14
    {
15
        $this->publishes([
16
            __DIR__.'/../resources/config/partialcache.php' => config_path('partialcache.php'),
17
        ], 'config');
18
19
        $directive = config('partialcache.directive');
20
21
        Blade::directive($directive, function ($expression) {
22
            if (starts_with($expression, '(')) {
23
                $expression = substr($expression, 1, -1);
24
            }
25
26
            return "<?php echo app()->make('partialcache')
27
                ->cache(array_except(get_defined_vars(), ['__data', '__path']), {$expression}); ?>";
28
        });
29
    }
30
31
    /**
32
     * Register the application services.
33
     */
34
    public function register()
35
    {
36
        $this->mergeConfigFrom(__DIR__.'/../resources/config/partialcache.php', 'partialcache');
37
38
        $this->app->singleton(PartialCache::class, PartialCache::class);
39
        $this->app->alias(PartialCache::class, 'partialcache');
40
    }
41
}
42