/** You can have this function include php field special syntax along with standard parsing. @param string string that matches form of a url query string @param specialSyntax whether to parse the string using php rules (where [] marks an array) in addition to "standard" rules */ static function parseQuery($string, $specialSyntax = false) { $parts = Tool::explode('&', $string); $array = array(); foreach ($parts as $part) { list($key, $value) = explode('=', $part); $key = urldecode($key); $value = urldecode($value); if ($specialSyntax && ($matches = self::getSpecialSyntaxKeys($key))) { if (Arrays::isElement($matches, $array)) { $currentValue = Arrays::getElement($matches, $array); if (is_array($currentValue)) { $currentValue[] = $value; } else { $currentValue = array($currentValue, $value); } Arrays::updateElement($matches, $array, $currentValue); } else { Arrays::updateElement($matches, $array, $value); } unset($match, $matches); } else { if ($array[$key]) { if (is_array($array[$key])) { $array[$key][] = $value; } else { $array[$key] = array($array[$key], $value); } } else { $array[$key] = $value; } } } return $array; }
/** Defaults to param if param available; if not, then to $this->data */ function to_input($name, $value = null, $useArray = false) { if (isset($this->in[$name])) { return $this->in[$name]; } else { $matches = \Http::getSpecialSyntaxKeys($name); if ($matches && \Arrays::isElement($matches, $this->in)) { return \Arrays::getElementReference($matches, $this->in); } else { if ($useArray) { return $this->in[$name]; } else { if ($value === null && isset($this->data[$name])) { return $this->data[$name]; } else { return $this->to_param($name, $value); } } } } }