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