From 3e961637400a083ef3c46f5b908f39bbccbaf87a Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Wed, 30 Apr 2025 23:18:55 +0300 Subject: [PATCH] A little code cleanup --- src/Routing/Route.php | 14 ++++++++------ src/ServiceProvider.php | 25 ++----------------------- 2 files changed, 10 insertions(+), 29 deletions(-) diff --git a/src/Routing/Route.php b/src/Routing/Route.php index 0a3e17e..5c7b490 100644 --- a/src/Routing/Route.php +++ b/src/Routing/Route.php @@ -12,12 +12,14 @@ class Route extends BaseRoute { public function getName(): ?string { - return $this->isProtectedRouteName() - ? $this->getProtectedRouteName() - : app()->call($this->getRouteNamesExtender(), [ - 'name' => Name::get($this->methods(), $this->uri()), - 'route' => $this, - ]); + if ($this->isProtectedRouteName()) { + return $this->getProtectedRouteName(); + } + + return app()->call($this->getRouteNamesExtender(), [ + 'name' => Name::get($this->methods(), $this->uri()), + 'route' => $this, + ]); } protected function isProtectedRouteName(): bool diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index c48f41f..574ccb7 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -4,8 +4,6 @@ namespace DragonCode\LaravelRouteNames; -use DragonCode\LaravelRouteNames\Routing\Router; -use Illuminate\Routing\Router as BaseRouter; use Illuminate\Support\ServiceProvider as BaseServiceProvider; class ServiceProvider extends BaseServiceProvider @@ -18,39 +16,20 @@ public function boot(): void public function register(): void { $this->registerConfig(); - $this->extendRouter(); } protected function publishConfig(): void { $this->publishes([ - $this->getPath() => config_path('route.php'), + __DIR__ . '/../config/route.php' => config_path('route.php'), ], 'config'); } protected function registerConfig(): void { $this->mergeConfigFrom( - $this->getPath(), + __DIR__ . '/../config/route.php', 'route' ); } - - protected function getPath(): string - { - return __DIR__ . '/../config/route.php'; - } - - protected function extendRouter(): void - { - $this->app->booting(function (): void { - $this->app->extend( - 'router', - static fn ( - BaseRouter $router, - $app - ): Router => ! $router instanceof Router ? new Router($app['events'], $app) : $router - ); - }); - } }