From 6e12c6c146d37662c376e7c98423e738a6d7f09b Mon Sep 17 00:00:00 2001 From: Bob Wezelman Date: Thu, 1 Dec 2022 14:42:40 +0100 Subject: [PATCH] Refactored routing (#15) --- .../Controllers/StatamicRewriteController.php | 30 ------------------- .../StatamicDataComposer.php | 3 +- src/RapidezStatamicServiceProvider.php | 21 ++++++------- 3 files changed, 13 insertions(+), 41 deletions(-) delete mode 100644 src/Http/Controllers/StatamicRewriteController.php rename src/Http/{ => ViewComposers}/StatamicDataComposer.php (94%) diff --git a/src/Http/Controllers/StatamicRewriteController.php b/src/Http/Controllers/StatamicRewriteController.php deleted file mode 100644 index c9a7465..0000000 --- a/src/Http/Controllers/StatamicRewriteController.php +++ /dev/null @@ -1,30 +0,0 @@ -get('rapidez.store_code'); - - $entry = Entry::query() - ->where('collection', 'pages') - ->where('locale', $storeCode) - ->where('slug', $request->path() == '/' ? 'home' : $request->path()) - ->first(); - - if (!$entry) { - throw new NotFoundHttpException(); - } - - $template = View::exists($entry->template()) ? $entry->template() : $entry->blueprint->handle(); - - echo view($template, ['entry' => $entry]); - } -} diff --git a/src/Http/StatamicDataComposer.php b/src/Http/ViewComposers/StatamicDataComposer.php similarity index 94% rename from src/Http/StatamicDataComposer.php rename to src/Http/ViewComposers/StatamicDataComposer.php index 31b92f2..f4eaa66 100644 --- a/src/Http/StatamicDataComposer.php +++ b/src/Http/ViewComposers/StatamicDataComposer.php @@ -1,6 +1,7 @@ bootConfig() ->bootRepositories() ->bootPublishables() - ->bootFilters() ->bootComposers() - ->bootListeners(); + ->bootListeners() + ->bootRoutes(); } - public function bootConfig() : self + public function bootRoutes() : self { - $this->mergeConfigFrom(__DIR__.'/../config/statamic.php', 'statamic'); + if (!$this->app->routesAreCached()) { + Rapidez::addFallbackRoute([FrontendController::class, 'index'], 100); + } return $this; } - public function bootFilters() : self + public function bootConfig() : self { - Eventy::addFilter('routes', fn ($routes) => array_merge($routes ?: [], [__DIR__.'/../routes/fallback.php'])); + $this->mergeConfigFrom(__DIR__.'/../config/statamic.php', 'statamic'); return $this; } - public function bootCommands() : self { $this->commands([