Files
Helpddesk/Modules/Documentation/Providers/DocumentationServiceProvider.php
T

75 lines
1.9 KiB
PHP
Executable File

<?php
declare(strict_types=1);
namespace Modules\Documentation\Providers;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\ServiceProvider;
use Modules\Documentation\Console\ImportDocumentationCommand;
final class DocumentationServiceProvider extends ServiceProvider
{
/**
* Register module services.
*/
public function register(): void
{
$this->app->register(RouteServiceProvider::class);
$this->mergeConfigFrom(
module_path('Documentation', 'Config/config.php'),
'documentation',
);
}
/**
* Bootstrap module services.
*/
public function boot(): void
{
$this->registerViews();
$this->registerCommands();
$this->loadMigrationsFrom(module_path('Documentation', 'Database/Migrations'));
}
/**
* Register module console commands.
*/
private function registerCommands(): void
{
if (! $this->app->runningInConsole()) {
return;
}
$this->commands([
ImportDocumentationCommand::class,
]);
}
/**
* Register module views and anonymous components.
*/
private function registerViews(): void
{
$sourcePath = module_path('Documentation', 'Resources/views');
$overridePath = resource_path('views/modules/documentation');
$this->publishes([
$sourcePath => $overridePath,
], ['views', 'documentation-module-views']);
$paths = [$sourcePath];
foreach (Config::get('view.paths', []) as $path) {
if (is_dir($path.'/modules/documentation')) {
array_unshift($paths, $path.'/modules/documentation');
}
}
$this->loadViewsFrom($paths, 'documentation');
Blade::anonymousComponentPath($sourcePath.'/components', 'documentation');
}
}