Example #1
0
 public function finalMatch(RouteCollection $collection, Request $request)
 {
     $this->routes = $collection;
     $context = new RequestContext();
     $context->fromRequest($request);
     $this->setContext($context);
     return $this->match($this->currentPath->getPath($request));
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->requestContext = $this->getMockBuilder('Drupal\\Core\\Routing\\RequestContext')->disableOriginalConstructor()->getMock();
     $this->requestContext->expects($this->any())->method('getCompleteBaseUrl')->willReturn('http://example.com/drupal');
     $container = new Container();
     $container->set('router.request_context', $this->requestContext);
     \Drupal::setContainer($container);
 }
 /**
  * @covers ::setTargetUrl
  * @expectedException \InvalidArgumentException
  */
 public function testSetTargetUrlWithUntrustedUrl()
 {
     $request_context = new RequestContext();
     $request_context->setCompleteBaseUrl('https://www.drupal.org');
     $container = new ContainerBuilder();
     $container->set('router.request_context', $request_context);
     \Drupal::setContainer($container);
     $redirect_response = new TrustedRedirectResponse('/example');
     $redirect_response->setTargetUrl('http://evil-url.com/example');
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->requestContext = $this->getMockBuilder('Drupal\\Core\\Routing\\RequestContext')->disableOriginalConstructor()->getMock();
     $this->requestContext->expects($this->any())->method('getCompleteBaseUrl')->willReturn('http://example.com/drupal');
     $this->urlAssembler = $this->getMock(UnroutedUrlAssemblerInterface::class);
     $this->urlAssembler->expects($this->any())->method('assemble')->willReturnMap([['base:test', ['query' => [], 'fragment' => '', 'absolute' => TRUE], FALSE, 'http://example.com/drupal/test'], ['base:example.com', ['query' => [], 'fragment' => '', 'absolute' => TRUE], FALSE, 'http://example.com/drupal/example.com'], ['base:example:com', ['query' => [], 'fragment' => '', 'absolute' => TRUE], FALSE, 'http://example.com/drupal/example:com'], ['base:javascript:alert(0)', ['query' => [], 'fragment' => '', 'absolute' => TRUE], FALSE, 'http://example.com/drupal/javascript:alert(0)']]);
     $container = new Container();
     $container->set('router.request_context', $this->requestContext);
     \Drupal::setContainer($container);
 }
Example #5
0
 /**
  * Implements \Drupal\Core\Form\FormInterface::buildForm().
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $config = $this->config('headless.config');
     $form['routing'] = array('#type' => 'details', '#title' => $this->t('Routing'), '#description' => $this->t('This is the publicly accessible path to User operation routes.'), '#open' => TRUE);
     $routing_path = $config->get('routing_path');
     if (empty($routing_path)) {
         $routing_path = 'headless';
     }
     $form['routing']['routing_path'] = array('#type' => 'textfield', '#title' => $this->t('Path'), '#size' => 55, '#maxlength' => 55, '#default_value' => $routing_path, '#required' => TRUE, '#field_prefix' => $this->requestContext->getCompleteBaseUrl() . '/');
     return parent::buildForm($form, $form_state);
 }
 /**
  * Matches a path in the router.
  *
  * @param string $path
  *   The request path.
  * @param array $exclude
  *   An array of paths or system paths to skip.
  *
  * @return \Symfony\Component\HttpFoundation\Request
  *   A populated request object or NULL if the path couldn't be matched.
  */
 protected function getRequestForPath($path, array $exclude)
 {
     if (!empty($exclude[$path])) {
         return NULL;
     }
     // @todo Use the RequestHelper once https://drupal.org/node/2090293 is
     //   fixed.
     $request = Request::create($this->context->getCompleteBaseUrl() . '/' . $path);
     // Performance optimization: set a short accept header to reduce overhead in
     // AcceptHeaderMatcher when matching the request.
     $request->headers->set('Accept', 'text/html');
     // Find the system path by resolving aliases, language prefix, etc.
     $processed = $this->pathProcessor->processInbound($path, $request);
     if (empty($processed) || !empty($exclude[$processed])) {
         // This resolves to the front page, which we already add.
         return NULL;
     }
     $this->currentPath->setPath('/' . $processed, $request);
     // Attempt to match this path to provide a fully built request.
     try {
         $request->attributes->add($this->router->matchRequest($request));
         return $request;
     } catch (ParamNotConvertedException $e) {
         return NULL;
     } catch (ResourceNotFoundException $e) {
         return NULL;
     } catch (MethodNotAllowedException $e) {
         return NULL;
     } catch (AccessDeniedHttpException $e) {
         return NULL;
     }
 }
 public function finalMatch(RouteCollection $collection, Request $request)
 {
     $this->routes = $collection;
     $context = new RequestContext();
     $context->fromRequest($request);
     $this->setContext($context);
     if ($request->attributes->has('_system_path')) {
         // _system_path never has leading or trailing slashes.
         $path = '/' . $request->attributes->get('_system_path');
     } else {
         // getPathInfo() always has leading slash, and might or might not have a
         // trailing slash.
         $path = rtrim($request->getPathInfo(), '/');
     }
     return $this->match($path);
 }
 protected function setUp()
 {
     $routes = new RouteCollection();
     $first_route = new Route('/test/one');
     $second_route = new Route('/test/two/{narf}');
     $third_route = new Route('/test/two/');
     $fourth_route = new Route('/test/four', array(), array('_scheme' => 'https'));
     $routes->add('test_1', $first_route);
     $routes->add('test_2', $second_route);
     $routes->add('test_3', $third_route);
     $routes->add('test_4', $fourth_route);
     // Create a route provider stub.
     $provider = $this->getMockBuilder('Drupal\\Core\\Routing\\RouteProvider')->disableOriginalConstructor()->getMock();
     // We need to set up return value maps for both the getRouteByName() and the
     // getRoutesByNames() method calls on the route provider. The parameters
     // are not passed in and default to an empty array.
     $route_name_return_map = $routes_names_return_map = array();
     $return_map_values = array(array('route_name' => 'test_1', 'return' => $first_route), array('route_name' => 'test_2', 'return' => $second_route), array('route_name' => 'test_3', 'return' => $third_route), array('route_name' => 'test_4', 'return' => $fourth_route));
     foreach ($return_map_values as $values) {
         $route_name_return_map[] = array($values['route_name'], $values['return']);
         $routes_names_return_map[] = array(array($values['route_name']), $values['return']);
     }
     $provider->expects($this->any())->method('getRouteByName')->will($this->returnValueMap($route_name_return_map));
     $provider->expects($this->any())->method('getRoutesByNames')->will($this->returnValueMap($routes_names_return_map));
     // Create an alias manager stub.
     $alias_manager = $this->getMockBuilder('Drupal\\Core\\Path\\AliasManager')->disableOriginalConstructor()->getMock();
     $alias_manager->expects($this->any())->method('getAliasByPath')->will($this->returnCallback(array($this, 'aliasManagerCallback')));
     $this->aliasManager = $alias_manager;
     $this->requestStack = new RequestStack();
     $request = Request::create('/some/path');
     $this->requestStack->push($request);
     $context = new RequestContext();
     $context->fromRequestStack($this->requestStack);
     $processor = new PathProcessorAlias($this->aliasManager);
     $processor_manager = new PathProcessorManager();
     $processor_manager->addOutbound($processor, 1000);
     $this->routeProcessorManager = $this->getMockBuilder('Drupal\\Core\\RouteProcessor\\RouteProcessorManager')->disableOriginalConstructor()->getMock();
     $config_factory_stub = $this->getConfigFactoryStub(array('system.filter' => array('protocols' => array('http', 'https'))));
     $generator = new UrlGenerator($provider, $processor_manager, $this->routeProcessorManager, $config_factory_stub, NULL, $this->requestStack);
     $generator->setContext($context);
     $this->generator = $generator;
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     $cache_contexts_manager = $this->getMockBuilder('Drupal\\Core\\Cache\\Context\\CacheContextsManager')->disableOriginalConstructor()->getMock();
     $cache_contexts_manager->method('assertValidTokens')->willReturn(TRUE);
     $container = new ContainerBuilder();
     $container->set('cache_contexts_manager', $cache_contexts_manager);
     \Drupal::setContainer($container);
     $routes = new RouteCollection();
     $first_route = new Route('/test/one');
     $second_route = new Route('/test/two/{narf}');
     $third_route = new Route('/test/two/');
     $fourth_route = new Route('/test/four', [], [], [], '', ['https']);
     $none_route = new Route('', [], [], ['_no_path' => TRUE]);
     $routes->add('test_1', $first_route);
     $routes->add('test_2', $second_route);
     $routes->add('test_3', $third_route);
     $routes->add('test_4', $fourth_route);
     $routes->add('<none>', $none_route);
     // Create a route provider stub.
     $provider = $this->getMockBuilder('Drupal\\Core\\Routing\\RouteProvider')->disableOriginalConstructor()->getMock();
     // We need to set up return value maps for both the getRouteByName() and the
     // getRoutesByNames() method calls on the route provider. The parameters
     // are not passed in and default to an empty array.
     $route_name_return_map = $routes_names_return_map = array();
     $return_map_values = array(['route_name' => 'test_1', 'return' => $first_route], ['route_name' => 'test_2', 'return' => $second_route], ['route_name' => 'test_3', 'return' => $third_route], ['route_name' => 'test_4', 'return' => $fourth_route], ['route_name' => '<none>', 'return' => $none_route]);
     foreach ($return_map_values as $values) {
         $route_name_return_map[] = array($values['route_name'], $values['return']);
         $routes_names_return_map[] = array(array($values['route_name']), $values['return']);
     }
     $this->provider = $provider;
     $this->provider->expects($this->any())->method('getRouteByName')->will($this->returnValueMap($route_name_return_map));
     $provider->expects($this->any())->method('getRoutesByNames')->will($this->returnValueMap($routes_names_return_map));
     // Create an alias manager stub.
     $alias_manager = $this->getMockBuilder('Drupal\\Core\\Path\\AliasManager')->disableOriginalConstructor()->getMock();
     $alias_manager->expects($this->any())->method('getAliasByPath')->will($this->returnCallback(array($this, 'aliasManagerCallback')));
     $this->aliasManager = $alias_manager;
     $this->requestStack = new RequestStack();
     $request = Request::create('/some/path');
     $this->requestStack->push($request);
     $this->context = new RequestContext();
     $this->context->fromRequestStack($this->requestStack);
     $processor = new PathProcessorAlias($this->aliasManager);
     $processor_manager = new PathProcessorManager();
     $processor_manager->addOutbound($processor, 1000);
     $this->routeProcessorManager = $this->getMockBuilder('Drupal\\Core\\RouteProcessor\\RouteProcessorManager')->disableOriginalConstructor()->getMock();
     $generator = new UrlGenerator($this->provider, $processor_manager, $this->routeProcessorManager, $this->requestStack, ['http', 'https']);
     $generator->setContext($this->context);
     $this->generator = $generator;
 }
 /**
  * Tests the breadcrumb for a user path.
  *
  * @covers ::build
  * @covers ::getRequestForPath
  */
 public function testBuildWithUserPath()
 {
     $this->context->expects($this->once())->method('getPathInfo')->will($this->returnValue('/user/1/edit'));
     $this->setupStubPathProcessor();
     $route_1 = new Route('/user/1');
     $this->requestMatcher->expects($this->exactly(1))->method('matchRequest')->will($this->returnCallback(function (Request $request) use($route_1) {
         if ($request->getPathInfo() == '/user/1') {
             return array(RouteObjectInterface::ROUTE_NAME => 'user_page', RouteObjectInterface::ROUTE_OBJECT => $route_1, '_raw_variables' => new ParameterBag(array()));
         }
     }));
     $this->setupAccessManagerToAllow();
     $this->titleResolver->expects($this->once())->method('getTitle')->with($this->anything(), $route_1)->will($this->returnValue('Admin'));
     $links = $this->builder->build($this->getMock('Drupal\\Core\\Routing\\RouteMatchInterface'));
     $this->assertEquals(array(0 => new Link('Home', new Url('<front>')), 1 => new Link('Admin', new Url('user_page'))), $links);
 }
 /**
  * {@inheritdoc}
  */
 public function build(RouteMatchInterface $route_match)
 {
     $breadcrumb = new Breadcrumb();
     $links = array();
     // General path-based breadcrumbs. Use the actual request path, prior to
     // resolving path aliases, so the breadcrumb can be defined by simply
     // creating a hierarchy of path aliases.
     $path = trim($this->context->getPathInfo(), '/');
     $path_elements = explode('/', $path);
     $exclude = array();
     // Don't show a link to the front-page path.
     $front = $this->config->get('page.front');
     $exclude[$front] = TRUE;
     // /user is just a redirect, so skip it.
     // @todo Find a better way to deal with /user.
     $exclude['/user'] = TRUE;
     // Because this breadcrumb builder is entirely path-based, vary by the
     // 'url.path' cache context.
     $breadcrumb->addCacheContexts(['url.path']);
     while (count($path_elements) > 1) {
         array_pop($path_elements);
         // Copy the path elements for up-casting.
         $route_request = $this->getRequestForPath('/' . implode('/', $path_elements), $exclude);
         if ($route_request) {
             $route_match = RouteMatch::createFromRequest($route_request);
             $access = $this->accessManager->check($route_match, $this->currentUser, NULL, TRUE);
             // The set of breadcrumb links depends on the access result, so merge
             // the access result's cacheability metadata.
             $breadcrumb = $breadcrumb->addCacheableDependency($access);
             if ($access->isAllowed()) {
                 $title = $this->titleResolver->getTitle($route_request, $route_match->getRouteObject());
                 if (!isset($title)) {
                     // Fallback to using the raw path component as the title if the
                     // route is missing a _title or _title_callback attribute.
                     $title = str_replace(array('-', '_'), ' ', Unicode::ucfirst(end($path_elements)));
                 }
                 $url = Url::fromRouteMatch($route_match);
                 $links[] = new Link($title, $url);
             }
         }
     }
     if ($path && '/' . $path != $front) {
         // Add the Home link, except for the front page.
         $links[] = Link::createFromRoute($this->t('Home'), '<front>');
     }
     return $breadcrumb->setLinks(array_reverse($links));
 }
Example #12
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $site_config = $this->config('system.site');
     $site_mail = $site_config->get('mail');
     if (empty($site_mail)) {
         $site_mail = ini_get('sendmail_from');
     }
     $form['site_information'] = array('#type' => 'details', '#title' => t('Site details'), '#open' => TRUE);
     $form['site_information']['site_name'] = array('#type' => 'textfield', '#title' => t('Site name'), '#default_value' => $site_config->get('name'), '#required' => TRUE);
     $form['site_information']['site_slogan'] = array('#type' => 'textfield', '#title' => t('Slogan'), '#default_value' => $site_config->get('slogan'), '#description' => t("How this is used depends on your site's theme."));
     $form['site_information']['site_mail'] = array('#type' => 'email', '#title' => t('Email address'), '#default_value' => $site_mail, '#description' => t("The <em>From</em> address in automated emails sent during registration and new password requests, and other notifications. (Use an address ending in your site's domain to help prevent this email being flagged as spam.)"), '#required' => TRUE);
     $form['front_page'] = array('#type' => 'details', '#title' => t('Front page'), '#open' => TRUE);
     $front_page = $site_config->get('page.front') != '/user/login' ? $this->aliasManager->getAliasByPath($site_config->get('page.front')) : '';
     $form['front_page']['site_frontpage'] = array('#type' => 'textfield', '#title' => t('Default front page'), '#default_value' => $front_page, '#size' => 40, '#description' => t('Optionally, specify a relative URL to display as the front page. Leave blank to display the default front page.'), '#field_prefix' => $this->requestContext->getCompleteBaseUrl());
     $form['error_page'] = array('#type' => 'details', '#title' => t('Error pages'), '#open' => TRUE);
     $form['error_page']['site_403'] = array('#type' => 'textfield', '#title' => t('Default 403 (access denied) page'), '#default_value' => $site_config->get('page.403'), '#size' => 40, '#description' => t('This page is displayed when the requested document is denied to the current user. Leave blank to display a generic "access denied" page.'));
     $form['error_page']['site_404'] = array('#type' => 'textfield', '#title' => t('Default 404 (not found) page'), '#default_value' => $site_config->get('page.404'), '#size' => 40, '#description' => t('This page is displayed when no other content matches the requested document. Leave blank to display a generic "page not found" page.'));
     return parent::buildForm($form, $form_state);
 }
Example #13
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, $pid = NULL)
 {
     $this->path = $this->buildPath($pid);
     $form['source'] = array('#type' => 'textfield', '#title' => $this->t('Existing system path'), '#default_value' => $this->path['source'], '#maxlength' => 255, '#size' => 45, '#description' => $this->t('Specify the existing path you wish to alias. For example: /node/28, /forum/1, /taxonomy/term/1.'), '#field_prefix' => $this->requestContext->getCompleteBaseUrl(), '#required' => TRUE);
     $form['alias'] = array('#type' => 'textfield', '#title' => $this->t('Path alias'), '#default_value' => $this->path['alias'], '#maxlength' => 255, '#size' => 45, '#description' => $this->t('Specify an alternative path by which this data can be accessed. For example, type "/about" when writing an about page. Use a relative path with a slash in front..'), '#field_prefix' => $this->requestContext->getCompleteBaseUrl(), '#required' => TRUE);
     // A hidden value unless language.module is enabled.
     if (\Drupal::moduleHandler()->moduleExists('language')) {
         $languages = \Drupal::languageManager()->getLanguages();
         $language_options = array();
         foreach ($languages as $langcode => $language) {
             $language_options[$langcode] = $language->getName();
         }
         $form['langcode'] = array('#type' => 'select', '#title' => $this->t('Language'), '#options' => $language_options, '#empty_value' => LanguageInterface::LANGCODE_NOT_SPECIFIED, '#empty_option' => $this->t('- None -'), '#default_value' => $this->path['langcode'], '#weight' => -10, '#description' => $this->t('A path alias set for a specific language will always be used when displaying this page in that language, and takes precedence over path aliases set as <em>- None -</em>.'));
     } else {
         $form['langcode'] = array('#type' => 'value', '#value' => $this->path['langcode']);
     }
     $form['actions'] = array('#type' => 'actions');
     $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Save'));
     return $form;
 }
Example #14
0
 /**
  * {@inheritdoc}
  */
 public function generateFromRoute($name, $parameters = array(), $options = array(), $collect_bubbleable_metadata = FALSE)
 {
     $options += array('prefix' => '');
     $route = $this->getRoute($name);
     $generated_url = $collect_bubbleable_metadata ? new GeneratedUrl() : NULL;
     $query_params = [];
     // Symfony adds any parameters that are not path slugs as query strings.
     if (isset($options['query']) && is_array($options['query'])) {
         $query_params = $options['query'];
     }
     $fragment = '';
     if (isset($options['fragment'])) {
         if (($fragment = trim($options['fragment'])) != '') {
             $fragment = '#' . $fragment;
         }
     }
     // Generate a relative URL having no path, just query string and fragment.
     if ($route->getOption('_no_path')) {
         $query = $query_params ? '?' . http_build_query($query_params, '', '&') : '';
         $url = $query . $fragment;
         return $collect_bubbleable_metadata ? $generated_url->setGeneratedUrl($url) : $url;
     }
     $options += $route->getOption('default_url_options') ?: [];
     $options += array('prefix' => '', 'path_processing' => TRUE);
     $name = $this->getRouteDebugMessage($name);
     $this->processRoute($name, $route, $parameters, $generated_url);
     $path = $this->getInternalPathFromRoute($name, $route, $parameters, $query_params);
     // Outbound path processors might need the route object for the path, e.g.
     // to get the path pattern.
     $options['route'] = $route;
     if ($options['path_processing']) {
         $path = $this->processPath($path, $options, $generated_url);
     }
     if (!empty($options['prefix'])) {
         $path = ltrim($path, '/');
         $prefix = empty($path) ? rtrim($options['prefix'], '/') : $options['prefix'];
         $path = '/' . str_replace('%2F', '/', rawurlencode($prefix)) . $path;
     }
     // The base_url might be rewritten from the language rewrite in domain mode.
     if (isset($options['base_url'])) {
         $base_url = $options['base_url'];
         if (isset($options['https'])) {
             if ($options['https'] === TRUE) {
                 $base_url = str_replace('http://', 'https://', $base_url);
             } elseif ($options['https'] === FALSE) {
                 $base_url = str_replace('https://', 'http://', $base_url);
             }
         }
         $url = $base_url . $path . $fragment;
         return $collect_bubbleable_metadata ? $generated_url->setGeneratedUrl($url) : $url;
     }
     $base_url = $this->context->getBaseUrl();
     $absolute = !empty($options['absolute']);
     if (!$absolute || !($host = $this->context->getHost())) {
         $url = $base_url . $path . $fragment;
         return $collect_bubbleable_metadata ? $generated_url->setGeneratedUrl($url) : $url;
     }
     // Prepare an absolute URL by getting the correct scheme, host and port from
     // the request context.
     if (isset($options['https'])) {
         $scheme = $options['https'] ? 'https' : 'http';
     } else {
         $scheme = $this->context->getScheme();
     }
     $scheme_req = $route->getSchemes();
     if ($scheme_req && ($req = $scheme_req[0]) && $scheme !== $req) {
         $scheme = $req;
     }
     $port = '';
     if ('http' === $scheme && 80 != $this->context->getHttpPort()) {
         $port = ':' . $this->context->getHttpPort();
     } elseif ('https' === $scheme && 443 != $this->context->getHttpsPort()) {
         $port = ':' . $this->context->getHttpsPort();
     }
     if ($collect_bubbleable_metadata) {
         $generated_url->addCacheContexts(['url.site']);
     }
     $url = $scheme . '://' . $host . $port . $base_url . $path . $fragment;
     return $collect_bubbleable_metadata ? $generated_url->setGeneratedUrl($url) : $url;
 }
Example #15
0
 /**
  * {@inheritdoc}
  */
 public function generateFromRoute($name, $parameters = array(), $options = array(), $collect_cacheability_metadata = FALSE)
 {
     $generated_url = $collect_cacheability_metadata ? new GeneratedUrl() : NULL;
     $options += array('prefix' => '');
     $route = $this->getRoute($name);
     $name = $this->getRouteDebugMessage($name);
     $this->processRoute($name, $route, $parameters, $generated_url);
     $query_params = [];
     // Symfony adds any parameters that are not path slugs as query strings.
     if (isset($options['query']) && is_array($options['query'])) {
         $query_params = $options['query'];
     }
     $path = $this->getInternalPathFromRoute($name, $route, $parameters, $query_params);
     $path = $this->processPath($path, $options, $generated_url);
     if (!empty($options['prefix'])) {
         $path = ltrim($path, '/');
         $prefix = empty($path) ? rtrim($options['prefix'], '/') : $options['prefix'];
         $path = '/' . str_replace('%2F', '/', rawurlencode($prefix)) . $path;
     }
     $fragment = '';
     if (isset($options['fragment'])) {
         if (($fragment = trim($options['fragment'])) != '') {
             $fragment = '#' . $fragment;
         }
     }
     // The base_url might be rewritten from the language rewrite in domain mode.
     if (isset($options['base_url'])) {
         $base_url = $options['base_url'];
         if (isset($options['https'])) {
             if ($options['https'] === TRUE) {
                 $base_url = str_replace('http://', 'https://', $base_url);
             } elseif ($options['https'] === FALSE) {
                 $base_url = str_replace('https://', 'http://', $base_url);
             }
         }
         $url = $base_url . $path . $fragment;
         return $collect_cacheability_metadata ? $generated_url->setGeneratedUrl($url) : $url;
     }
     $base_url = $this->context->getBaseUrl();
     $absolute = !empty($options['absolute']);
     if (!$absolute || !($host = $this->context->getHost())) {
         if ($route->getOption('_only_fragment')) {
             return $collect_cacheability_metadata ? $generated_url->setGeneratedUrl($fragment) : $fragment;
         }
         $url = $base_url . $path . $fragment;
         return $collect_cacheability_metadata ? $generated_url->setGeneratedUrl($url) : $url;
     }
     // Prepare an absolute URL by getting the correct scheme, host and port from
     // the request context.
     if (isset($options['https'])) {
         $scheme = $options['https'] ? 'https' : 'http';
     } else {
         $scheme = $this->context->getScheme();
     }
     $scheme_req = $route->getRequirement('_scheme');
     if (isset($scheme_req) && ($req = strtolower($scheme_req)) && $scheme !== $req) {
         $scheme = $req;
     }
     $port = '';
     if ('http' === $scheme && 80 != $this->context->getHttpPort()) {
         $port = ':' . $this->context->getHttpPort();
     } elseif ('https' === $scheme && 443 != $this->context->getHttpsPort()) {
         $port = ':' . $this->context->getHttpsPort();
     }
     if ($collect_cacheability_metadata) {
         $generated_url->addCacheContexts(['url.site']);
     }
     $url = $scheme . '://' . $host . $port . $base_url . $path . $fragment;
     return $collect_cacheability_metadata ? $generated_url->setGeneratedUrl($url) : $url;
 }