public function testRetainQueryString() { // given $app = new UrlLintApp(new StubApp()); $ctx = $this->createContext(Url::fromString('/foo/bar/')); $ctx->getRequest()->setGetParams(['foo' => 'bar', 'baz' => 'bin']); // when $loc = ''; try { $app->call($ctx); } catch (RedirectException $e) { $loc = $e->getLocation(); } //then $this->assertEquals('/foo/bar?foo=bar&baz=bin', (string) $loc); }
public function call(Context $context) { $currentHost = $context->getRequest()->getHost(); $currentProtocol = $context->getRequest()->getProtocol(); $currentUrl = $context->getRequest()->getUrl(); $currentMethod = $context->getRequest()->getHttpMethod(); // Identify current Command; register RouteMap & params with Context $route; try { $route = $this->routeMap->getRoute($context->getRequest()); } catch (RouteException $e) { throw new NotFoundException(sprintf("Route not found for request: %s %s://%s%s", $currentMethod, $currentProtocol, $currentHost, $currentUrl)); } $context->setProp(self::CURRENT_ROUTE, $route); // Force pages to their designated protocol if specified if ($route->getProtocol() != null) { if ($currentProtocol != $route->getProtocol()) { $url = Url::fromString(sprintf("%s://%s/", $route->getProtocol(), $currentHost))->join($currentUrl)->addParams($_GET); throw new RedirectException('Change Protocol', 301, $url); } } $this->wrappedApp->call($context); }
private static function getCurrentUrl() { $urlParts = parse_url($_SERVER['REQUEST_URI']); $str = '/' . ltrim($urlParts['path'], '/'); return Url::fromString($str); }