Completed
Push — master ( 16ebaf...a3d07b )
by Arjay
14:09
created

ThemesServiceProvider::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
cc 1
eloc 7
c 2
b 0
f 2
nc 1
nop 0
dl 0
loc 14
rs 9.4285
1
<?php
2
3
namespace Yajra\CMS\Providers;
4
5
use Illuminate\Support\ServiceProvider;
6
use Symfony\Component\Finder\Finder;
7
use Yajra\CMS\Theme\Repository;
8
use Yajra\CMS\View\ThemeViewFinder;
9
10
class ThemesServiceProvider extends ServiceProvider
11
{
12
    /**
13
     * Bootstrap the application services.
14
     *
15
     * @return void
16
     */
17
    public function boot()
18
    {
19
        /** @var \Illuminate\View\Factory $view */
20
        $view = $this->app['view'];
21
        $view->setFinder($this->app['theme.view.finder']);
22
        $view->addLocation(__DIR__ . '/../resources/views');
23
24
        // Load admin theme views.
25
        $this->loadViewsFrom(__DIR__ . '/../resources/themes/' . config('theme.backend', 'default'), 'admin');
26
27
        /** @var Repository $themes */
28
        $themes = $this->app['themes'];
29
        $themes->scan();
30
    }
31
32
    /**
33
     * Register the application services.
34
     *
35
     * @return void
36
     */
37
    public function register()
38
    {
39
        $this->app->singleton('theme.view.finder', function ($app) {
40
            $finder = new ThemeViewFinder($app['files'], $app['config']['view.paths']);
41
            $finder->setBasePath(config('theme.path', base_path('themes')) . DIRECTORY_SEPARATOR . config('theme.frontend', 'default'));
42
43
            return $finder;
44
        });
45
46
        $this->app->singleton('themes', function () {
47
            return new Repository(new Finder, $this->app['config']);
48
        });
49
50
        $this->app->alias('themes', Repository::class);
51
    }
52
}
53