public function invoke(URLComponent $url) { $class_name = $url->getController(); $method = $url->getAction(); $class = $this->app . '\\action\\' . $class_name; //Response对象 $response = Response::getInstance(); //Request对象 $request = Request::getInstance(); #实例化控制器,使用反射 $reflection = new \ReflectionClass($class); $instacne = $reflection->newInstance(); //先执行初始化方法init if ($reflection->hasMethod('init')) { $init = $reflection->getMethod('init'); $data = $init->invokeArgs($instacne, array($request, $response)); if ($data) { //如果有返回数据则输出 $response->setBody($data); $response->send(); return true; } } if ($reflection->hasMethod($method)) { $method = $reflection->getMethod($method); } elseif ($reflection->hasMethod('getMiss')) { $method = $reflection->getMethod('getMiss'); } else { throw new RouteException('Method does not exist.'); } $data = $method->invokeArgs($instacne, array($request, $response)); #输出 $response->setBody($data); $response->send(); }