|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Itstructure\MultiMenu; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Blade; |
|
6
|
|
|
use Illuminate\Support\ServiceProvider; |
|
7
|
|
|
use Itstructure\MultiMenu\Commands\PublishCommand; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class MultiMenuServiceProvider |
|
11
|
|
|
* |
|
12
|
|
|
* @package Itstructure\MultiMenu |
|
13
|
|
|
* |
|
14
|
|
|
* @author Andrey Girnik <[email protected]> |
|
15
|
|
|
*/ |
|
16
|
|
|
class MultiMenuServiceProvider extends ServiceProvider |
|
17
|
|
|
{ |
|
18
|
|
|
public function register() |
|
19
|
|
|
{ |
|
20
|
|
|
$this->registerCommands(); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function boot() |
|
24
|
|
|
{ |
|
25
|
|
|
$this->loadViews(); |
|
26
|
|
|
|
|
27
|
|
|
$this->publishViews(); |
|
28
|
|
|
|
|
29
|
|
|
$this->publishConfig(); |
|
30
|
|
|
|
|
31
|
|
|
require_once __DIR__ . '/functions.php'; |
|
32
|
|
|
|
|
33
|
|
|
Blade::directive('multiMenu', function ($options) { |
|
34
|
|
|
return "<?php echo multi_menu($options); ?>"; |
|
35
|
|
|
}); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @return void |
|
40
|
|
|
*/ |
|
41
|
|
|
private function loadViews(): void |
|
42
|
|
|
{ |
|
43
|
|
|
$this->loadViewsFrom($this->packagePath('resources/views'), 'multimenu'); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @return void |
|
48
|
|
|
*/ |
|
49
|
|
|
private function publishViews(): void |
|
50
|
|
|
{ |
|
51
|
|
|
$this->publishes([ |
|
52
|
|
|
$this->packagePath('resources/views') => resource_path('views/vendor/multimenu'), |
|
53
|
|
|
], 'views'); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @return void |
|
58
|
|
|
*/ |
|
59
|
|
|
private function publishConfig(): void |
|
60
|
|
|
{ |
|
61
|
|
|
$configPath = $this->packagePath('config/multimenu.php'); |
|
62
|
|
|
|
|
63
|
|
|
$this->publishes([ |
|
64
|
|
|
$configPath => config_path('multimenu.php'), |
|
65
|
|
|
], 'config'); |
|
66
|
|
|
|
|
67
|
|
|
$this->mergeConfigFrom($configPath, 'multimenu'); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @return void |
|
72
|
|
|
*/ |
|
73
|
|
|
private function registerCommands(): void |
|
74
|
|
|
{ |
|
75
|
|
|
$this->commands(PublishCommand::class); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @param $path |
|
80
|
|
|
* @return string |
|
81
|
|
|
*/ |
|
82
|
|
|
private function packagePath($path): string |
|
83
|
|
|
{ |
|
84
|
|
|
return __DIR__ . "/../" . $path; |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|