Browse Source

run constraints checks on routing

tags/0.1.11
Robin Thoni 8 years ago
parent
commit
fc49ec017d
1 changed files with 18 additions and 0 deletions
  1. 18
    0
      src/Utils/LuRoute.php

+ 18
- 0
src/Utils/LuRoute.php View File

2
 
2
 
3
 namespace Luticate\Utils;
3
 namespace Luticate\Utils;
4
 
4
 
5
+use Luticate\Utils\Business\LuDocParser;
6
+use Luticate\Utils\Dbo\LuDboConstraintException;
5
 use Luticate\Utils\Dbo\LuDboDeserializeException;
7
 use Luticate\Utils\Dbo\LuDboDeserializeException;
6
 
8
 
7
 class LuRoute {
9
 class LuRoute {
118
         {
120
         {
119
             $reflect = new \ReflectionMethod($controller, $method);
121
             $reflect = new \ReflectionMethod($controller, $method);
120
             $params = $reflect->getParameters();
122
             $params = $reflect->getParameters();
123
+            $doc = new LuDocParser($reflect->getDocComment());
124
+            $doc->parse();
121
 
125
 
122
             $args = array();
126
             $args = array();
123
             foreach ($params as $param) {
127
             foreach ($params as $param) {
134
                 else {
138
                 else {
135
                     $args[$param->getName()] = $ctrl->getParam($param, LuBusiness::checkParam($param->getName()));
139
                     $args[$param->getName()] = $ctrl->getParam($param, LuBusiness::checkParam($param->getName()));
136
                 }
140
                 }
141
+
142
+                try {
143
+                    if (array_key_exists($param->getName(), $doc->getParams())) {
144
+                        foreach ($doc->getParams()[$param->getName()]->getConstraints() as $constraint) {
145
+                            call_user_func_array([$args[$param->getName()], $constraint->getMethod()],
146
+                                $constraint->getArguments());
147
+                        }
148
+                    }
149
+                }
150
+                catch (LuDboConstraintException $e)
151
+                {
152
+                    $paramName = $param->getName();
153
+                    LuBusiness::badInput("Invalid value for '${paramName}': " . $e->getMessage());
154
+                }
137
             }
155
             }
138
 
156
 
139
             $controllerInstance = new $controller();
157
             $controllerInstance = new $controller();

Loading…
Cancel
Save