Files
lucent-laravel/src/LucentServiceProvider.php
T

85 lines
2.5 KiB
PHP
Raw Normal View History

2023-10-02 23:10:49 +03:00
<?php
namespace Lucent;
use Illuminate\Routing\Router;
use Illuminate\Support\Facades\View;
2023-10-02 23:47:01 +03:00
use Illuminate\Support\ServiceProvider;
2023-10-04 13:32:30 +03:00
use Intervention\Image\ImageManager;
2023-10-02 23:10:49 +03:00
use Lucent\Channel\ChannelService;
2023-10-06 13:07:09 +03:00
use Lucent\Commands\CompileSchemas;
2023-10-02 23:10:49 +03:00
use Lucent\Commands\RebuildThumbnails;
2023-10-04 13:32:30 +03:00
use Lucent\File\FileService;
2023-10-02 23:10:49 +03:00
use Lucent\File\ImageService;
2023-10-15 23:40:34 +03:00
use Lucent\Query\DatabaseGraph\DatabaseGraph;
use Lucent\Query\DatabaseGraph\PgsqlDatabaseGraph;
use Lucent\Query\DatabaseGraph\SqliteDatabaseGraph;
2023-10-02 23:10:49 +03:00
2023-10-02 23:47:01 +03:00
class LucentServiceProvider extends ServiceProvider
2023-10-02 23:10:49 +03:00
{
/**
* Register any application services.
*/
public function register(): void
{
$this->app->singleton(ChannelService::class, function () {
return ChannelService::fromConfig();
});
2023-10-04 13:32:30 +03:00
$this->app->bind(ImageManager::class, function () {
return new ImageManager(['driver' => 'imagick']);
});
2023-10-15 23:40:34 +03:00
$this->app->bind(DatabaseGraph::class, function () {
2023-10-15 23:46:21 +03:00
return match (config("lucent.database")) {
2023-10-15 23:40:34 +03:00
"sqlite" => new SqliteDatabaseGraph(),
"pgsql" => new PgsqlDatabaseGraph(),
};
});
2023-10-04 13:32:30 +03:00
2023-10-02 23:10:49 +03:00
}
/**
* Bootstrap any package services.
*/
public function boot(Router $router): void
{
2023-10-06 13:07:09 +03:00
$manifestPath = public_path('vendor/lucent/dist/manifest.json');
2023-10-15 23:40:34 +03:00
$manifest = null;
if (file_exists($manifestPath)) {
$manifest = json_decode(file_get_contents(public_path('vendor/lucent/dist/manifest.json')), true);
2023-10-06 13:07:09 +03:00
}
2023-10-05 13:16:23 +03:00
2023-10-02 23:10:49 +03:00
$router->aliasMiddleware('lucent.auth', \Lucent\Http\Middleware\AuthMiddleware::class);
$router->aliasMiddleware('lucent.guest', \Lucent\Http\Middleware\GuestMiddleware::class);
$this->loadViewsFrom(__DIR__ . '/Views', 'lucent');
$this->loadRoutesFrom(__DIR__ . '/Http/web.php');
$this->loadRoutesFrom(__DIR__ . '/Http/api.php');
2023-10-04 13:32:30 +03:00
$this->loadMigrationsFrom(__DIR__ . '/Database/migrations');
2023-10-02 23:10:49 +03:00
if ($this->app->runningInConsole()) {
$this->commands([
2023-10-06 13:07:09 +03:00
CompileSchemas::class,
2023-10-02 23:10:49 +03:00
RebuildThumbnails::class,
]);
}
2023-10-05 13:16:23 +03:00
View::share('manifest', $manifest);
2023-10-02 23:10:49 +03:00
View::share('image', app()->make(ImageService::class));
2023-10-04 13:32:30 +03:00
View::share('file', app()->make(FileService::class));
2023-10-02 23:10:49 +03:00
$this->publishes([
__DIR__ . '/Config/main.php' => config_path('lucent.php'),
]);
2023-10-05 13:16:23 +03:00
$this->publishes([
2023-10-15 23:40:34 +03:00
__DIR__ . '/../front/dist' => public_path('vendor/lucent/dist'),
2023-10-05 13:16:23 +03:00
], 'public');
2023-10-02 23:10:49 +03:00
}
}