/** * Inspects the request and determines what to serve. */ public function dispatch(Request $request) { // This is a crappy place for this, but it has to come AFTER the packages because sometimes packages // want to replace legacy "tools" URLs with the new MVC, and the tools paths are so greedy they don't // work unless they come at the end. $this->registerLegacyRoutes(); $path = rawurldecode($request->getPathInfo()); if (substr($path, 0, 3) == '../' || substr($path, -3) == '/..' || strpos($path, '/../') || substr($path, 0, 3) == '..\\' || substr($path, -3) == '\\..' || strpos($path, '\\..\\')) { throw new \RuntimeException(t('Invalid path traversal. Please make this request with a valid HTTP client.')); } if ($this->installed) { $response = $this->getEarlyDispatchResponse(); } if (!isset($response)) { $collection = Route::getList(); $context = new \Symfony\Component\Routing\RequestContext(); $context->fromRequest($request); $matcher = new UrlMatcher($collection, $context); $path = rtrim($request->getPathInfo(), '/') . '/'; try { $request->attributes->add($matcher->match($path)); $matched = $matcher->match($path); $route = $collection->get($matched['_route']); Route::setRequest($request); $response = Route::execute($route, $matched); } catch (ResourceNotFoundException $e) { $callback = new DispatcherRouteCallback('dispatcher'); $response = $callback->execute($request); } } return $response; }
/** * Returns the path being requested relative to the executed script. * * The path info always starts with a /. * * Suppose this request is instantiated from /mysite on localhost: * * * http://localhost/mysite returns an empty string * * http://localhost/mysite/about returns '/about' * * http://localhost/mysite/enco%20ded returns '/enco%20ded' * * http://localhost/mysite/about?var=1 returns '/about' * * @return string The raw path (i.e. not urldecoded) * * @api */ public function getPathInfo() { return parent::getPathInfo(); }