Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Url.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Customer\Model;
7 
13 
17 class Url
18 {
22  const ROUTE_ACCOUNT_LOGIN = 'customer/account/login';
23 
27  const XML_PATH_CUSTOMER_STARTUP_REDIRECT_TO_DASHBOARD = 'customer/startup/redirect_dashboard';
28 
32  const REFERER_QUERY_PARAM_NAME = 'referer';
33 
37  protected $urlBuilder;
38 
42  protected $request;
43 
47  protected $scopeConfig;
48 
52  protected $customerSession;
53 
57  protected $urlEncoder;
58 
62  private $urlDecoder;
63 
67  private $hostChecker;
68 
78  public function __construct(
84  \Magento\Framework\Url\DecoderInterface $urlDecoder = null,
85  \Magento\Framework\Url\HostChecker $hostChecker = null
86  ) {
87  $this->request = $request;
88  $this->urlBuilder = $urlBuilder;
89  $this->scopeConfig = $scopeConfig;
90  $this->customerSession = $customerSession;
91  $this->urlEncoder = $urlEncoder;
92  $this->urlDecoder = $urlDecoder ?: \Magento\Framework\App\ObjectManager::getInstance()
93  ->get(\Magento\Framework\Url\DecoderInterface::class);
94  $this->hostChecker = $hostChecker ?: \Magento\Framework\App\ObjectManager::getInstance()
95  ->get(\Magento\Framework\Url\HostChecker::class);
96  }
97 
103  public function getLoginUrl()
104  {
105  return $this->urlBuilder->getUrl(self::ROUTE_ACCOUNT_LOGIN, $this->getLoginUrlParams());
106  }
107 
113  public function getLoginUrlParams()
114  {
115  $params = [];
116  $referer = $this->getRequestReferrer();
117  if (!$referer
118  && !$this->scopeConfig->isSetFlag(
119  self::XML_PATH_CUSTOMER_STARTUP_REDIRECT_TO_DASHBOARD,
120  ScopeInterface::SCOPE_STORE
121  )
122  && !$this->customerSession->getNoReferer()
123  ) {
124  $referer = $this->urlBuilder->getUrl('*/*/*', ['_current' => true, '_use_rewrite' => true]);
125  $referer = $this->urlEncoder->encode($referer);
126  }
127 
128  if ($referer) {
129  $params = [self::REFERER_QUERY_PARAM_NAME => $referer];
130  }
131 
132  return $params;
133  }
134 
140  public function getLoginPostUrl()
141  {
142  $params = [];
143  $referer = $this->getRequestReferrer();
144  if ($referer) {
145  $params = [
146  self::REFERER_QUERY_PARAM_NAME => $referer,
147  ];
148  }
149  return $this->urlBuilder->getUrl('customer/account/loginPost', $params);
150  }
151 
157  public function getLogoutUrl()
158  {
159  return $this->urlBuilder->getUrl('customer/account/logout');
160  }
161 
167  public function getDashboardUrl()
168  {
169  return $this->urlBuilder->getUrl('customer/account');
170  }
171 
177  public function getAccountUrl()
178  {
179  return $this->urlBuilder->getUrl('customer/account');
180  }
181 
187  public function getRegisterUrl()
188  {
189  return $this->urlBuilder->getUrl('customer/account/create');
190  }
191 
197  public function getRegisterPostUrl()
198  {
199  return $this->urlBuilder->getUrl('customer/account/createpost');
200  }
201 
207  public function getEditUrl()
208  {
209  return $this->urlBuilder->getUrl('customer/account/edit');
210  }
211 
217  public function getEditPostUrl()
218  {
219  return $this->urlBuilder->getUrl('customer/account/editpost');
220  }
221 
227  public function getForgotPasswordUrl()
228  {
229  return $this->urlBuilder->getUrl('customer/account/forgotpassword');
230  }
231 
238  public function getEmailConfirmationUrl($email = null)
239  {
240  return $this->urlBuilder->getUrl('customer/account/confirmation', ['_query' => ['email' => $email]]);
241  }
242 
246  private function getRequestReferrer()
247  {
248  $referer = $this->request->getParam(self::REFERER_QUERY_PARAM_NAME);
249  if ($referer && $this->hostChecker->isOwnOrigin($this->urlDecoder->decode($referer))) {
250  return $referer;
251  }
252  return null;
253  }
254 }
$email
Definition: details.phtml:13
getEmailConfirmationUrl($email=null)
Definition: Url.php:238
const XML_PATH_CUSTOMER_STARTUP_REDIRECT_TO_DASHBOARD
Definition: Url.php:27
const REFERER_QUERY_PARAM_NAME
Definition: Url.php:32
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18
__construct(Session $customerSession, ScopeConfigInterface $scopeConfig, RequestInterface $request, UrlInterface $urlBuilder, EncoderInterface $urlEncoder, \Magento\Framework\Url\DecoderInterface $urlDecoder=null, \Magento\Framework\Url\HostChecker $hostChecker=null)
Definition: Url.php:78