1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace NovaFlexibleContent; |
4
|
|
|
|
5
|
|
|
use Laravel\Nova\Events\ServingNova; |
6
|
|
|
use Laravel\Nova\Nova; |
7
|
|
|
use NovaFlexibleContent\Http\FlexibleAttribute; |
8
|
|
|
use NovaFlexibleContent\Http\Middleware\InterceptFlexibleAttributes; |
9
|
|
|
|
10
|
|
|
class ServiceProvider extends \Illuminate\Support\ServiceProvider |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Bootstrap any application services. |
14
|
|
|
* |
15
|
|
|
* @return void |
16
|
|
|
*/ |
17
|
29 |
|
public function boot(): void |
18
|
|
|
{ |
19
|
29 |
|
$this->addMiddleware(); |
20
|
|
|
|
21
|
29 |
|
Nova::serving(function (ServingNova $event) { |
|
|
|
|
22
|
|
|
Nova::script('flexible-content-field', __DIR__ . '/../dist/js/field.js'); |
23
|
|
|
Nova::style('flexible-content-field', __DIR__ . '/../dist/css/field.css'); |
24
|
|
|
|
25
|
|
|
Nova::provideToScript([ |
26
|
|
|
'flexible-content-field.flexible-attribute-key-name' => FlexibleAttribute::REGISTER_FLEXIBLE_FIELD_NAME, |
27
|
|
|
'flexible-content-field.file-indicator-prefix' => FlexibleAttribute::FILE_INDICATOR, |
28
|
|
|
'flexible-content-field.group-separator' => FlexibleAttribute::GROUP_SEPARATOR, |
29
|
|
|
]); |
30
|
29 |
|
}); |
31
|
|
|
|
32
|
29 |
|
if ($this->app->runningInConsole()) { |
33
|
29 |
|
$this->publishes([ |
34
|
29 |
|
__DIR__ . '/../config/nova-flexible-content.php' => config_path('nova-flexible-content.php'), |
35
|
29 |
|
], 'config'); |
36
|
|
|
|
37
|
29 |
|
$this->commands([ |
38
|
29 |
|
// |
39
|
29 |
|
]); |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Register any application services. |
45
|
|
|
* |
46
|
|
|
* @return void |
47
|
|
|
*/ |
48
|
29 |
|
public function register(): void |
49
|
|
|
{ |
50
|
29 |
|
$this->mergeConfigFrom(__DIR__ . '/../config/nova-flexible-content.php', 'nova-flexible-content'); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Adds required middleware for Nova requests. |
55
|
|
|
* |
56
|
|
|
* @return void |
57
|
|
|
*/ |
58
|
29 |
|
public function addMiddleware(): void |
59
|
|
|
{ |
60
|
29 |
|
$router = $this->app['router']; |
61
|
|
|
|
62
|
29 |
|
if ($router->hasMiddlewareGroup('nova')) { |
63
|
29 |
|
$router->pushMiddlewareToGroup('nova', InterceptFlexibleAttributes::class); |
64
|
|
|
|
65
|
29 |
|
return; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
if (!$this->app->configurationIsCached()) { |
69
|
|
|
config()->set('nova.middleware', array_merge( |
70
|
|
|
config('nova.middleware', []), |
71
|
|
|
[InterceptFlexibleAttributes::class] |
72
|
|
|
)); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.