Pārlūkot izejas kodu

run constraints checks on routing

tags/0.1.11
Robin Thoni 8 gadus atpakaļ
vecāks
revīzija
fc49ec017d
1 mainītis faili ar 18 papildinājumiem un 0 dzēšanām
  1. 18
    0
      src/Utils/LuRoute.php

+ 18
- 0
src/Utils/LuRoute.php Parādīt failu

@@ -2,6 +2,8 @@
2 2
 
3 3
 namespace Luticate\Utils;
4 4
 
5
+use Luticate\Utils\Business\LuDocParser;
6
+use Luticate\Utils\Dbo\LuDboConstraintException;
5 7
 use Luticate\Utils\Dbo\LuDboDeserializeException;
6 8
 
7 9
 class LuRoute {
@@ -118,6 +120,8 @@ class LuRoute {
118 120
         {
119 121
             $reflect = new \ReflectionMethod($controller, $method);
120 122
             $params = $reflect->getParameters();
123
+            $doc = new LuDocParser($reflect->getDocComment());
124
+            $doc->parse();
121 125
 
122 126
             $args = array();
123 127
             foreach ($params as $param) {
@@ -134,6 +138,20 @@ class LuRoute {
134 138
                 else {
135 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 157
             $controllerInstance = new $controller();

Notiek ielāde…
Atcelt
Saglabāt