Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes
Url Class Reference
Inheritance diagram for Url:
DataObject UrlInterface Url

Public Member Functions

 __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)
 
 getUseSession ()
 
 getConfigData ($key, $prefix=null)
 
 setRequest (\Magento\Framework\App\RequestInterface $request)
 
 setScope ($params)
 
 getBaseUrl ($params=[])
 
 getRouteUrl ($routePath=null, $routeParams=null)
 
 addSessionParam ()
 
 addQueryParams (array $data)
 
 setQueryParam ($key, $data)
 
 getUrl ($routePath=null, $routeParams=null)
 
 getRebuiltUrl ($url)
 
 escape ($value)
 
 getDirectUrl ($url, $params=[])
 
 sessionUrlVar ($html)
 
 useSessionIdForUrl ($secure=false)
 
 isOwnOriginUrl ()
 
 getRedirectUrl ($url)
 
 getCurrentUrl ()
 
- Public Member Functions inherited from DataObject
 __construct (array $data=[])
 
 addData (array $arr)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 getDataByPath ($path)
 
 getDataByKey ($key)
 
 setDataUsingMethod ($key, $args=[])
 
 getDataUsingMethod ($key, $args=null)
 
 hasData ($key='')
 
 toArray (array $keys=[])
 
 convertToArray (array $keys=[])
 
 toXml (array $keys=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 convertToXml (array $arrAttributes=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 toJson (array $keys=[])
 
 convertToJson (array $keys=[])
 
 toString ($format='')
 
 __call ($method, $args)
 
 isEmpty ()
 
 serialize ($keys=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
 
 debug ($data=null, &$objects=[])
 
 offsetSet ($offset, $value)
 
 offsetExists ($offset)
 
 offsetUnset ($offset)
 
 offsetGet ($offset)
 

Protected Member Functions

 _parseUrl ($url)
 
 _getConfigCacheId ($path)
 
 _getConfig ($path)
 
 _getRequest ()
 
 _getType ()
 
 _isSecure ()
 
 _getScope ()
 
 _setRoutePath ($data)
 
 _getActionPath ()
 
 _getRoutePath ($routeParams=[])
 
 _setRouteName ($data)
 
 _getRouteFrontName ()
 
 _getRouteName ($default=null)
 
 _setControllerName ($data)
 
 _getControllerName ($default=null)
 
 _setActionName ($data)
 
 _getActionName ($default=null)
 
 _setRouteParams (array $data, $unsetOldParams=true)
 
 _getRouteParams ()
 
 _setQuery ($data)
 
 _getQuery ($escape=false)
 
 _getFragment ()
 
 _prepareSessionUrl ($url)
 
 getRouteParamsResolver ()
 
- Protected Member Functions inherited from DataObject
 _getData ($key)
 
 _underscore ($name)
 

Protected Attributes

 $_reservedRouteParams
 
 $_scopeType
 
 $_request
 
 $_useSession
 
 $_urlSecurityInfo
 
 $_session
 
 $_sidResolver
 
 $_routeConfig
 
 $_scopeResolver
 
 $_queryParamsResolver
 
 $_scopeConfig
 
 $routeParamsPreprocessor
 
- Protected Attributes inherited from DataObject
 $_data = []
 

Static Protected Attributes

static $_configDataCache
 
- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Additional Inherited Members

- Data Fields inherited from UrlInterface
const URL_TYPE_LINK = 'link'
 
const URL_TYPE_DIRECT_LINK = 'direct_link'
 
const URL_TYPE_WEB = 'web'
 
const URL_TYPE_MEDIA = 'media'
 
const URL_TYPE_STATIC = 'static'
 
const URL_TYPE_JS = 'js'
 
const DEFAULT_URL_TYPE = 'link'
 
const DEFAULT_CONTROLLER_NAME = 'index'
 
const DEFAULT_ACTION_NAME = 'index'
 
const REWRITE_REQUEST_PATH_ALIAS = 'rewrite_request_path'
 
const SESSION_NAMESPACE = 'frontend'
 

Detailed Description

URL

Properties:

@codingStandardsIgnoreStart URL structure:

https://user:password@host:443/base_path/[base_script][scopeview_path]route_name/controller_name/action_name/param1/value1?query_param=query_value::fragment __________A___________/____________________________________B_____________________________________/ __________________C___________________/ __________________D_________________/ _____E_____/ _____________F______________/ ___________________________G______________________/ ___________________________________________________H____________________________________________________/ @codingStandardsIgnoreEnd

Definition at line 66 of file Url.php.

Constructor & Destructor Documentation

◆ __construct()

__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 
)
Parameters
\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
string$scopeType
array$data
HostChecker | null$hostChecker
Json | null$serializer@SuppressWarnings(PHPMD.ExcessiveParameterList)

Definition at line 213 of file Url.php.

228  {
229  $this->_request = $request;
230  $this->_routeConfig = $routeConfig;
231  $this->_urlSecurityInfo = $urlSecurityInfo;
232  $this->_scopeResolver = $scopeResolver;
233  $this->_session = $session;
234  $this->_sidResolver = $sidResolver;
235  $this->_routeParamsResolverFactory = $routeParamsResolverFactory;
236  $this->_queryParamsResolver = $queryParamsResolver;
237  $this->_scopeConfig = $scopeConfig;
238  $this->routeParamsPreprocessor = $routeParamsPreprocessor;
239  $this->_scopeType = $scopeType;
240  $this->hostChecker = $hostChecker ?: \Magento\Framework\App\ObjectManager::getInstance()
241  ->get(HostChecker::class);
242  $this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class);
243  parent::__construct($data);
244  }

Member Function Documentation

◆ _getActionName()

_getActionName (   $default = null)
protected

Retrieve action name

Parameters
mixed$default
Returns
string|null

Definition at line 701 of file Url.php.

702  {
703  return $this->_getData('action_name') ? $this->_getData('action_name') : $default;
704  }

◆ _getActionPath()

_getActionPath ( )
protected

Retrieve action path

Returns
string

Definition at line 549 of file Url.php.

550  {
551  if (!$this->_getRouteName()) {
552  return '';
553  }
554 
555  $hasParams = (bool) $this->_getRouteParams();
556  $path = $this->_getRouteFrontName() . '/';
557 
558  if ($this->_getControllerName()) {
559  $path .= $this->_getControllerName() . '/';
560  } elseif ($hasParams) {
561  $path .= self::DEFAULT_CONTROLLER_NAME . '/';
562  }
563  if ($this->_getActionName()) {
564  $path .= $this->_getActionName() . '/';
565  } elseif ($hasParams) {
566  $path .= self::DEFAULT_ACTION_NAME . '/';
567  }
568 
569  return $path;
570  }
_getActionName($default=null)
Definition: Url.php:701
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
_getRouteName($default=null)
Definition: Url.php:643
_getControllerName($default=null)
Definition: Url.php:672

◆ _getConfig()

_getConfig (   $path)
protected

Get config data by path

Parameters
string$path
Returns
null|string

Definition at line 340 of file Url.php.

341  {
342  return $this->_scopeConfig->getValue(
343  $path,
344  $this->_scopeType,
345  $this->_getScope()
346  );
347  }

◆ _getConfigCacheId()

_getConfigCacheId (   $path)
protected

Get cache id for config path

Parameters
string$path
Returns
string

Definition at line 329 of file Url.php.

330  {
331  return $this->_getScope()->getCode() . '/' . $path;
332  }

◆ _getControllerName()

_getControllerName (   $default = null)
protected

Retrieve controller name

Parameters
mixed$default
Returns
string|null

Definition at line 672 of file Url.php.

673  {
674  return $this->_getData('controller_name') ? $this->_getData('controller_name') : $default;
675  }

◆ _getFragment()

_getFragment ( )
protected

Retrieve URL fragment

Returns
string|null

Definition at line 825 of file Url.php.

826  {
827  return $this->_getData('fragment');
828  }

◆ _getQuery()

_getQuery (   $escape = false)
protected

Get query params part of url

Parameters
bool$escape"&" escape flag
Returns
string

Definition at line 790 of file Url.php.

791  {
792  return $this->_queryParamsResolver->getQuery($escape);
793  }

◆ _getRequest()

_getRequest ( )
protected

Zend request object

Returns
\Magento\Framework\App\RequestInterface

Definition at line 366 of file Url.php.

367  {
368  return $this->_request;
369  }

◆ _getRouteFrontName()

_getRouteFrontName ( )
protected

Retrieve route front name

Returns
string

Definition at line 625 of file Url.php.

626  {
627  if (!$this->hasData('route_front_name')) {
628  $frontName = $this->_routeConfig->getRouteFrontName(
629  $this->_getRouteName(),
630  $this->_scopeResolver->getAreaCode()
631  );
632  $this->setData('route_front_name', $frontName);
633  }
634  return $this->_getData('route_front_name');
635  }
_getRouteName($default=null)
Definition: Url.php:643
setData($key, $value=null)
Definition: DataObject.php:72

◆ _getRouteName()

_getRouteName (   $default = null)
protected

Retrieve route name

Parameters
mixed$default
Returns
string|null

Definition at line 643 of file Url.php.

644  {
645  return $this->_getData('route_name') ? $this->_getData('route_name') : $default;
646  }

◆ _getRouteParams()

_getRouteParams ( )
protected

Retrieve route params

Returns
array

Definition at line 724 of file Url.php.

725  {
726  return $this->getRouteParamsResolver()->getRouteParams();
727  }

◆ _getRoutePath()

_getRoutePath (   $routeParams = [])
protected

Retrieve route path

Parameters
array$routeParams
Returns
string @SuppressWarnings(PHPMD.CyclomaticComplexity)

Definition at line 579 of file Url.php.

580  {
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);
585  return $routePath;
586  }
587  $routePath = $this->_getActionPath();
588  if ($this->_getRouteParams()) {
589  foreach ($this->_getRouteParams() as $key => $value) {
590  if ($value === null || false === $value || '' === $value || !is_scalar($value)) {
591  continue;
592  }
593  $routePath .= $key . '/' . $value . '/';
594  }
595  }
596  $this->setData('route_path', $routePath);
597  }
598  return $this->_getData('route_path');
599  }
$value
Definition: gender.phtml:16
setData($key, $value=null)
Definition: DataObject.php:72

◆ _getScope()

_getScope ( )
protected

Get current scope for the url instance

Returns
\Magento\Framework\Url\ScopeInterface

Definition at line 439 of file Url.php.

440  {
441  if (!$this->hasData('scope')) {
442  $this->setScope(null);
443  }
444  return $this->_getData('scope');
445  }
setScope($params)
Definition: Url.php:427

◆ _getType()

_getType ( )
protected

Retrieve URL type

Returns
string

Definition at line 376 of file Url.php.

377  {
378  if (!$this->getRouteParamsResolver()->hasData('type')) {
379  $this->getRouteParamsResolver()->setData('type', self::DEFAULT_URL_TYPE);
380  }
381  return $this->getRouteParamsResolver()->getType();
382  }

◆ _isSecure()

_isSecure ( )
protected

Retrieve is secure mode URL

Returns
bool

Definition at line 389 of file Url.php.

390  {
391  if ($this->_request->isSecure()) {
392  if ($this->getRouteParamsResolver()->hasData('secure')) {
393  return (bool) $this->getRouteParamsResolver()->getData('secure');
394  }
395  return true;
396  }
397 
398  if ($this->getRouteParamsResolver()->hasData('secure_is_forced')) {
399  return (bool) $this->getRouteParamsResolver()->getData('secure');
400  }
401 
402  if (!$this->_getScope()->isUrlSecure()) {
403  return false;
404  }
405 
406  if (!$this->getRouteParamsResolver()->hasData('secure')) {
407  if ($this->_getType() == UrlInterface::URL_TYPE_LINK) {
408  $pathSecure = $this->_urlSecurityInfo->isSecure('/' . $this->_getActionPath());
409  $this->getRouteParamsResolver()->setData('secure', $pathSecure);
411  $isRequestSecure = $this->_getRequest()->isSecure();
412  $this->getRouteParamsResolver()->setData('secure', $isRequestSecure);
413  } else {
414  $this->getRouteParamsResolver()->setData('secure', true);
415  }
416  }
417 
418  return $this->getRouteParamsResolver()->getData('secure');
419  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17

◆ _parseUrl()

_parseUrl (   $url)
protected

Initialize object data from retrieved url

Parameters
string$url
Returns
\Magento\Framework\UrlInterface

Definition at line 252 of file Url.php.

253  {
254  $data = parse_url($url);
255  $parts = [
256  'scheme' => 'setScheme',
257  'host' => 'setHost',
258  'port' => 'setPort',
259  'user' => 'setUser',
260  'pass' => 'setPassword',
261  'path' => 'setPath',
262  'query' => '_setQuery',
263  'fragment' => 'setFragment',
264  ];
265 
266  foreach ($parts as $component => $method) {
267  if (isset($data[$component])) {
268  $this->{$method}($data[$component]);
269  }
270  }
271  return $this;
272  }
$method
Definition: info.phtml:13

◆ _prepareSessionUrl()

_prepareSessionUrl (   $url)
protected

Check and add session id to URL

Parameters
string$url
Returns
\Magento\Framework\UrlInterface

Definition at line 976 of file Url.php.

977  {
978  if (!$this->getUseSession()) {
979  return $this;
980  }
981  $sessionId = $this->_session->getSessionIdForHost($url);
982  if ($this->_sidResolver->getUseSessionVar() && !$sessionId) {
983  $this->setQueryParam('___SID', $this->_isSecure() ? 'S' : 'U');
984  } elseif ($sessionId) {
985  $this->setQueryParam($this->_sidResolver->getSessionIdQueryParam($this->_session), $sessionId);
986  }
987  return $this;
988  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
setQueryParam($key, $data)
Definition: Url.php:814

◆ _setActionName()

_setActionName (   $data)
protected

Set Action name Reseted route path if action name has change

Parameters
string$data
Returns
\Magento\Framework\UrlInterface

Definition at line 684 of file Url.php.

685  {
686  if ($this->_getData('action_name') == $data) {
687  return $this;
688  }
689  $this->unsetData('route_path');
690  $this->setData('action_name', $data);
691  $this->_queryParamsResolver->unsetData('secure');
692  return $this;
693  }
setData($key, $value=null)
Definition: DataObject.php:72

◆ _setControllerName()

_setControllerName (   $data)
protected

Set Controller Name

Reset action name and route path if has change

Parameters
string$data
Returns
\Magento\Framework\UrlInterface

Definition at line 656 of file Url.php.

657  {
658  if ($this->_getData('controller_name') == $data) {
659  return $this;
660  }
661  $this->unsetData('route_path')->unsetData('action_name');
662  $this->_queryParamsResolver->unsetData('secure');
663  return $this->setData('controller_name', $data);
664  }
setData($key, $value=null)
Definition: DataObject.php:72

◆ _setQuery()

_setQuery (   $data)
protected

Set URL query param(s)

Parameters
mixed$data
Returns
\Magento\Framework\UrlInterface

Definition at line 779 of file Url.php.

780  {
781  return $this->_queryParamsResolver->setQuery($data);
782  }

◆ _setRouteName()

_setRouteName (   $data)
protected

Set route name

Parameters
string$data
Returns
\Magento\Framework\UrlInterface

Definition at line 607 of file Url.php.

608  {
609  if ($this->_getData('route_name') == $data) {
610  return $this;
611  }
612  $this->unsetData('route_front_name')
613  ->unsetData('route_path')
614  ->unsetData('controller_name')
615  ->unsetData('action_name');
616  $this->_queryParamsResolver->unsetData('secure');
617  return $this->setData('route_name', $data);
618  }
setData($key, $value=null)
Definition: DataObject.php:72

◆ _setRouteParams()

_setRouteParams ( array  $data,
  $unsetOldParams = true 
)
protected

Set route params

Parameters
array$data
boolean$unsetOldParams
Returns
\Magento\Framework\UrlInterface

Definition at line 713 of file Url.php.

714  {
715  $this->getRouteParamsResolver()->setRouteParams($data, $unsetOldParams);
716  return $this;
717  }

◆ _setRoutePath()

_setRoutePath (   $data)
protected

Set Route Parameters

Parameters
string$data
Returns
\Magento\Framework\UrlInterface @SuppressWarnings(PHPMD.CyclomaticComplexity)

Definition at line 498 of file Url.php.

499  {
500  if ($this->_getData('route_path') == $data) {
501  return $this;
502  }
503 
504  $this->unsetData('route_path');
505  $routePieces = explode('/', $data);
506 
507  $route = array_shift($routePieces);
508  if ('*' === $route) {
509  $route = $this->_getRequest()->getRouteName();
510  }
511  $this->_setRouteName($route);
512 
513  $controller = '';
514  if (!empty($routePieces)) {
515  $controller = array_shift($routePieces);
516  if ('*' === $controller) {
517  $controller = $this->_getRequest()->getControllerName();
518  }
519  }
521 
522  $action = '';
523  if (!empty($routePieces)) {
524  $action = array_shift($routePieces);
525  if ('*' === $action) {
526  $action = $this->_getRequest()->getActionName();
527  }
528  }
529  $this->_setActionName($action);
530 
531  if (!empty($routePieces)) {
532  while (!empty($routePieces)) {
533  $key = array_shift($routePieces);
534  if (!empty($routePieces)) {
535  $value = array_shift($routePieces);
536  $this->getRouteParamsResolver()->setRouteParam($key, $value);
537  }
538  }
539  }
540 
541  return $this;
542  }
$value
Definition: gender.phtml:16
_setControllerName($data)
Definition: Url.php:656
_setRouteName($data)
Definition: Url.php:607
_setActionName($data)
Definition: Url.php:684
$controller
Definition: info.phtml:14

◆ addQueryParams()

addQueryParams ( array  $data)

Add query Params as array

Parameters
array$data
Returns
\Magento\Framework\UrlInterface

Implements UrlInterface.

Definition at line 801 of file Url.php.

802  {
803  $this->_queryParamsResolver->addQueryParams($data);
804  return $this;
805  }

◆ addSessionParam()

addSessionParam ( )

Add session param

Returns
\Magento\Framework\UrlInterface

Implements UrlInterface.

Definition at line 764 of file Url.php.

765  {
766  $this->setQueryParam(
767  $this->_sidResolver->getSessionIdQueryParam($this->_session),
768  $this->_session->getSessionId()
769  );
770  return $this;
771  }
setQueryParam($key, $data)
Definition: Url.php:814

◆ escape()

escape (   $value)

Escape (enclosure) URL string

Parameters
string$value
Returns
string
Deprecated:
101.0.0

Implements UrlInterface.

Definition at line 1029 of file Url.php.

1030  {
1031  $value = str_replace('"', '%22', $value);
1032  $value = str_replace("'", '%27', $value);
1033  $value = str_replace('>', '%3E', $value);
1034  $value = str_replace('<', '%3C', $value);
1035  return $value;
1036  }
$value
Definition: gender.phtml:16

◆ getBaseUrl()

getBaseUrl (   $params = [])

Retrieve Base URL

Parameters
array$params
Returns
string

Original Scope

Add availability support urls without scope code

Implements UrlInterface.

Definition at line 453 of file Url.php.

454  {
458  $origScope = $this->_getScope();
459 
460  if (isset($params['_scope'])) {
461  $this->setScope($params['_scope']);
462  }
463  if (isset($params['_type'])) {
464  $this->getRouteParamsResolver()->setType($params['_type']);
465  }
466 
467  if (isset($params['_secure'])) {
468  $this->getRouteParamsResolver()->setSecure($params['_secure']);
469  }
470 
474  if ($this->_getType() == UrlInterface::URL_TYPE_LINK
475  && $this->_getRequest()->isDirectAccessFrontendName(
476  $this->_getRouteFrontName()
477  )
478  ) {
480  }
481 
482  $result = $this->_getScope()->getBaseUrl($this->_getType(), $this->_isSecure());
483 
484  // setting back the original scope
485  $this->setScope($origScope);
486  $this->getRouteParamsResolver()->setType(self::DEFAULT_URL_TYPE);
487 
488  return $result;
489  }
setScope($params)
Definition: Url.php:427
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

◆ getConfigData()

getConfigData (   $key,
  $prefix = null 
)

Retrieve configuration data

Parameters
string$key
string | null$prefix
Returns
string

Definition at line 307 of file Url.php.

308  {
309  if ($prefix === null) {
310  $prefix = 'web/' . ($this->_isSecure() ? 'secure' : 'unsecure') . '/';
311  }
312  $path = $prefix . $key;
313 
314  $cacheId = $this->_getConfigCacheId($path);
315  if (!isset(self::$_configDataCache[$cacheId])) {
316  $data = $this->_getConfig($path);
317  self::$_configDataCache[$cacheId] = $data;
318  }
319 
320  return self::$_configDataCache[$cacheId];
321  }
_getConfigCacheId($path)
Definition: Url.php:329
$prefix
Definition: name.phtml:25
_getConfig($path)
Definition: Url.php:340

◆ getCurrentUrl()

getCurrentUrl ( )

Retrieve current url

Returns
string

Custom port

Implements UrlInterface.

Definition at line 1143 of file Url.php.

1144  {
1145  $httpHostWithPort = $this->_request->getHttpHost(false);
1146  $httpHostWithPort = explode(':', $httpHostWithPort);
1147  $httpHost = isset($httpHostWithPort[0]) ? $httpHostWithPort[0] : '';
1148  $port = '';
1149  if (isset($httpHostWithPort[1])) {
1150  $defaultPorts = [
1153  ];
1154  if (!in_array($httpHostWithPort[1], $defaultPorts)) {
1156  $port = ':' . $httpHostWithPort[1];
1157  }
1158  }
1159  return $this->_request->getScheme() . '://' . $httpHost . $port . $this->_request->getRequestUri();
1160  }

◆ getDirectUrl()

getDirectUrl (   $url,
  $params = [] 
)

Build url by direct url and parameters

Parameters
string$url
array$params
Returns
string

Implements UrlInterface.

Definition at line 1045 of file Url.php.

1046  {
1047  $params['_direct'] = $url;
1048  return $this->getUrl('', $params);
1049  }
getUrl($routePath=null, $routeParams=null)
Definition: Url.php:839
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

◆ getRebuiltUrl()

getRebuiltUrl (   $url)

Rebuild URL to handle the case when session ID was changed

Parameters
string$url
Returns
string

Definition at line 996 of file Url.php.

997  {
998  $this->_parseUrl($url);
999  $port = $this->getPort();
1000  if ($port) {
1001  $port = ':' . $port;
1002  } else {
1003  $port = '';
1004  }
1005  $url = $this->getScheme() . '://' . $this->getHost() . $port . $this->getPath();
1006 
1007  $this->_prepareSessionUrl($url);
1008 
1009  $query = $this->_getQuery();
1010  if ($query) {
1011  $url .= '?' . $query;
1012  }
1013 
1014  $fragment = $this->_getFragment();
1015  if ($fragment) {
1016  $url .= '#' . $this->getEscaper()->encodeUrlParam($fragment);
1017  }
1018 
1019  return $url;
1020  }
_prepareSessionUrl($url)
Definition: Url.php:976
_getQuery($escape=false)
Definition: Url.php:790

◆ getRedirectUrl()

getRedirectUrl (   $url)

Return frontend redirect URL with SID and other session parameters if any

Parameters
string$url
Returns
string

Implements UrlInterface.

Definition at line 1127 of file Url.php.

1128  {
1129  $this->_prepareSessionUrl($url);
1130  $query = $this->_getQuery(false);
1131  if ($query) {
1132  $url .= (strpos($url, '?') === false ? '?' : '&') . $query;
1133  }
1134 
1135  return $url;
1136  }
_prepareSessionUrl($url)
Definition: Url.php:976
_getQuery($escape=false)
Definition: Url.php:790

◆ getRouteParamsResolver()

getRouteParamsResolver ( )
protected

Get Route Params Resolver

Returns
Url\RouteParamsResolverInterface

Definition at line 1167 of file Url.php.

1168  {
1169  if (!$this->_routeParamsResolver) {
1170  $this->_routeParamsResolver = $this->_routeParamsResolverFactory->create();
1171  }
1172  return $this->_routeParamsResolver;
1173  }

◆ getRouteUrl()

getRouteUrl (   $routePath = null,
  $routeParams = null 
)

Retrieve route URL

Parameters
string$routePath
array$routeParams
Returns
string

Implements UrlInterface.

Definition at line 736 of file Url.php.

737  {
738  if (filter_var($routePath, FILTER_VALIDATE_URL)) {
739  return $routePath;
740  }
741 
742  $this->getRouteParamsResolver()->unsetData('route_params');
743 
744  if (isset($routeParams['_direct'])) {
745  if (is_array($routeParams)) {
746  $this->_setRouteParams($routeParams, false);
747  }
748  return $this->getBaseUrl() . $routeParams['_direct'];
749  }
750 
751  $this->_setRoutePath($routePath);
752  if (is_array($routeParams)) {
753  $this->_setRouteParams($routeParams, false);
754  }
755 
756  return $this->getBaseUrl($routeParams) . $this->_getRoutePath($routeParams);
757  }
_setRoutePath($data)
Definition: Url.php:498
_setRouteParams(array $data, $unsetOldParams=true)
Definition: Url.php:713
getBaseUrl($params=[])
Definition: Url.php:453
_getRoutePath($routeParams=[])
Definition: Url.php:579

◆ getUrl()

getUrl (   $routePath = null,
  $routeParams = null 
)

Build and cache url by requested path and parameters

Parameters
string | null$routePath
array | null$routeParams
Returns
string @SuppressWarnings(PHPMD.CyclomaticComplexity) @SuppressWarnings(PHPMD.NPathComplexity)

Implements UrlInterface.

Definition at line 839 of file Url.php.

840  {
841  if (filter_var($routePath, FILTER_VALIDATE_URL)) {
842  return $routePath;
843  }
844 
845  $routeParams = $this->routeParamsPreprocessor
846  ->execute($this->_scopeResolver->getAreaCode(), $routePath, $routeParams);
847 
848  $isCached = true;
849  $isArray = is_array($routeParams);
850 
851  if ($isArray) {
852  array_walk_recursive(
853  $routeParams,
854  function ($item) use (&$isCached) {
855  if (is_object($item)) {
856  $isCached = false;
857  }
858  }
859  );
860  }
861 
862  if (!$isCached) {
863  return $this->getUrlModifier()->execute(
864  $this->createUrl($routePath, $routeParams)
865  );
866  }
867 
868  $cachedParams = $routeParams;
869  if ($isArray) {
870  ksort($cachedParams);
871  }
872 
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)
877  );
878  }
879 
880  return $this->cacheUrl[$cacheKey];
881  }

◆ getUseSession()

getUseSession ( )

Retrieve use session rule

Returns
bool @SuppressWarnings(PHPMD.BooleanGetMethodName)

Implements UrlInterface.

Definition at line 292 of file Url.php.

293  {
294  if ($this->_useSession === null) {
295  $this->_useSession = $this->_sidResolver->getUseSessionInUrl();
296  }
297  return $this->_useSession;
298  }

◆ isOwnOriginUrl()

isOwnOriginUrl ( )

Check if users originated URL is one of the domain URLs assigned to scopes

Returns
boolean

Implements UrlInterface.

Definition at line 1115 of file Url.php.

1116  {
1117  return $this->hostChecker->isOwnOrigin($this->_request->getServer('HTTP_REFERER'));
1118  }

◆ sessionUrlVar()

sessionUrlVar (   $html)

Replace Session ID value in URL

Parameters
string$html
Returns
string

Callback function for session replace

Parameters
array$match
Returns
string

Implements UrlInterface.

Definition at line 1057 of file Url.php.

1058  {
1059  return preg_replace_callback(
1060  '#(\?|&amp;|&)___SID=([SU])(&amp;|&)?#',
1061  // @codingStandardsIgnoreStart
1068  // @codingStandardsIgnoreEnd
1069  function ($match) {
1070  if ($this->useSessionIdForUrl($match[2] == 'S' ? true : false)) {
1071  return $match[1] . $this->_sidResolver->getSessionIdQueryParam($this->_session) . '='
1072  . $this->_session->getSessionId() . (isset($match[3]) ? $match[3] : '');
1073  } else {
1074  if ($match[1] == '?') {
1075  return isset($match[3]) ? '?' : '';
1076  } elseif ($match[1] == '&amp;' || $match[1] == '&') {
1077  return $match[3] ?? '';
1078  }
1079  }
1080  },
1081  $html
1082  );
1083  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
useSessionIdForUrl($secure=false)
Definition: Url.php:1091

◆ setQueryParam()

setQueryParam (   $key,
  $data 
)

Set query param

Parameters
string$key
mixed$data
Returns
\Magento\Framework\UrlInterface

Implements UrlInterface.

Definition at line 814 of file Url.php.

815  {
816  $this->_queryParamsResolver->setQueryParam($key, $data);
817  return $this;
818  }

◆ setRequest()

setRequest ( \Magento\Framework\App\RequestInterface  $request)

Set request

Parameters
\Magento\Framework\App\RequestInterface$request
Returns
\Magento\Framework\UrlInterface

Definition at line 355 of file Url.php.

356  {
357  $this->_request = $request;
358  return $this;
359  }

◆ setScope()

setScope (   $params)

Set scope entity

Parameters
mixed$params
Returns
\Magento\Framework\UrlInterface

Implements UrlInterface.

Definition at line 427 of file Url.php.

428  {
429  $this->setData('scope', $this->_scopeResolver->getScope($params));
430  $this->getRouteParamsResolver()->setScope($this->_scopeResolver->getScope($params));
431  return $this;
432  }
setData($key, $value=null)
Definition: DataObject.php:72
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

◆ setUseSession()

setUseSession (   $useSession)

Set use session rule

Parameters
bool$useSession
Returns
\Magento\Framework\UrlInterface

Definition at line 280 of file Url.php.

281  {
282  $this->_useSession = (bool) $useSession;
283  return $this;
284  }

◆ useSessionIdForUrl()

useSessionIdForUrl (   $secure = false)

Check and return use SID for URL

Parameters
bool$secure
Returns
bool

Definition at line 1091 of file Url.php.

1092  {
1093  $key = 'use_session_id_for_url_' . (int)$secure;
1094  if ($this->getData($key) === null) {
1095  $httpHost = $this->_request->getHttpHost();
1096  $urlHost = parse_url(
1097  $this->_getScope()->getBaseUrl(UrlInterface::URL_TYPE_LINK, $secure),
1098  PHP_URL_HOST
1099  );
1100 
1101  if ($httpHost != $urlHost) {
1102  $this->setData($key, true);
1103  } else {
1104  $this->setData($key, false);
1105  }
1106  }
1107  return $this->getData($key);
1108  }
getData($key='', $index=null)
Definition: DataObject.php:119
getBaseUrl($params=[])
Definition: Url.php:453
setData($key, $value=null)
Definition: DataObject.php:72

Field Documentation

◆ $_configDataCache

$_configDataCache
staticprotected

Definition at line 73 of file Url.php.

◆ $_queryParamsResolver

$_queryParamsResolver
protected

Definition at line 157 of file Url.php.

◆ $_request

$_request
protected

Definition at line 106 of file Url.php.

◆ $_reservedRouteParams

$_reservedRouteParams
protected
Initial value:
= [
'_scope',
'_type',
'_secure',
'_forced_secure',
'_use_rewrite',
'_nosid',
'_absolute',
'_current',
'_direct',
'_fragment',
'_escape',
'_query',
'_scope_to_url',
]

Definition at line 80 of file Url.php.

◆ $_routeConfig

$_routeConfig
protected

Definition at line 137 of file Url.php.

◆ $_scopeConfig

$_scopeConfig
protected

Definition at line 169 of file Url.php.

◆ $_scopeResolver

$_scopeResolver
protected

Definition at line 152 of file Url.php.

◆ $_scopeType

$_scopeType
protected

Definition at line 99 of file Url.php.

◆ $_session

$_session
protected

Definition at line 125 of file Url.php.

◆ $_sidResolver

$_sidResolver
protected

Definition at line 130 of file Url.php.

◆ $_urlSecurityInfo

$_urlSecurityInfo
protected

Definition at line 120 of file Url.php.

◆ $_useSession

$_useSession
protected

Definition at line 113 of file Url.php.

◆ $routeParamsPreprocessor

$routeParamsPreprocessor
protected

Definition at line 174 of file Url.php.


The documentation for this class was generated from the following file: