comparison core/lib/Drupal/Core/Utility/UnroutedUrlAssembler.php @ 16:c2387f117808

Routine composer update
author Chris Cannam
date Tue, 10 Jul 2018 15:07:59 +0100
parents 4c8ae668cc8c
children 129ea1e6d783
comparison
equal deleted inserted replaced
15:e200cb7efeb3 16:c2387f117808
1 <?php 1 <?php
2 2
3 namespace Drupal\Core\Utility; 3 namespace Drupal\Core\Utility;
4 4
5 use Drupal\Component\Utility\NestedArray;
5 use Drupal\Component\Utility\UrlHelper; 6 use Drupal\Component\Utility\UrlHelper;
6 use Drupal\Core\GeneratedUrl; 7 use Drupal\Core\GeneratedUrl;
7 use Drupal\Core\PathProcessor\OutboundPathProcessorInterface; 8 use Drupal\Core\PathProcessor\OutboundPathProcessorInterface;
8 use Symfony\Component\HttpFoundation\RequestStack; 9 use Symfony\Component\HttpFoundation\RequestStack;
9 10
67 /** 68 /**
68 * {@inheritdoc} 69 * {@inheritdoc}
69 */ 70 */
70 protected function buildExternalUrl($uri, array $options = [], $collect_bubbleable_metadata = FALSE) { 71 protected function buildExternalUrl($uri, array $options = [], $collect_bubbleable_metadata = FALSE) {
71 $this->addOptionDefaults($options); 72 $this->addOptionDefaults($options);
72 // Split off the fragment. 73 // Split off the query & fragment.
73 if (strpos($uri, '#') !== FALSE) { 74 $parsed = UrlHelper::parse($uri);
74 list($uri, $old_fragment) = explode('#', $uri, 2); 75 $uri = $parsed['path'];
75 // If $options contains no fragment, take it over from the path. 76
76 if (isset($old_fragment) && !$options['fragment']) { 77 $parsed += ['query' => []];
77 $options['fragment'] = '#' . $old_fragment; 78 $options += ['query' => []];
78 } 79
80 $options['query'] = NestedArray::mergeDeep($parsed['query'], $options['query']);
81 ksort($options['query']);
82
83 if ($parsed['fragment'] && !$options['fragment']) {
84 $options['fragment'] = '#' . $parsed['fragment'];
79 } 85 }
80 86
81 if (isset($options['https'])) { 87 if (isset($options['https'])) {
82 if ($options['https'] === TRUE) { 88 if ($options['https'] === TRUE) {
83 $uri = str_replace('http://', 'https://', $uri); 89 $uri = str_replace('http://', 'https://', $uri);
86 $uri = str_replace('https://', 'http://', $uri); 92 $uri = str_replace('https://', 'http://', $uri);
87 } 93 }
88 } 94 }
89 // Append the query. 95 // Append the query.
90 if ($options['query']) { 96 if ($options['query']) {
91 $uri .= (strpos($uri, '?') !== FALSE ? '&' : '?') . UrlHelper::buildQuery($options['query']); 97 $uri .= '?' . UrlHelper::buildQuery($options['query']);
92 } 98 }
93 // Reassemble. 99 // Reassemble.
94 $url = $uri . $options['fragment']; 100 $url = $uri . $options['fragment'];
95 return $collect_bubbleable_metadata ? (new GeneratedUrl())->setGeneratedUrl($url) : $url; 101 return $collect_bubbleable_metadata ? (new GeneratedUrl())->setGeneratedUrl($url) : $url;
96 } 102 }