/** * Creates a URL query from a query string or as empty. * * Just like in any valid URL, a provided query string is not expected to contain characters that cannot be * represented literally and percent-encoding is expected to be used for any such characters. The query string * should not contain a leading "?" because it's rather a delimiter that is used to separate the query string from * the preceding URL part. * * @param string $queryString **OPTIONAL. Default is** *create an empty URL query*. The source query string. * @param reference $parsingWasFruitful **OPTIONAL. OUTPUT.** After the object is constructed, this parameter, * which is of type `bool`, tells whether the parsing of the query string resulted in any valid fields. */ public function __construct($queryString = null, &$parsingWasFruitful = null) { assert('!isset($queryString) || is_cstring($queryString)', vs(isset($this), get_defined_vars())); if (isset($queryString)) { if (!CString::isEmpty($queryString)) { // Before parsing, normalize field delimiters to the default one (e.g. make ";" to be "&"). $delimiters = CString::splitIntoChars(self::$ms_fieldDelimiters); $fields = CString::split($queryString, $delimiters); $queryString = CArray::join($fields, self::$ms_fieldDelimiters[0]); // Parse the query string. parse_str($queryString, $this->m_query); if (!is_cmap($this->m_query)) { $this->m_query = CMap::make(); } // Recursively convert any PHP's associative array with sequential keys into a CArray. foreach ($this->m_query as &$value) { $value = self::recurseQueryValueAfterParsing($value, 0); } unset($value); } else { $this->m_query = CMap::make(); } $parsingWasFruitful = !CMap::isEmpty($this->m_query); } else { $this->m_query = CMap::make(); } }