123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Framework\Url;
- class QueryParamsResolver extends \Magento\Framework\DataObject implements QueryParamsResolverInterface
- {
- /**
- * {@inheritdoc}
- */
- public function getQuery($escape = false)
- {
- if (!$this->hasData('query')) {
- $query = '';
- $params = $this->getQueryParams();
- if (is_array($params)) {
- ksort($params);
- $query = http_build_query($params, '', $escape ? '&' : '&');
- }
- $this->setData('query', $query);
- }
- return $this->_getData('query');
- }
- /**
- * {@inheritdoc}
- */
- public function setQuery($data)
- {
- if ($this->_getData('query') !== $data) {
- $this->unsetData('query_params');
- $this->setData('query', $data);
- }
- return $this;
- }
- /**
- * {@inheritdoc}
- */
- public function setQueryParam($key, $data)
- {
- $params = $this->getQueryParams();
- if (isset($params[$key]) && $params[$key] == $data) {
- return $this;
- }
- $params[$key] = $data;
- $this->unsetData('query');
- $this->setData('query_params', $params);
- return $this;
- }
- /**
- * {@inheritdoc}
- */
- public function getQueryParams()
- {
- if (!$this->hasData('query_params')) {
- $params = [];
- if ($this->_getData('query')) {
- foreach (explode('&', $this->_getData('query')) as $param) {
- $paramArr = explode('=', $param);
- $params[$paramArr[0]] = urldecode($paramArr[1]);
- }
- }
- $this->setData('query_params', $params);
- }
- return $this->_getData('query_params');
- }
- /**
- * {@inheritdoc}
- */
- public function setQueryParams(array $data)
- {
- return $this->setData('query_params', $data);
- }
- /**
- * {@inheritdoc}
- */
- public function addQueryParams(array $data)
- {
- $this->unsetData('query');
- if ($this->_getData('query_params') == $data) {
- return $this;
- }
- $params = $this->_getData('query_params');
- if (!is_array($params)) {
- $params = [];
- }
- foreach ($data as $param => $value) {
- $params[$param] = $value;
- }
- $this->setData('query_params', $params);
- return $this;
- }
- }
|