Esempio n. 1
0
 /**
 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 = \Grithin\Strings::explode('&', $string);
     $array = array();
     foreach ($parts as $part) {
         list($key, $value) = explode('=', $part);
         $key = urldecode($key);
         $value = urldecode($value);
         if ($specialSyntax && ($matches = self::specialSyntaxKeys($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;
 }
Esempio n. 2
0
 function applyPath($path)
 {
     $this->tokens = \Grithin\Strings::explode('/', $path);
     $this->path = implode('/', $this->tokens);
     # recap the "/" on the path
     if (substr($path, -1) == '/') {
         $this->path .= '/';
     }
     $this->caselessPath = strtolower($this->path);
 }