Completed
Push — master ( 247ae6...f93a8c )
by Nicolas
03:59
created

LaravelModulesServiceProvider::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
ccs 4
cts 4
cp 1
cc 1
eloc 3
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Nwidart\Modules;
4
5
use Illuminate\Support\ServiceProvider;
6
use Nwidart\Modules\Providers\BootstrapServiceProvider;
7
use Nwidart\Modules\Providers\ConsoleServiceProvider;
8
use Nwidart\Modules\Providers\ContractsServiceProvider;
9
use Nwidart\Modules\Support\Stub;
10
11
class LaravelModulesServiceProvider extends ServiceProvider
12
{
13
    /**
14
     * Indicates if loading of the provider is deferred.
15
     *
16
     * @var bool
17
     */
18
    protected $defer = false;
19
20
    /**
21
     * Booting the package.
22
     */
23 111
    public function boot()
24
    {
25 111
        $this->registerNamespaces();
26
27 111
        $this->registerModules();
28 111
    }
29
30
    /**
31
     * Register all modules.
32
     */
33 111
    protected function registerModules()
34
    {
35 111
        $this->app->register(BootstrapServiceProvider::class);
36 111
    }
37
38
    /**
39
     * Register the service provider.
40
     */
41 111
    public function register()
42
    {
43 111
        $this->registerServices();
44 111
        $this->setupStubPath();
45 111
        $this->registerProviders();
46 111
    }
47
48
    /**
49
     * Setup stub path.
50
     */
51 111
    public function setupStubPath()
52
    {
53
        $this->app->booted(function ($app) {
54 111
            Stub::setBasePath(__DIR__ . '/Commands/stubs');
55
56 111
            if ($app['modules']->config('stubs.enabled') === true) {
57 111
                Stub::setBasePath($app['modules']->config('stubs.path'));
58
            }
59 111
        });
60 111
    }
61
62
    /**
63
     * Register package's namespaces.
64
     */
65 111
    protected function registerNamespaces()
66
    {
67 111
        $configPath = __DIR__ . '/../config/config.php';
68 111
        $this->mergeConfigFrom($configPath, 'modules');
69 111
        $this->publishes([
70 111
            $configPath => config_path('modules.php'),
71 111
        ], 'config');
72 111
    }
73
74
    /**
75
     * Register the service provider.
76
     */
77
    protected function registerServices()
78
    {
79 111
        $this->app->singleton('modules', function ($app) {
80 111
            $path = $app['config']->get('modules.paths.modules');
81
82 111
            return new Repository($app, $path);
83 111
        });
84 111
    }
85
86
    /**
87
     * Get the services provided by the provider.
88
     *
89
     * @return array
90
     */
91
    public function provides()
92
    {
93
        return ['modules'];
94
    }
95
96
    /**
97
     * Register providers.
98
     */
99 111
    protected function registerProviders()
100
    {
101 111
        $this->app->register(ConsoleServiceProvider::class);
102 111
        $this->app->register(ContractsServiceProvider::class);
103 111
    }
104
}
105