From 6962c2b790b5428699fe5897de840d41090fcd37 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Sat, 31 Mar 2018 05:19:49 +0200 Subject: Legacy URL Support --- src/Routing/LegacyUrlGenerator.php | 25 +++++++++++++++++++++++++ src/Routing/RoutingServiceProvider.php | 9 ++++++++- src/Routing/UrlGenerator.php | 2 +- src/Routing/UrlGeneratorInterface.php | 13 +++++++++++++ src/helpers.php | 4 ++-- 5 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 src/Routing/LegacyUrlGenerator.php create mode 100644 src/Routing/UrlGeneratorInterface.php (limited to 'src') diff --git a/src/Routing/LegacyUrlGenerator.php b/src/Routing/LegacyUrlGenerator.php new file mode 100644 index 00000000..f17bdf88 --- /dev/null +++ b/src/Routing/LegacyUrlGenerator.php @@ -0,0 +1,25 @@ + $page], $parameters); + } + + $uri = parent::to('index.php', $parameters); + $uri = preg_replace('~(/index\.php)+~', '/index.php', $uri); + + return $uri; + } +} diff --git a/src/Routing/RoutingServiceProvider.php b/src/Routing/RoutingServiceProvider.php index b7db1383..021840c3 100644 --- a/src/Routing/RoutingServiceProvider.php +++ b/src/Routing/RoutingServiceProvider.php @@ -8,7 +8,14 @@ class RoutingServiceProvider extends ServiceProvider { public function register() { - $urlGenerator = $this->app->make(UrlGenerator::class); + $config = $this->app->get('config'); + $class = UrlGenerator::class; + if (!$config->get('rewrite_urls', true)) { + $class = LegacyUrlGenerator::class; + } + + $urlGenerator = $this->app->make($class); $this->app->instance('routing.urlGenerator', $urlGenerator); + $this->app->bind(UrlGeneratorInterface::class, 'routing.urlGenerator'); } } diff --git a/src/Routing/UrlGenerator.php b/src/Routing/UrlGenerator.php index 6df52425..8dd52271 100644 --- a/src/Routing/UrlGenerator.php +++ b/src/Routing/UrlGenerator.php @@ -2,7 +2,7 @@ namespace Engelsystem\Routing; -class UrlGenerator +class UrlGenerator implements UrlGeneratorInterface { /** * @param string $path diff --git a/src/Routing/UrlGeneratorInterface.php b/src/Routing/UrlGeneratorInterface.php new file mode 100644 index 00000000..d97da30d --- /dev/null +++ b/src/Routing/UrlGeneratorInterface.php @@ -0,0 +1,13 @@ +