Completed
Push — master ( 27c653...65cbbc )
by ARCANEDEV
03:48
created

PackageServiceProvider::getSidebarFolder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 0
cts 2
cp 0
crap 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
     * Vendor name.
21
     *
22
     * @var string
23
     */
24
    protected $vendor = 'arcanesoft';
25
26
    /* ------------------------------------------------------------------------------------------------
27
     |  Getters & Setters
28
     | ------------------------------------------------------------------------------------------------
29
     */
30
    /**
31
     * Get config key.
32
     *
33
     * @return string
34
     */
35 6
    protected function getConfigKey()
36
    {
37 6
        return Str::slug("{$this->vendor} {$this->package}", '.');
38
    }
39
40
    /**
41
     * Get the sidebar folder.
42
     *
43
     * @return string
44
     */
45
    protected function getSidebarFolder()
46
    {
47
        return $this->getConfigFolder().DS.'sidebar';
48
    }
49
50
    /**
51
     * Get the sidebar config key.
52
     *
53
     * @return string
54
     */
55
    protected function getSidebarKey()
56
    {
57
        return "{$this->vendor}.sidebar.{$this->package}";
58
    }
59
60
    /* ------------------------------------------------------------------------------------------------
61
     |  Main Functions
62
     | ------------------------------------------------------------------------------------------------
63
     */
64
    /**
65
     * Register the service provider.
66
     */
67 6
    public function register()
68
    {
69 6
        parent::register();
70
71 6
        $this->registerCoreServiceProvider();
72 6
    }
73
74
    /**
75
     * Register the Core service provider.
76
     */
77
    protected function registerCoreServiceProvider()
78
    {
79
        $this->registerProvider(CoreServiceProvider::class);
80
    }
81
82
    /* ------------------------------------------------------------------------------------------------
83
     |  Package Functions
84
     | ------------------------------------------------------------------------------------------------
85
     */
86
    /**
87
     * Publish all the package files.
88
     *
89
     * @param  bool  $load
90
     */
91
    protected function publishAll($load = true)
92
    {
93
        parent::publishAll($load);
94
95
        $this->publishSidebarItems();
96
    }
97
98
    /**
99
     * Publish the config file.
100
     */
101
    protected function publishConfig()
102
    {
103
        $this->publishes([
104
            $this->getConfigFile() => config_path("{$this->vendor}/{$this->package}.php"),
105
        ], 'config');
106
    }
107
108
    /**
109
     * Publish all the sidebar config files.
110
     */
111
    protected function publishSidebarItems()
112
    {
113
        $this->publishes([
114
            $this->getSidebarFolder() => config_path($this->vendor.DS.'sidebar'.DS.$this->package)
115
        ], 'sidebar');
116
    }
117
118
    /**
119
     * Register all the sidebar config files.
120
     */
121
    protected function registerSidebarItems()
122
    {
123
        foreach ($this->filesystem()->glob($this->getSidebarFolder().DS.'*.php') as $path) {
124
            $this->mergeConfigFrom($path, $this->getSidebarKey().'.'.basename($path, '.php'));
125
        }
126
    }
127
}
128