Browse Source

execute route after dispatch

develop
Robin Thoni 8 years ago
parent
commit
bf7ea5d10a
1 changed files with 15 additions and 1 deletions
  1. 15
    1
      src/Utils/Controller/LuRoute.php

+ 15
- 1
src/Utils/Controller/LuRoute.php View File

2
 
2
 
3
 namespace Luticate\Utils\Controller;
3
 namespace Luticate\Utils\Controller;
4
 
4
 
5
+use FastRoute\Dispatcher;
6
+use Luticate\Utils\Business\LuBusinessException;
5
 use Luticate\Utils\Business\LuDocParser;
7
 use Luticate\Utils\Business\LuDocParser;
6
 use Luticate\Utils\Dbo\LuDboConstraintException;
8
 use Luticate\Utils\Dbo\LuDboConstraintException;
7
 use Luticate\Utils\Dbo\LuDboDeserializeException;
9
 use Luticate\Utils\Dbo\LuDboDeserializeException;
124
 
126
 
125
     public function dispatch(string $httpMethod, string $url)
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
     private function getClassName(\ReflectionParameter $param) {
144
     private function getClassName(\ReflectionParameter $param) {

Loading…
Cancel
Save