Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
QueryParamsResolver.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Framework\Url;
7 
9 {
13  public function getQuery($escape = false)
14  {
15  if (!$this->hasData('query')) {
16  $query = '';
17  $params = $this->getQueryParams();
18  if (is_array($params)) {
19  ksort($params);
20  $query = http_build_query($params, '', $escape ? '&amp;' : '&');
21  }
22  $this->setData('query', $query);
23  }
24  return $this->_getData('query');
25  }
26 
30  public function setQuery($data)
31  {
32  if ($this->_getData('query') !== $data) {
33  $this->unsetData('query_params');
34  $this->setData('query', $data);
35  }
36  return $this;
37  }
38 
42  public function setQueryParam($key, $data)
43  {
44  $params = $this->getQueryParams();
45  if (isset($params[$key]) && $params[$key] == $data) {
46  return $this;
47  }
48  $params[$key] = $data;
49  $this->unsetData('query');
50  $this->setData('query_params', $params);
51  return $this;
52  }
53 
57  public function getQueryParams()
58  {
59  if (!$this->hasData('query_params')) {
60  $params = [];
61  if ($this->_getData('query')) {
62  foreach (explode('&', $this->_getData('query')) as $param) {
63  $paramArr = explode('=', $param);
64  $params[$paramArr[0]] = urldecode($paramArr[1]);
65  }
66  }
67  $this->setData('query_params', $params);
68  }
69  return $this->_getData('query_params');
70  }
71 
75  public function setQueryParams(array $data)
76  {
77  return $this->setData('query_params', $data);
78  }
79 
83  public function addQueryParams(array $data)
84  {
85  $this->unsetData('query');
86 
87  if ($this->_getData('query_params') == $data) {
88  return $this;
89  }
90 
91  $params = $this->_getData('query_params');
92  if (!is_array($params)) {
93  $params = [];
94  }
95  foreach ($data as $param => $value) {
96  $params[$param] = $value;
97  }
98  $this->setData('query_params', $params);
99 
100  return $this;
101  }
102 }
$value
Definition: gender.phtml:16
setData($key, $value=null)
Definition: DataObject.php:72
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18