Przeglądaj źródła

execute route after dispatch

develop
Robin Thoni 8 lat temu
rodzic
commit
bf7ea5d10a
1 zmienionych plików z 15 dodań i 1 usunięć
  1. 15
    1
      src/Utils/Controller/LuRoute.php

+ 15
- 1
src/Utils/Controller/LuRoute.php Wyświetl plik

@@ -2,6 +2,8 @@
2 2
 
3 3
 namespace Luticate\Utils\Controller;
4 4
 
5
+use FastRoute\Dispatcher;
6
+use Luticate\Utils\Business\LuBusinessException;
5 7
 use Luticate\Utils\Business\LuDocParser;
6 8
 use Luticate\Utils\Dbo\LuDboConstraintException;
7 9
 use Luticate\Utils\Dbo\LuDboDeserializeException;
@@ -124,7 +126,19 @@ class LuRoute {
124 126
 
125 127
     public function dispatch(string $httpMethod, string $url)
126 128
     {
127
-        $this->_dispatcher->dispatch($httpMethod, $url);
129
+        $routeInfo = $this->_dispatcher->dispatch($httpMethod, $url);
130
+
131
+        if ($routeInfo[0] == Dispatcher::NOT_FOUND) {
132
+            throw new LuBusinessException("Route not found", 404);
133
+        }
134
+        else if ($routeInfo[0] == Dispatcher::METHOD_NOT_ALLOWED) {
135
+            throw new LuBusinessException("Method not allowed", 405);
136
+        }
137
+        else {
138
+            $handler = $routeInfo[1];
139
+            $vars = $routeInfo[2];
140
+            $handler($vars);
141
+        }
128 142
     }
129 143
     
130 144
     private function getClassName(\ReflectionParameter $param) {

Ładowanie…
Anuluj
Zapisz