PackageServiceProvider   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 123
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 18.75%

Importance

Changes 0
Metric Value
dl 0
loc 123
ccs 6
cts 32
cp 0.1875
rs 10
c 0
b 0
f 0
wmc 11
lcom 2
cbo 3

9 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfigKey() 0 4 1
A getSidebarFolder() 0 4 1
A getSidebarKey() 0 4 1
A registerCoreServiceProvider() 0 4 1
A publishAll() 0 6 1
A publishConfig() 0 6 1
A publishSidebarItems() 0 6 1
A register() 0 8 2
A registerSidebarItems() 0 6 2
1
<?php namespace Arcanesoft\Core\Bases;
2
3
use Arcanedev\Support\PackageServiceProvider as ServiceProvider;
4
use Arcanesoft\Core\CoreServiceProvider;
5
use Illuminate\Support\Str;
6
7
/**
8
 * Class     PackageServiceProvider
9
 *
10
 * @package  Arcanesoft\Core\Bases
11
 * @author   ARCANEDEV <[email protected]>
12
 */
13
abstract class PackageServiceProvider extends ServiceProvider
14
{
15
    /* -----------------------------------------------------------------
16
     |  Properties
17
     | -----------------------------------------------------------------
18
     */
19
20
    /**
21
     * Vendor name.
22
     *
23
     * @var string
24
     */
25
    protected $vendor = 'arcanesoft';
26
27
    /**
28
     * Register the core service provider.
29
     *
30
     * @var bool
31
     */
32
    protected $registerCoreServiceProvider = true;
33
34
    /* -----------------------------------------------------------------
35
     |  Getters & Setters
36
     | -----------------------------------------------------------------
37
     */
38
39
    /**
40
     * Get config key.
41
     *
42
     * @return string
43
     */
44 124
    protected function getConfigKey()
45
    {
46 124
        return Str::slug("{$this->vendor} {$this->package}", '.');
47
    }
48
49
    /**
50
     * Get the sidebar folder.
51
     *
52
     * @return string
53
     */
54
    protected function getSidebarFolder()
55
    {
56
        return $this->getConfigFolder().DS.'sidebar';
57
    }
58
59
    /**
60
     * Get the sidebar config key.
61
     *
62
     * @return string
63
     */
64
    protected function getSidebarKey()
65
    {
66
        return "{$this->vendor}.sidebar.{$this->package}";
67
    }
68
69
    /* -----------------------------------------------------------------
70
     |  Main Methods
71
     | -----------------------------------------------------------------
72
     */
73
74
    /**
75
     * Register the service provider.
76
     */
77 124
    public function register()
78
    {
79 124
        parent::register();
80
81 124
        if ($this->registerCoreServiceProvider) {
82
            $this->registerCoreServiceProvider();
83
        }
84 124
    }
85
86
    /**
87
     * Register the Core service provider.
88
     */
89
    protected function registerCoreServiceProvider()
90
    {
91
        $this->registerProvider(CoreServiceProvider::class);
92
    }
93
94
    /**
95
     * Publish all the package files.
96
     *
97
     * @param  bool  $load
98
     */
99
    protected function publishAll($load = true)
100
    {
101
        parent::publishAll($load);
102
103
        $this->publishSidebarItems();
104
    }
105
106
    /**
107
     * Publish the config file.
108
     */
109
    protected function publishConfig()
110
    {
111
        $this->publishes([
112
            $this->getConfigFile() => config_path("{$this->vendor}/{$this->package}.php"),
113
        ], 'config');
114
    }
115
116
    /**
117
     * Publish all the sidebar config files.
118
     */
119
    protected function publishSidebarItems()
120
    {
121
        $this->publishes([
122
            $this->getSidebarFolder() => config_path($this->vendor.DS.'sidebar'.DS.$this->package)
123
        ], 'sidebar');
124
    }
125
126
    /**
127
     * Register all the sidebar config files.
128
     */
129
    protected function registerSidebarItems()
130
    {
131
        foreach ($this->filesystem()->glob($this->getSidebarFolder().DS.'*.php') as $path) {
132
            $this->mergeConfigFrom($path, $this->getSidebarKey().'.'.basename($path, '.php'));
133
        }
134
    }
135
}
136