| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | namespace LaravelUi5\OData; |
| 6: | |
| 7: | use Illuminate\Support\Facades\Route; |
| 8: | use Illuminate\Support\ServiceProvider; |
| 9: | use LaravelUi5\OData\Console\CacheCommand; |
| 10: | use LaravelUi5\OData\Console\ClearCommand; |
| 11: | use LaravelUi5\OData\Service\Contracts\ODataServiceRegistryInterface; |
| 12: | |
| 13: | class ODataServiceProvider extends ServiceProvider |
| 14: | { |
| 15: | public function register(): void |
| 16: | { |
| 17: | $this->mergeConfigFrom(__DIR__ . '/../config.php', 'odata'); |
| 18: | |
| 19: | $this->app->singleton(ODataServiceRegistryInterface::class, fn ($app) => $app->make( |
| 20: | config('odata.service_registry', ODataServiceRegistry::class) |
| 21: | ), |
| 22: | ); |
| 23: | } |
| 24: | |
| 25: | public function boot(): void |
| 26: | { |
| 27: | if ($this->app->runningInConsole()) { |
| 28: | $this->publishes([__DIR__ . '/../config.php' => config_path('odata.php')], 'config'); |
| 29: | $this->commands([ |
| 30: | CacheCommand::class, |
| 31: | ClearCommand::class, |
| 32: | ]); |
| 33: | } |
| 34: | |
| 35: | if (config('odata.register_routes', true)) { |
| 36: | Route::prefix(config('odata.prefix', 'odata')) |
| 37: | ->middleware(config('odata.middleware', [])) |
| 38: | ->group(__DIR__ . '/../routes/odata.php'); |
| 39: | } |
| 40: | } |
| 41: | } |
| 42: | |