|
1 | | -<?php |
2 | | - |
3 | | -namespace Glhd\Gretel\Support; |
4 | | - |
5 | | -use Glhd\Gretel\Macros; |
6 | | -use Glhd\Gretel\Registry; |
7 | | -use Illuminate\Contracts\Container\Container; |
8 | | -use Illuminate\Contracts\Foundation\Application; |
9 | | -use Illuminate\Support\Facades\Blade; |
10 | | -use Illuminate\Support\ServiceProvider; |
11 | | - |
12 | | -class GretelServiceProvider extends ServiceProvider |
13 | | -{ |
14 | | - protected string $base_dir; |
15 | | - |
16 | | - public function __construct($app) |
17 | | - { |
18 | | - parent::__construct($app); |
19 | | - |
20 | | - $this->base_dir = dirname(__DIR__, 2); |
21 | | - } |
22 | | - |
23 | | - public function boot() |
24 | | - { |
25 | | - require_once __DIR__.'/helpers.php'; |
26 | | - |
27 | | - $this->bootConfig(); |
28 | | - $this->bootViews(); |
29 | | - $this->bootBladeComponents(); |
30 | | - } |
31 | | - |
32 | | - public function register() |
33 | | - { |
34 | | - $this->mergeConfigFrom("{$this->base_dir}/config.php", 'gretel'); |
35 | | - |
36 | | - $this->app->singleton(Registry::class); |
37 | | - $this->app->booting(fn(Container $app) => Macros::register($app->make(Registry::class))); |
38 | | - } |
39 | | - |
40 | | - protected function bootViews() : self |
41 | | - { |
42 | | - $views_directory = "{$this->base_dir}/resources/views"; |
43 | | - |
44 | | - $this->loadViewsFrom($views_directory, 'gretel'); |
45 | | - |
46 | | - if (method_exists($this->app, 'resourcePath')) { |
47 | | - $this->publishes([ |
48 | | - $views_directory => $this->app->resourcePath('views/vendor/gretel'), |
49 | | - ], 'gretel-views'); |
50 | | - } |
51 | | - |
52 | | - return $this; |
53 | | - } |
54 | | - |
55 | | - protected function bootBladeComponents() : self |
56 | | - { |
57 | | - if (version_compare($this->app->version(), '8.0.0', '>=')) { |
58 | | - Blade::componentNamespace('Glhd\\Gretel\\Components', 'gretel'); |
59 | | - } |
60 | | - |
61 | | - return $this; |
62 | | - } |
63 | | - |
64 | | - protected function bootConfig() : self |
65 | | - { |
66 | | - if (method_exists($this->app, 'configPath')) { |
67 | | - $this->publishes([ |
68 | | - "{$this->base_dir}/config.php" => $this->app->configPath('gretel.php'), |
69 | | - ], 'gretel-config'); |
70 | | - } |
71 | | - |
72 | | - return $this; |
73 | | - } |
74 | | -} |
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Glhd\Gretel\Support; |
| 4 | + |
| 5 | +use Glhd\Gretel\Macros; |
| 6 | +use Glhd\Gretel\Registry; |
| 7 | +use Illuminate\Contracts\Container\Container; |
| 8 | +use Illuminate\Support\Facades\Blade; |
| 9 | +use Illuminate\Support\ServiceProvider; |
| 10 | + |
| 11 | +class GretelServiceProvider extends ServiceProvider |
| 12 | +{ |
| 13 | + protected string $base_dir; |
| 14 | + |
| 15 | + public function __construct($app) |
| 16 | + { |
| 17 | + parent::__construct($app); |
| 18 | + |
| 19 | + $this->base_dir = dirname(__DIR__, 2); |
| 20 | + } |
| 21 | + |
| 22 | + public function boot() |
| 23 | + { |
| 24 | + require_once __DIR__.'/helpers.php'; |
| 25 | + |
| 26 | + $this->bootConfig(); |
| 27 | + $this->bootViews(); |
| 28 | + $this->bootBladeComponents(); |
| 29 | + } |
| 30 | + |
| 31 | + public function register() |
| 32 | + { |
| 33 | + $this->mergeConfigFrom("{$this->base_dir}/config.php", 'gretel'); |
| 34 | + |
| 35 | + $this->app->singleton(Registry::class); |
| 36 | + $this->app->booting(fn(Container $app) => Macros::register($app->make(Registry::class))); |
| 37 | + } |
| 38 | + |
| 39 | + protected function bootViews(): self |
| 40 | + { |
| 41 | + $views_directory = "{$this->base_dir}/resources/views"; |
| 42 | + |
| 43 | + $this->loadViewsFrom($views_directory, 'gretel'); |
| 44 | + |
| 45 | + if (method_exists($this->app, 'resourcePath')) { |
| 46 | + $this->publishes([ |
| 47 | + $views_directory => $this->app->resourcePath('views/vendor/gretel'), |
| 48 | + ], 'gretel-views'); |
| 49 | + } |
| 50 | + |
| 51 | + return $this; |
| 52 | + } |
| 53 | + |
| 54 | + protected function bootBladeComponents(): self |
| 55 | + { |
| 56 | + if (version_compare($this->app->version(), '8.0.0', '>=')) { |
| 57 | + Blade::componentNamespace('Glhd\\Gretel\\Components', 'gretel'); |
| 58 | + } |
| 59 | + |
| 60 | + return $this; |
| 61 | + } |
| 62 | + |
| 63 | + protected function bootConfig(): self |
| 64 | + { |
| 65 | + if (method_exists($this->app, 'configPath')) { |
| 66 | + $this->publishes([ |
| 67 | + "{$this->base_dir}/config.php" => $this->app->configPath('gretel.php'), |
| 68 | + ], 'gretel-config'); |
| 69 | + } |
| 70 | + |
| 71 | + return $this; |
| 72 | + } |
| 73 | +} |
0 commit comments