Completed
Push — master ( 0d6573...bd21d3 )
by Fumio
07:02
created

ExtensionServiceProvider::register()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 38
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 18
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 38
ccs 16
cts 16
cp 1
crap 1
rs 8.8571
1
<?php
2
3
namespace LaravelPlus\Extension\Providers;
4
5
use Illuminate\Support\Facades\Blade;
6
use Jumilla\Addomnipot\Laravel\Environment as AddonEnvironment;
7
use Jumilla\Addomnipot\Laravel\Registrar as AddonRegistrar;
8
use Jumilla\Addomnipot\Laravel\ClassLoader as AddonClassLoader;
9
use Jumilla\Addomnipot\Laravel\Generator as AddonGenerator;
10
use Jumilla\Addomnipot\Laravel\AliasResolver;
11
use Jumilla\Addomnipot\Laravel\Repository;
12
use Jumilla\Addomnipot\Laravel\Events\AddonWorldCreated;
13
use Jumilla\Addomnipot\Laravel\Events\AddonRegistered;
14
use Jumilla\Addomnipot\Laravel\Events\AddonBooted;
15
//use LaravelPlus\Extension\Generators\GeneratorCommandRegistrar;
16
use LaravelPlus\Extension\Templates\BladeExtension;
17
use Jumilla\Versionia\Laravel\Migrator;
18
19
class ExtensionServiceProvider extends \Illuminate\Support\ServiceProvider
20
{
21
    /**
22
     * Addon environment.
23
     *
24
     * @var \Jumilla\Addomnipot\Laravel\Environment
25
     */
26
    protected $addonEnvironment;
27
28
    /**
29
     * @var array
30
     */
31
    protected $addons;
32
33
    /**
34
     * Register the service provider.
35
     */
36 2
    public function register()
37
    {
38 2
        $app = $this->app;
39
40
        // register spec path for app
41 2
        $app['path.specs'] = $app->basePath().'/resources/specs';
42
43
        // register spec repository
44
        $app->singleton('specs', function ($app) {
45
            $loader = new Repository\FileLoader($app['files'], $app['path.specs']);
46
47
            return new Repository\NamespacedRepository($loader);
48 2
        });
49
50
        // register addon environment
51 2
        $app->instance('addon', $this->addonEnvironment = new AddonEnvironment($app));
52 2
        $app->alias('addon', AddonEnvironment::class);
53
54
        // register addon generator
55
        $app->singleton('addon.generator', function ($app) {
56
            return new AddonGenerator();
57 2
        });
58 2
        $app->alias('addon.generator', AddonGenerator::class);
59
60
        // register database migrator
61 2
        $app->singleton('database.migrator', function ($app) {
62
            return new Migrator($app['db'], $app['config']);
63 2
        });
64 2
        $app->alias('database.migrator', Migrator::class);
65
66 2
        $app['events']->fire(new AddonWorldCreated($this->addonEnvironment));
67
68 2
        $this->registerClassResolvers();
69
70 2
        (new AddonRegistrar)->register($app, $this->addonEnvironment->addons());
71
72 2
        $app['events']->fire(new AddonRegistered($this->addonEnvironment));
73 2
    }
74
75
    /**
76
     */
77 2
    protected function registerClassResolvers()
78
    {
79 2
        $addons = $this->addonEnvironment->addons();
80
81 2
        AddonClassLoader::register($this->addonEnvironment, $addons);
82
83 2
        AliasResolver::register($this->app['path'], $addons, $this->app['config']->get('app.aliases', []));
84 2
    }
85
86
    /**
87
     * Bootstrap the application events.
88
     */
89 2
    public function boot()
90
    {
91 2
        $app = $this->app;
92
93
        //
94 2
        $this->registerBladeExtensions();
95
96
        // boot all addons
97 2
        (new AddonRegistrar)->boot($app, $this->addonEnvironment->addons());
98
99 2
        $app['events']->fire(new AddonBooted($this->addonEnvironment));
100 2
    }
101
102
    /**
103
     * register blade extensions.
104
     */
105 2
    protected function registerBladeExtensions()
106
    {
107 2
        Blade::extend(BladeExtension::comment());
108
109 2
        Blade::extend(BladeExtension::script());
110 2
    }
111
}
112