/** * @RequestMapping(value="/user/{uid:\d+}") */ public function aaa(int $bb,int $uid) { return "aaa---".$uid; }
case FastRoute\Dispatcher::FOUND: $handler = $routeInfo[1]; $vars = $routeInfo[2];//参数 /*var_dump($vars); exit;*/ /* array(1) { ["uid"]=> string(3) "123" }*/ // ... call $handler with $vars $response->end($handler($vars)); //最终执行的目标方法 break;
invokeArgs — 带参数执行
//return $method->invoke($instance);//执行反射方法 $inputParams=[]; //得到方法的反射参数 $refParams=$method->getParameters(); //var_dump($refParams);exit; //value="/user/{uid:\d+}" /*[0]=> object(ReflectionParameter)#35 (1) { ["name"]=> string(3) "uid" }*/ foreach ($refParams as $refParam){ if(isset($params[$refParam->getName()])){ $inputParams[] = $params[$refParam->getName()]; }else{ $inputParams[] = false; } } return $method->invokeArgs($instance,$inputParams);