generated from filamentphp/plugin-skeleton
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPageBuilderPluginServiceProvider.php
More file actions
149 lines (126 loc) · 4.02 KB
/
PageBuilderPluginServiceProvider.php
File metadata and controls
149 lines (126 loc) · 4.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
namespace Redberry\PageBuilderPlugin;
use Filament\Support\Assets\Asset;
use Filament\Support\Assets\Css;
use Filament\Support\Facades\FilamentAsset;
use Filament\Support\Facades\FilamentIcon;
use Illuminate\Filesystem\Filesystem;
use Livewire\Features\SupportTesting\Testable;
use Redberry\PageBuilderPlugin\Commands\CreatePageBuilderPluginBlockCategoryCommand;
use Redberry\PageBuilderPlugin\Commands\CreatePageBuilderPluginBlockCommand;
use Redberry\PageBuilderPlugin\Testing\TestsPageBuilderPlugin;
use Spatie\LaravelPackageTools\Commands\InstallCommand;
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;
class PageBuilderPluginServiceProvider extends PackageServiceProvider
{
public static string $name = 'page-builder-plugin';
public static string $viewNamespace = 'page-builder-plugin';
public function configurePackage(Package $package): void
{
$package->name(static::$name)
->hasCommands($this->getCommands())
->hasInstallCommand(function (InstallCommand $command) {
$command
->publishConfigFile()
->publishMigrations()
->askToRunMigrations()
->askToStarRepoOnGitHub('Redberry/filament-page-builder-plugin');
});
$configFileName = $package->shortName();
if (file_exists($package->basePath("/../config/{$configFileName}.php"))) {
$package->hasConfigFile();
}
if (file_exists($package->basePath('/../database/migrations'))) {
$package->hasMigrations($this->getMigrations());
}
if (file_exists($package->basePath('/../resources/lang'))) {
$package->hasTranslations();
}
if (file_exists($package->basePath('/../resources/views'))) {
$package->hasViews(static::$viewNamespace);
}
}
public function packageRegistered(): void
{
$this->app->singleton(GlobalBlocksPlugin::class);
}
public function packageBooted(): void
{
// Asset Registration
FilamentAsset::register(
$this->getAssets(),
$this->getAssetPackageName()
);
FilamentAsset::registerScriptData(
$this->getScriptData(),
$this->getAssetPackageName()
);
// Icon Registration
FilamentIcon::register($this->getIcons());
// Handle Stubs
if (app()->runningInConsole()) {
foreach (app(Filesystem::class)->files(__DIR__ . '/../stubs/') as $file) {
$this->publishes([
$file->getRealPath() => base_path("stubs/page-builder-plugin/{$file->getFilename()}"),
], 'page-builder-plugin-stubs');
}
}
// Testing
Testable::mixin(new TestsPageBuilderPlugin);
}
protected function getAssetPackageName(): ?string
{
return 'redberryproducts/page-builder-plugin';
}
/**
* @return array<Asset>
*/
protected function getAssets(): array
{
return [
Css::make('page-builder-plugin-styles', __DIR__ . '/../resources/dist/page-builder-plugin.css'),
];
}
/**
* @return array<class-string>
*/
protected function getCommands(): array
{
return [
CreatePageBuilderPluginBlockCommand::class,
CreatePageBuilderPluginBlockCategoryCommand::class,
];
}
/**
* @return array<string>
*/
protected function getIcons(): array
{
return [];
}
/**
* @return array<string>
*/
protected function getRoutes(): array
{
return [];
}
/**
* @return array<string, mixed>
*/
protected function getScriptData(): array
{
return [];
}
/**
* @return array<string>
*/
protected function getMigrations(): array
{
return [
'create_page_builder_blocks_table',
'create_global_block_configs_table',
];
}
}