PackageServiceProvider::publishAll()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
ccs 0
cts 4
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
    /**
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