| Current Path : /var/www/html/dynaweb-starter/plugin/dynaweb-audit/src/ |
| Current File : /var/www/html/dynaweb-starter/plugin/dynaweb-audit/src/DynawebAuditServiceProvider.php |
<?php
namespace Dynaweb\DynawebAudit;
use Filament\Support\Assets\AlpineComponent;
use Filament\Support\Assets\Asset;
use Filament\Support\Assets\Css;
use Filament\Support\Assets\Js;
use Filament\Support\Facades\FilamentAsset;
use Filament\Support\Facades\FilamentIcon;
use Illuminate\Filesystem\Filesystem;
use Livewire\Features\SupportTesting\Testable;
use Spatie\LaravelPackageTools\Commands\InstallCommand;
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;
use Dynaweb\DynawebAudit\Commands\DynawebAuditCommand;
use Dynaweb\DynawebAudit\Testing\TestsDynawebAudit;
class DynawebAuditServiceProvider extends PackageServiceProvider
{
public static string $name = 'dynaweb-audit';
public static string $viewNamespace = 'dynaweb-audit';
public function configurePackage(Package $package): void
{
/*
* This class is a Package Service Provider
*
* More info: https://github.com/spatie/laravel-package-tools
*/
$package->name(static::$name)
->hasCommands($this->getCommands())
->hasInstallCommand(function (InstallCommand $command) {
$command
->publishConfigFile()
->publishMigrations()
->askToRunMigrations();
});
$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
{
}
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/dynawebaudit/{$file->getFilename()}"),
], 'dynawebaudit-stubs');
}
}
// Testing
Testable::mixin(new TestsDynawebAudit());
}
protected function getAssetPackageName(): ?string
{
return 'dynaweb/dynaweb-audit';
}
/**
* @return array<Asset>
*/
protected function getAssets(): array
{
return [
// AlpineComponent::make('dynawebaudit', __DIR__ . '/../resources/dist/components/dynawebaudit.js'),
// Css::make('dynawebaudit-styles', __DIR__ . '/../resources/dist/dynawebaudit.css'),
// Js::make('dynawebaudit-scripts', __DIR__ . '/../resources/dist/dynawebaudit.js'),
];
}
/**
* @return array<class-string>
*/
protected function getCommands(): array
{
return [
DynawebAuditCommand::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_dynawebaudit_table',
];
}
}