Completed
Push — master ( 2c7b48...621a30 )
by Nicolas
17:00
created

LaravelModulesServiceProvider::setupStubPath()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2.0116

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
ccs 6
cts 7
cp 0.8571
rs 9.4285
cc 2
eloc 5
nc 1
nop 0
crap 2.0116
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 76
    public function boot()
24
    {
25 76
        $this->registerNamespaces();
26
27 76
        $this->registerModules();
28 76
    }
29
30
    /**
31
     * Register all modules.
32
     */
33 76
    protected function registerModules()
34
    {
35 76
        $this->app->register(BootstrapServiceProvider::class);
36 76
    }
37
38
    /**
39
     * Register the service provider.
40
     */
41 76
    public function register()
42
    {
43 76
        $this->registerServices();
44 76
        $this->setupStubPath();
45 76
        $this->registerProviders();
46 76
    }
47
48
    /**
49
     * Setup stub path.
50
     */
51 76
    public function setupStubPath()
52
    {
53
        $this->app->booted(function ($app) {
54 76
            Stub::setBasePath(__DIR__ . '/Commands/stubs');
55
56 76
            if ($app['modules']->config('stubs.enabled') === true) {
57 76
                Stub::setBasePath($app['modules']->config('stubs.path'));
58
            }
59 76
        });
60 76
    }
61
62
    /**
63
     * Register package's namespaces.
64
     */
65 76
    protected function registerNamespaces()
66
    {
67 76
        $configPath = __DIR__ . '/../config/config.php';
68 76
        $this->mergeConfigFrom($configPath, 'modules');
69 76
        $this->publishes([
70 76
            $configPath => config_path('modules.php'),
71 76
        ], 'config');
72 76
    }
73
74
    /**
75
     * Register the service provider.
76
     */
77
    protected function registerServices()
78
    {
79 76
        $this->app->singleton('modules', function ($app) {
80 76
            $path = $app['config']->get('modules.paths.modules');
81
82 76
            return new Repository($app, $path);
83 76
        });
84 76
    }
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 76
    protected function registerProviders()
100
    {
101 76
        $this->app->register(ConsoleServiceProvider::class);
102 76
        $this->app->register(ContractsServiceProvider::class);
103 76
    }
104
}
105