/** * @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; }
/** * @param Request $request * @param Route $route * @return Request|null */ protected function match(Request $request, Route $route) { return !$route->host() || in_array($request->host(), (array) $route->host()) ? $request : null; }
/** * @param RouteRequest $request * @param Route $route * @param string $name * @param null|Route $parent * @return Request */ protected function step(RouteRequest $request, Route $route, $name, $parent = null) { return $this->route($request->with(Arg::NAME, $this->name(is_string($name) ? $name : $route->name(), $request->name())), $route, $parent); }
/** * @param Request $request * @param Route $route * @return bool */ protected function match(Request $request, Route $route) { return in_array($request->scheme(), (array) $route->scheme()); }
/** * @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; }
/** * @param Request $request * @param Route $route * @return Request */ function __invoke(Request $request, Route $route) { ($middleware = $this->middleware($request->controller(), $route[Arg::MIDDLEWARE])) && ($request[Arg::CONTROLLER] = $middleware); return $request; }
/** * @param Request $request * @return array */ protected function params(Request $request) { return $request->get(Arg::PARAMS) ?: []; }
/** * @param Request $request * @param Route $route * @return Request */ function __invoke(Request $request, Route $route) { $route->actions() && ($controller = $route->action($request->method())) && ($request[Arg::CONTROLLER] = $controller); return $request; }