Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Data.php
Go to the documentation of this file.
1 <?php
13 
15 {
21  public function getCurrentBase64Url()
22  {
23  return $this->urlEncoder->encode($this->_urlBuilder->getCurrentUrl());
24  }
25 
30  public function getEncodedUrl($url = null)
31  {
32  if (!$url) {
33  $url = $this->_urlBuilder->getCurrentUrl();
34  }
35  return $this->urlEncoder->encode($url);
36  }
37 
45  public function addRequestParam($url, $param)
46  {
47  $startDelimiter = false === strpos($url, '?') ? '?' : '&';
48 
49  $arrQueryParams = [];
50  foreach ($param as $key => $value) {
51  if (is_numeric($key) || is_object($value)) {
52  continue;
53  }
54 
55  if (is_array($value)) {
56  // $key[]=$value1&$key[]=$value2 ...
57  $arrQueryParams[] = $key . '[]=' . implode('&' . $key . '[]=', $value);
58  } elseif ($value === null) {
59  $arrQueryParams[] = $key;
60  } else {
61  $arrQueryParams[] = $key . '=' . $value;
62  }
63  }
64  if (!empty($arrQueryParams)) {
65  $url .= $startDelimiter . implode('&', $arrQueryParams);
66  }
67 
68  return $url;
69  }
70 
78  public function removeRequestParam($url, $paramKey, $caseSensitive = false)
79  {
80  $regExpression = '/\\?[^#]*?(' . preg_quote($paramKey, '/') . '\\=[^#&]*&?)/' . ($caseSensitive ? '' : 'i');
81  while (preg_match($regExpression, $url, $matches) !== 0) {
82  $paramString = $matches[1];
83  // if ampersand is at the end of $paramString
84  if (substr($paramString, -1, 1) != '&') {
85  $url = preg_replace('/(&|\\?)?' . preg_quote($paramString, '/') . '/', '', $url);
86  } else {
87  $url = str_replace($paramString, '', $url);
88  }
89  }
90  return $url;
91  }
92 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$value
Definition: gender.phtml:16
addRequestParam($url, $param)
Definition: Data.php:45
removeRequestParam($url, $paramKey, $caseSensitive=false)
Definition: Data.php:78