Completed
Push — master ( 7a1e6c...8794c3 )
by Arjay
11:28
created

AssetServiceProvider::strParser()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 1 Features 0
Metric Value
cc 1
eloc 2
c 5
b 1
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php
2
3
namespace Yajra\CMS\Providers;
4
5
use Illuminate\Support\ServiceProvider;
6
use Illuminate\Database\QueryException;
7
use Yajra\CMS\Entities\FileAsset;
8
use Yajra\CMS\Repositories\FileAsset\FileAssetCacheRepository;
9
use Yajra\CMS\Repositories\FileAsset\FileAssetEloquentRepository;
10
use Yajra\CMS\Repositories\FileAsset\FileAssetRepository;
11
12
/**
13
 * Class AssetServiceProvider
14
 *
15
 * @package Yajra\CMS\Providers
16
 */
17
class AssetServiceProvider extends ServiceProvider
18
{
19
    /**
20
     * Bootstrap the application services.
21
     */
22
    public function boot()
23
    {
24
        try {
25
            $this->addAssets('css');
26
            $this->addAssets('js');
27
            $this->requireAdminDefaultAssets();
28
            $this->assetJs();
29
            $this->assetCss();
30
        } catch (QueryException $e) {
31
            // \\_(",)_//
32
        }
33
34
        FileAsset::saved(function () {
35
            $this->app['cache.store']->forget('fileAssets.all');
36
        });
37
        FileAsset::deleted(function () {
38
            $this->app['cache.store']->forget('fileAssets.all');
39
        });
40
    }
41
42
    /**
43
     * Register the application services.
44
     *
45
     * @return void
46
     */
47
    public function register()
48
    {
49
        $this->app->singleton(FileAssetRepository::class, function () {
50
            return new FileAssetCacheRepository(
51
                new FileAssetEloquentRepository,
52
                $this->app['cache.store']
53
            );
54
        });
55
    }
56
57
    /**
58
     * Load require admin default assets.
59
     */
60
    protected function requireAdminDefaultAssets()
61
    {
62
        $this->app->make(FileAssetRepository::class)->registerAdminRequireAssets();
63
    }
64
65
    /**
66
     * Load js assets.
67
     *
68
     * @return string
69
     */
70
    protected function assetJs()
71
    {
72
        return $this->app->make(FileAssetRepository::class)->registerJsBlade();
73
    }
74
75
    /**
76
     * Load css assets.
77
     *
78
     * @return string
79
     */
80
    protected function assetCss()
81
    {
82
        return $this->app->make(FileAssetRepository::class)->registerCssBlade();
83
    }
84
85
    /**
86
     * Add site assets.
87
     *
88
     * @param string $type
89
     */
90
    protected function addAssets($type)
91
    {
92
        return $this->app->make(FileAssetRepository::class)->addAsset($type);
93
    }
94
}
95