示例#1
0
文件: Path.php 项目: mvc5/framework
 /**
  * @param Event $event
  * @param Request $request
  * @param Route $route
  * @return Request
  */
 function __invoke(Event $event, Request $request, Route $route)
 {
     if (!preg_match('(\\G' . $route->regex() . ')', $request->path(), $match, null, $request->length())) {
         return null;
     }
     $request[Arg::CONTROLLER] = $route->controller();
     $request[Arg::LENGTH] = $request->length() + strlen($match[0]);
     $request[Arg::MATCHED] = $request->length() == strlen($request->path());
     $request[Arg::PARAMS] = $this->params($match, $route->defaults() + $request->params());
     return $request->matched() || $route->children() && $event->stop() ? $request : null;
 }
示例#2
0
 /**
  * @param Request $request
  * @param Route $route
  * @return Request|NotFound
  */
 function __invoke(Request $request, Route $route)
 {
     if ($request->controller()) {
         return $request;
     }
     $options = $this->options($route);
     $params = $request->params();
     $action = $this->format($this->action($params, $options), $options);
     $controller = $this->format($this->controller($params, $options), $options);
     $name = $this->name($action, $controller, $options);
     if ($this->invalid($action, $controller, $this->replacement($options))) {
         return null;
     }
     $controller = $this->match($name, $this->load($name));
     if (!$controller) {
         return new NotFound();
     }
     $request[Arg::CONTROLLER] = $controller;
     return $request;
 }