Completed
Pull Request — master (#1)
by ARCANEDEV
03:50
created

PackageServiceProvider::publishConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 0
cts 5
cp 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
crap 2
1
<?php namespace Arcanesoft\Core\Bases;
2
3
use Arcanedev\Support\PackageServiceProvider as ServiceProvider;
4
5
/**
6
 * Class     PackageServiceProvider
7
 *
8
 * @package  Arcanesoft\Core\Bases
9
 * @author   ARCANEDEV <[email protected]>
10
 */
11
abstract class PackageServiceProvider extends ServiceProvider
12
{
13
    /* ------------------------------------------------------------------------------------------------
14
     |  Properties
15
     | ------------------------------------------------------------------------------------------------
16
     */
17
    /**
18
     * Vendor name.
19
     *
20
     * @var string
21
     */
22
    protected $vendor = 'arcanesoft';
23
24
    /* ------------------------------------------------------------------------------------------------
25
     |  Getters & Setters
26
     | ------------------------------------------------------------------------------------------------
27
     */
28
    /**
29
     * Get config key.
30
     *
31
     * @return string
32
     */
33
    protected function getConfigKey()
34
    {
35
        return str_slug($this->vendor . ' ' .$this->package, '.');
36
    }
37
38
    /**
39
     * Get the config repository instance.
40
     *
41
     * @return \Illuminate\Contracts\Config\Repository
42
     */
43 8
    protected function config()
44
    {
45 8
        return $this->app['config'];
46
    }
47
48
    /**
49
     * Get the filesystem instance.
50
     *
51
     * @return \Illuminate\Filesystem\Filesystem
52
     */
53
    protected function filesystem()
54
    {
55
        return $this->app['files'];
56
    }
57
58
    /**
59
     * Get the sidebar folder.
60
     *
61
     * @return string
62
     */
63
    protected function getSidebarFolder()
64
    {
65
        return $this->getConfigFolder() . DS . 'sidebar';
66
    }
67
68
    /**
69
     * Get the sidebar config key.
70
     *
71
     * @return string
72
     */
73
    protected function getSidebarKey()
74
    {
75
        return "$this->vendor.sidebar.$this->package";
76
    }
77
78
    /* ------------------------------------------------------------------------------------------------
79
     |  Package Functions
80
     | ------------------------------------------------------------------------------------------------
81
     */
82
    /**
83
     * Publish all the package files.
84
     *
85
     * @param  bool  $load
86
     */
87
    protected function publishAll($load = true)
88
    {
89
        parent::publishAll($load);
90
91
        $this->publishSidebarItems();
92
    }
93
94
    /**
95
     * Publish the config file.
96
     */
97
    protected function publishConfig()
98
    {
99
        $this->publishes([
100
            $this->getConfigFile() => config_path("{$this->vendor}/{$this->package}.php"),
101
        ], 'config');
102
    }
103
104
    /**
105
     * Publish all the sidebar config files.
106
     */
107
    protected function publishSidebarItems()
108
    {
109
        $this->publishes([
110
            $this->getSidebarFolder() => config_path($this->vendor . DS . 'sidebar' . DS . $this->package)
111
        ], 'sidebar');
112
    }
113
114
    /**
115
     * Register all the sidebar config files.
116
     */
117
    protected function registerSidebarItems()
118
    {
119
        foreach ($this->filesystem()->glob($this->getSidebarFolder() . DS . '*.php') as $path) {
120
            $this->mergeConfigFrom($path, $this->getSidebarKey() . '.' . basename($path, '.php'));
121
        }
122
    }
123
}
124