ZF-1480: add 3 new methods to Zend_Uri_Http

Description

  • method Zend_Uri_Http::getQueryAsArray() get the query params in an array

  • method Zend_Uri_Http::addQueryParams($params=array()) which add or replace params in the query string

  • method Zend_Uri_Http::removeQueryParams($params=array()) which remove params in the query string

 

/**
     * Returns the query portion of the URL (after ?)
     *
     * @return array
     */
    public function getQueryAsArray()
    {
        $queryParams = array();
        if($queryString = $this->getQuery()){
            $temp = explode('&', $queryString);
            foreach($temp as $param){
                list($key, $value) = explode('=', $param);
                $queryParams[$key] = $value;
            }
        }
        return $queryParams;;
    }
    
    
    /**
     * Add or replace params in the query string for the current URI, and return the old query 
     *
     * @param array $queryParams
     * @return string Old query string
     */
    public function addReplaceQuery($queryParams)
    {
        $queryParams = array_merge($this->getQueryAsArray(), $queryParams);
        return $this->setQuery($queryParams);
    }
    
    /**
     * Remove params in the query string for the current URI, and return the old query 
     *
     * @param array $queryParams
     * @return string Old query string
     */
    public function addReplaceQuery($queryParams)
    {
        $queryParams = array_diff($this->getQueryAsArray(), $queryParams);
        return $this->setQuery($queryParams);
    }

Comments

This should be discussed for post 1.0 features

Assign to Shahar.

closed in trunk (r19041).

Added

  • {{Zend_Uri_Http::getQueryAsArray()}}
  • {{Zend_Uri_Http::addReplaceQueryParameters(array $queryParams)}}
  • {{Zend_Uri_Http::removeQueryParameters(array $queryParamKeys)}}