summaryrefslogtreecommitdiff
path: root/src/Middleware/RouteDispatcherServiceProvider.php
diff options
context:
space:
mode:
authorIgor Scheller <igor.scheller@igorshp.de>2018-08-25 21:16:20 +0200
committerIgor Scheller <igor.scheller@igorshp.de>2018-08-25 21:48:39 +0200
commita1bc763a16ee8be109de5c9053fbc5eded53824e (patch)
tree7253db0c8ea918e82253bef3926bcba461a7105d /src/Middleware/RouteDispatcherServiceProvider.php
parent73c9d923e7cc77847cfcbff4b90ad4815699a4fa (diff)
Added nikic/fast-route as routing dispatcher
Diffstat (limited to 'src/Middleware/RouteDispatcherServiceProvider.php')
-rw-r--r--src/Middleware/RouteDispatcherServiceProvider.php41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/Middleware/RouteDispatcherServiceProvider.php b/src/Middleware/RouteDispatcherServiceProvider.php
new file mode 100644
index 00000000..3b4fa183
--- /dev/null
+++ b/src/Middleware/RouteDispatcherServiceProvider.php
@@ -0,0 +1,41 @@
+<?php
+
+namespace Engelsystem\Middleware;
+
+use Engelsystem\Container\ServiceProvider;
+use FastRoute\Dispatcher as FastRouteDispatcher;
+use FastRoute\RouteCollector;
+use Psr\Http\Server\MiddlewareInterface;
+
+class RouteDispatcherServiceProvider extends ServiceProvider
+{
+ public function register()
+ {
+ $this->app->alias(RouteDispatcher::class, 'route.dispatcher');
+
+ $this->app
+ ->when(RouteDispatcher::class)
+ ->needs(FastRouteDispatcher::class)
+ ->give(function () {
+ return $this->generateRouting();
+ });
+
+ $this->app
+ ->when(RouteDispatcher::class)
+ ->needs(MiddlewareInterface::class)
+ ->give(LegacyMiddleware::class);
+ }
+
+ /**
+ * Includes the routes.php file
+ *
+ * @return FastRouteDispatcher
+ * @codeCoverageIgnore
+ */
+ function generateRouting()
+ {
+ return \FastRoute\simpleDispatcher(function (RouteCollector $route) {
+ require config_path('routes.php');
+ });
+ }
+}