Files
lucent-laravel/src/LucentServiceProvider.php
T
lexx 842bd71a18 Json Schema transformer is done
Form builder stuck on infinite recurrsion
2024-03-14 22:12:26 +02:00

91 lines
2.8 KiB
PHP

<?php
namespace Lucent;
use Illuminate\Routing\Router;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;
use Intervention\Image\ImageManager;
use Lucent\Channel\ChannelService;
use Lucent\Commands\CompileSchemas;
use Lucent\Commands\LiveLink;
use Lucent\Commands\RebuildThumbnails;
use Lucent\Commands\RemoveOrphanEdges;
use Lucent\File\FileService;
use Lucent\File\ImageService;
use Lucent\JsonSchema\Command\GenerateJsonSchema;
use Lucent\Query\DatabaseGraph\DatabaseGraph;
use Lucent\Query\DatabaseGraph\PgsqlDatabaseGraph;
use Lucent\Query\DatabaseGraph\SqliteDatabaseGraph;
class LucentServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*/
public function register(): void
{
$this->app->singleton(ChannelService::class, function () {
return ChannelService::fromConfig();
});
$this->app->bind(ImageManager::class, function () {
return new ImageManager(['driver' => 'imagick']);
});
$this->app->bind(DatabaseGraph::class, function () {
return match (config("lucent.database")) {
"sqlite" => new SqliteDatabaseGraph(),
"pgsql" => new PgsqlDatabaseGraph(),
};
});
}
/**
* Bootstrap any package services.
*/
public function boot(Router $router): void
{
$manifestPath = public_path('vendor/lucent/dist/manifest.json');
$manifest = null;
if (file_exists($manifestPath)) {
$manifest = json_decode(file_get_contents(public_path('vendor/lucent/dist/manifest.json')), true);
}
$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');
$this->loadMigrationsFrom(__DIR__ . '/Database/migrations');
if ($this->app->runningInConsole()) {
$this->commands([
CompileSchemas::class,
RebuildThumbnails::class,
LiveLink::class,
RemoveOrphanEdges::class,
GenerateJsonSchema::class,
]);
}
View::share('manifest', $manifest);
View::share('image', app()->make(ImageService::class));
View::share('file', app()->make(FileService::class));
$this->publishes([
__DIR__ . '/Config/main.php' => config_path('lucent.php'),
]);
$this->publishes([
__DIR__ . '/../front/dist' => public_path('vendor/lucent/dist'),
], 'lucent');
}
}