/** * Parse a query string into a Query object. * * @param puzzle_Query $query Query object to populate * @param string $str Query string to parse * @param bool|string $urlEncoding How the query string is encoded */ public function parseInto(puzzle_Query $query, $str, $urlEncoding = true) { if ($str === '') { return; } $result = array(); $this->duplicates = false; $this->numericIndices = true; $decoder = self::getDecoder($urlEncoding); foreach (explode('&', $str) as $kvp) { $parts = explode('=', $kvp, 2); $key = call_user_func($decoder, $parts[0]); $value = isset($parts[1]) ? call_user_func($decoder, $parts[1]) : null; // Special handling needs to be taken for PHP nested array syntax if (strpos($key, '[') !== false) { $this->parsePhpValue($key, $value, $result); continue; } if (!isset($result[$key])) { $result[$key] = $value; } else { $this->duplicates = true; if (!is_array($result[$key])) { $result[$key] = array($result[$key]); } $result[$key][] = $value; } } $query->replace($result); if (!$this->numericIndices) { $query->setAggregator(puzzle_Query::phpAggregator(false)); } elseif ($this->duplicates) { $query->setAggregator(puzzle_Query::duplicateAggregator()); } }
/** * {@inheritdoc} */ public function replace(array $data) { $this->_assertNotFrozen(); $this->_delegate->replace($data); return $this; }