Files
lucent-laravel/src/LucentServiceProvider.php
T

133 lines
4.0 KiB
PHP
Raw Normal View History

2023-10-02 23:10:49 +03:00
<?php
namespace Lucent;
use Illuminate\Routing\Router;
2024-08-14 22:04:34 +03:00
use Illuminate\Support\Facades\Blade;
2023-10-02 23:10:49 +03:00
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;
2026-04-20 21:07:35 +03:00
use Lucent\Account\AuthService;
use Lucent\Account\AuthServiceLunar;
2026-05-06 23:16:09 +03:00
use Lucent\Account\AuthServiceLucent;
2026-04-20 21:07:35 +03:00
use Lucent\Account\UserRepo;
2026-05-06 19:36:53 +03:00
use Lucent\Account\UserRepoLucent;
2026-04-20 21:07:35 +03:00
use Lucent\Account\UserRepoLunar;
2023-10-02 23:10:49 +03:00
use Lucent\Channel\ChannelService;
2023-10-06 13:07:09 +03:00
use Lucent\Commands\CompileSchemas;
2024-09-07 00:03:11 +03:00
use Lucent\Commands\GenerateCollectionSchema;
2023-10-16 15:38:25 +03:00
use Lucent\Commands\LiveLink;
2023-10-02 23:10:49 +03:00
use Lucent\Commands\RebuildThumbnails;
2023-11-29 17:10:15 +02:00
use Lucent\Commands\RemoveOrphanEdges;
2024-09-06 23:30:12 +03:00
use Lucent\Commands\SetupDatabase;
2026-05-07 17:42:46 +03:00
use Lucent\Commands\Export;
use Lucent\Commands\Import;
2026-05-07 21:38:07 +03:00
use Lucent\Commands\Setup;
2026-05-06 19:36:53 +03:00
use Lucent\Data\ChannelAuth;
2023-10-04 13:32:30 +03:00
use Lucent\File\FileService;
2023-10-15 23:40:34 +03:00
use Lucent\Query\DatabaseGraph\DatabaseGraph;
use Lucent\Query\DatabaseGraph\PgsqlDatabaseGraph;
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 () {
2026-04-20 21:07:35 +03:00
return new ImageManager(["driver" => "imagick"]);
2023-10-04 13:32:30 +03:00
});
2023-10-15 23:40:34 +03:00
$this->app->bind(DatabaseGraph::class, function () {
2026-04-20 21:07:35 +03:00
return new PgsqlDatabaseGraph();
2023-10-15 23:40:34 +03:00
});
2026-05-06 19:36:53 +03:00
$this->app->bind(UserRepo::class, function ($app) {
return match ($app->make(ChannelService::class)->channel->auth) {
ChannelAuth::LUNAR => new UserRepoLunar(),
ChannelAuth::LUCENT => new UserRepoLucent(),
};
2026-04-20 21:07:35 +03:00
});
2024-08-19 17:48:10 +03:00
2026-04-20 21:07:35 +03:00
$this->app->bind(AuthService::class, function ($app) {
2026-05-06 23:16:09 +03:00
return match ($app->make(ChannelService::class)->channel->auth) {
ChannelAuth::LUNAR => $app->make(AuthServiceLunar::class),
ChannelAuth::LUCENT => $app->make(AuthServiceLucent::class),
};
2026-04-20 21:07:35 +03:00
});
2023-10-02 23:10:49 +03:00
}
/**
* Bootstrap any package services.
*/
public function boot(Router $router): void
{
2026-04-20 21:07:35 +03:00
$manifestPath = public_path("vendor/lucent/dist/manifest.json");
2023-10-15 23:40:34 +03:00
$manifest = null;
if (file_exists($manifestPath)) {
2026-04-20 21:07:35 +03:00
$manifest = json_decode(
file_get_contents(
public_path("vendor/lucent/dist/manifest.json"),
),
true,
);
2023-10-06 13:07:09 +03:00
}
2026-04-20 21:07:35 +03:00
$router->aliasMiddleware(
"lucent.auth",
\Lucent\Http\Middleware\AuthMiddleware::class,
);
$router->aliasMiddleware(
"lucent.guest",
\Lucent\Http\Middleware\GuestMiddleware::class,
);
2023-10-05 13:16:23 +03:00
2026-04-20 21:07:35 +03:00
$this->loadViewsFrom(__DIR__ . "/../front/views", "lucent");
$this->loadRoutesFrom(__DIR__ . "/Http/web.php");
$this->loadRoutesFrom(__DIR__ . "/Http/api.php");
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-16 15:38:25 +03:00
LiveLink::class,
2023-11-29 17:10:15 +02:00
RemoveOrphanEdges::class,
2024-09-06 23:30:12 +03:00
SetupDatabase::class,
2024-09-07 00:03:11 +03:00
GenerateCollectionSchema::class,
2026-05-07 17:42:46 +03:00
Export::class,
Import::class,
2026-05-07 21:38:07 +03:00
Setup::class,
2023-10-02 23:10:49 +03:00
]);
}
2026-04-20 21:07:35 +03:00
View::share("manifest", $manifest);
View::share("file", app()->make(FileService::class));
Blade::anonymousComponentPath(
__DIR__ . "../front/views/components",
"lucent",
);
$this->publishes(
[
__DIR__ . "/Config/main.php" => config_path("lucent.php"),
],
"lucent-config",
);
$this->publishes(
[
__DIR__ . "/../front/dist" => public_path("vendor/lucent/dist"),
__DIR__ . "/../front/public" => public_path(
"vendor/lucent/public",
),
],
"lucent",
);
2023-10-02 23:10:49 +03:00
}
}