142 private $_routeParamsResolver;
147 private $_routeParamsResolverFactory;
164 private $cacheUrl = [];
179 private $urlModifier;
189 private $hostChecker;
214 \
Magento\Framework\
App\Route\ConfigInterface $routeConfig,
216 \
Magento\Framework\
Url\SecurityInfoInterface $urlSecurityInfo,
217 \
Magento\Framework\
Url\ScopeResolverInterface $scopeResolver,
219 \
Magento\Framework\Session\SidResolverInterface $sidResolver,
220 \
Magento\Framework\
Url\RouteParamsResolverFactory $routeParamsResolverFactory,
221 \
Magento\Framework\
Url\QueryParamsResolverInterface $queryParamsResolver,
222 \
Magento\Framework\
App\Config\ScopeConfigInterface $scopeConfig,
227 Json $serializer =
null 230 $this->_routeConfig = $routeConfig;
231 $this->_urlSecurityInfo = $urlSecurityInfo;
232 $this->_scopeResolver = $scopeResolver;
234 $this->_sidResolver = $sidResolver;
235 $this->_routeParamsResolverFactory = $routeParamsResolverFactory;
236 $this->_queryParamsResolver = $queryParamsResolver;
237 $this->_scopeConfig = $scopeConfig;
239 $this->_scopeType = $scopeType;
241 ->get(HostChecker::class);
243 parent::__construct(
$data);
256 'scheme' =>
'setScheme',
260 'pass' =>
'setPassword',
262 'query' =>
'_setQuery',
263 'fragment' =>
'setFragment',
266 foreach ($parts as $component =>
$method) {
267 if (isset(
$data[$component])) {
282 $this->_useSession = (bool) $useSession;
294 if ($this->_useSession ===
null) {
295 $this->_useSession = $this->_sidResolver->getUseSessionInUrl();
315 if (!isset(self::$_configDataCache[$cacheId])) {
317 self::$_configDataCache[$cacheId] =
$data;
320 return self::$_configDataCache[$cacheId];
342 return $this->_scopeConfig->getValue(
391 if ($this->_request->isSecure()) {
402 if (!$this->
_getScope()->isUrlSecure()) {
408 $pathSecure = $this->_urlSecurityInfo->isSecure(
'/' . $this->
_getActionPath());
411 $isRequestSecure = $this->
_getRequest()->isSecure();
429 $this->
setData(
'scope', $this->_scopeResolver->getScope(
$params));
441 if (!$this->
hasData(
'scope')) {
460 if (isset(
$params[
'_scope'])) {
467 if (isset(
$params[
'_secure'])) {
475 && $this->
_getRequest()->isDirectAccessFrontendName(
505 $routePieces = explode(
'/',
$data);
507 $route = array_shift($routePieces);
508 if (
'*' === $route) {
514 if (!empty($routePieces)) {
523 if (!empty($routePieces)) {
524 $action = array_shift($routePieces);
525 if (
'*' === $action) {
531 if (!empty($routePieces)) {
532 while (!empty($routePieces)) {
533 $key = array_shift($routePieces);
534 if (!empty($routePieces)) {
535 $value = array_shift($routePieces);
561 $path .= self::DEFAULT_CONTROLLER_NAME .
'/';
566 $path .= self::DEFAULT_ACTION_NAME .
'/';
581 if (!$this->
hasData(
'route_path')) {
582 $routePath = $this->
_getRequest()->getAlias(self::REWRITE_REQUEST_PATH_ALIAS);
583 if (!empty($routeParams[
'_use_rewrite']) && $routePath !==
null) {
584 $this->
setData(
'route_path', $routePath);
593 $routePath .= $key .
'/' .
$value .
'/';
596 $this->
setData(
'route_path', $routePath);
598 return $this->
_getData(
'route_path');
613 ->unsetData(
'route_path')
614 ->unsetData(
'controller_name')
615 ->unsetData(
'action_name');
616 $this->_queryParamsResolver->unsetData(
'secure');
627 if (!$this->
hasData(
'route_front_name')) {
628 $frontName = $this->_routeConfig->getRouteFrontName(
630 $this->_scopeResolver->getAreaCode()
632 $this->
setData(
'route_front_name', $frontName);
634 return $this->
_getData(
'route_front_name');
645 return $this->
_getData(
'route_name') ? $this->
_getData(
'route_name') : $default;
661 $this->
unsetData(
'route_path')->unsetData(
'action_name');
662 $this->_queryParamsResolver->unsetData(
'secure');
674 return $this->
_getData(
'controller_name') ? $this->
_getData(
'controller_name') : $default;
691 $this->_queryParamsResolver->unsetData(
'secure');
703 return $this->
_getData(
'action_name') ? $this->
_getData(
'action_name') : $default;
736 public function getRouteUrl($routePath =
null, $routeParams =
null)
738 if (filter_var($routePath, FILTER_VALIDATE_URL)) {
744 if (isset($routeParams[
'_direct'])) {
745 if (is_array($routeParams)) {
748 return $this->
getBaseUrl() . $routeParams[
'_direct'];
752 if (is_array($routeParams)) {
767 $this->_sidResolver->getSessionIdQueryParam($this->_session),
768 $this->_session->getSessionId()
781 return $this->_queryParamsResolver->setQuery(
$data);
792 return $this->_queryParamsResolver->getQuery($escape);
803 $this->_queryParamsResolver->addQueryParams(
$data);
816 $this->_queryParamsResolver->setQueryParam($key,
$data);
839 public function getUrl($routePath =
null, $routeParams =
null)
841 if (filter_var($routePath, FILTER_VALIDATE_URL)) {
845 $routeParams = $this->routeParamsPreprocessor
846 ->execute($this->_scopeResolver->getAreaCode(), $routePath, $routeParams);
849 $isArray = is_array($routeParams);
852 array_walk_recursive(
854 function (
$item) use (&$isCached) {
855 if (is_object(
$item)) {
863 return $this->getUrlModifier()->execute(
864 $this->createUrl($routePath, $routeParams)
868 $cachedParams = $routeParams;
870 ksort($cachedParams);
873 $cacheKey = sha1($routePath . $this->serializer->serialize($cachedParams));
874 if (!isset($this->cacheUrl[$cacheKey])) {
875 $this->cacheUrl[$cacheKey] = $this->getUrlModifier()->execute(
876 $this->createUrl($routePath, $routeParams)
880 return $this->cacheUrl[$cacheKey];
892 private function createUrl($routePath =
null, array $routeParams =
null)
894 $escapeQuery =
false;
895 $escapeParams =
true;
904 if (isset($routeParams[
'_fragment'])) {
905 $fragment = $routeParams[
'_fragment'];
906 unset($routeParams[
'_fragment']);
909 if (isset($routeParams[
'_escape'])) {
910 $escapeQuery = $routeParams[
'_escape'];
911 unset($routeParams[
'_escape']);
914 if (isset($routeParams[
'_escape_params'])) {
915 $escapeParams = $routeParams[
'_escape_params'];
916 unset($routeParams[
'_escape_params']);
921 if (isset($routeParams[
'_query'])) {
922 $this->_queryParamsResolver->setQueryParams([]);
923 $query = $routeParams[
'_query'];
924 unset($routeParams[
'_query']);
928 if (isset($routeParams[
'_nosid'])) {
929 $noSid = (bool)$routeParams[
'_nosid'];
930 unset($routeParams[
'_nosid']);
948 if ($noSid !==
true) {
954 $mark = strpos(
$url,
'?') ===
false ?
'?' : ($escapeQuery ?
'&' :
'&');
956 $this->_queryParamsResolver->unsetData(
'query');
957 $this->_queryParamsResolver->unsetData(
'query_params');
960 if ($fragment !==
null) {
961 $url .=
'#' . $this->getEscaper()->encodeUrlParam($fragment);
981 $sessionId = $this->_session->getSessionIdForHost(
$url);
982 if ($this->_sidResolver->getUseSessionVar() && !$sessionId) {
985 $this->
setQueryParam($this->_sidResolver->getSessionIdQueryParam($this->_session), $sessionId);
999 $port = $this->getPort();
1001 $port =
':' . $port;
1005 $url = $this->getScheme() .
'://' . $this->getHost() . $port . $this->getPath();
1016 $url .=
'#' . $this->getEscaper()->encodeUrlParam($fragment);
1059 return preg_replace_callback(
1060 '#(\?|&|&)___SID=([SU])(&|&)?#',
1071 return $match[1] . $this->_sidResolver->getSessionIdQueryParam($this->_session) .
'=' 1072 . $this->_session->getSessionId() . (isset($match[3]) ? $match[3] :
'');
1074 if ($match[1] ==
'?') {
1075 return isset($match[3]) ?
'?' :
'';
1076 }
elseif ($match[1] ==
'&' || $match[1] ==
'&') {
1077 return $match[3] ??
'';
1093 $key =
'use_session_id_for_url_' . (int)$secure;
1094 if ($this->
getData($key) ===
null) {
1095 $httpHost = $this->_request->getHttpHost();
1096 $urlHost = parse_url(
1101 if ($httpHost != $urlHost) {
1117 return $this->hostChecker->isOwnOrigin($this->_request->getServer(
'HTTP_REFERER'));
1145 $httpHostWithPort = $this->_request->getHttpHost(
false);
1146 $httpHostWithPort = explode(
':', $httpHostWithPort);
1147 $httpHost = isset($httpHostWithPort[0]) ? $httpHostWithPort[0] :
'';
1149 if (isset($httpHostWithPort[1])) {
1154 if (!in_array($httpHostWithPort[1], $defaultPorts)) {
1156 $port =
':' . $httpHostWithPort[1];
1159 return $this->_request->getScheme() .
'://' . $httpHost . $port . $this->_request->getRequestUri();
1169 if (!$this->_routeParamsResolver) {
1170 $this->_routeParamsResolver = $this->_routeParamsResolverFactory->create();
1172 return $this->_routeParamsResolver;
1181 private function getUrlModifier()
1183 if ($this->urlModifier ===
null) {
1185 \
Magento\Framework\
Url\ModifierInterface::class
1189 return $this->urlModifier;
1198 private function getEscaper()
1200 if ($this->escaper ==
null) {
1202 ->get(\
Magento\Framework\Escaper::class);
1204 return $this->escaper;
getDirectUrl($url, $params=[])
_getActionName($default=null)
setRequest(\Magento\Framework\App\RequestInterface $request)
getData($key='', $index=null)
elseif(isset( $params[ 'redirect_parent']))
useSessionIdForUrl($secure=false)
_getRouteName($default=null)
getUrl($routePath=null, $routeParams=null)
__construct(\Magento\Framework\App\Route\ConfigInterface $routeConfig, \Magento\Framework\App\RequestInterface $request, \Magento\Framework\Url\SecurityInfoInterface $urlSecurityInfo, \Magento\Framework\Url\ScopeResolverInterface $scopeResolver, \Magento\Framework\Session\Generic $session, \Magento\Framework\Session\SidResolverInterface $sidResolver, \Magento\Framework\Url\RouteParamsResolverFactory $routeParamsResolverFactory, \Magento\Framework\Url\QueryParamsResolverInterface $queryParamsResolver, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Framework\Url\RouteParamsPreprocessorInterface $routeParamsPreprocessor, $scopeType, array $data=[], HostChecker $hostChecker=null, Json $serializer=null)
setUseSession($useSession)
getConfigData($key, $prefix=null)
setQueryParam($key, $data)
_setControllerName($data)
_setRouteParams(array $data, $unsetOldParams=true)
setData($key, $value=null)
_getControllerName($default=null)
getRouteUrl($routePath=null, $routeParams=null)
addQueryParams(array $data)
const URL_TYPE_DIRECT_LINK
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
_getRoutePath($routeParams=[])