parse() public method

Parse string containing key-value pairs
public parse ( $str ) : array
$str string
return array
Esempio n. 1
0
 /**
  * Obtains a SimpleID URL.  URLs produced by SimpleID should use this function.
  *
  * @param string $path the FatFree path or alias
  * @param string $query a properly encoded query string
  * @param string $secure if $relative is false, either 'https' to force an HTTPS connection, 'http' to force
  * an unencrypted HTTP connection, 'detect' to base on the current connection, or NULL to vary based on SIMPLEID_BASE_URL
  * @return string the url
  *
  * @since 0.7
  */
 public function getCanonicalURL($path = '', $query = '', $secure = null)
 {
     $config = $this->f3->get('config');
     $canonical_base_path = $config['canonical_base_path'];
     if (preg_match('/^(?:@(\\w+)(?:(\\(.+?)\\))*|https?:\\/\\/)/', $path, $parts)) {
         if (isset($parts[1])) {
             $aliases = $this->f3->get('ALIASES');
             if (!empty($aliases[$parts[1]])) {
                 $path = $aliases[$parts[1]];
                 $path = $this->f3->build($path, isset($parts[2]) ? $this->f3->parse($parts[2]) : array());
                 $path = ltrim($path, '/');
             }
         }
     }
     // Make sure that the base has a trailing slash
     if (substr($config['canonical_base_path'], -1) == '/') {
         $url = $config['canonical_base_path'];
     } else {
         $url = $config['canonical_base_path'] . '/';
     }
     if ($secure == 'https' && stripos($url, 'http:') === 0) {
         $url = 'https:' . substr($url, 5);
     }
     if ($secure == 'http' && stripos($url, 'https:') === 0) {
         $url = 'http:' . substr($url, 6);
     }
     if ($secure == 'detect' && $this->isHttps() && stripos($url, 'http:') === 0) {
         $url = 'https:' . substr($url, 5);
     }
     if ($secure == 'detect' && !$this->isHttps() && stripos($url, 'https:') === 0) {
         $url = 'http:' . substr($url, 6);
     }
     $url .= $path . ($query == '' ? '' : '?' . $query);
     return $url;
 }
Esempio n. 2
0
 /**
  * Assemble url from alias name
  * @param string $name
  * @param array $params
  * @param string $lang
  * @return string|FALSE
  */
 function alias($name, $params = NULL, $lang = NULL)
 {
     if (in_array($name, $this->global_aliases)) {
         return $this->f3->alias($name, $params);
     }
     $params = $params ? $this->f3->parse($params) : array();
     if (!$lang) {
         $lang = $this->current;
     }
     if (isset($this->rules[$lang][$name]) && $this->rules[$lang][$name] === FALSE) {
         return FALSE;
     }
     $url = isset($this->rules[$lang][$name]) ? $this->rules[$lang][$name] : @$this->_aliases[$name];
     if (!$url) {
         user_error(sprintf(\Base::E_Named, $name), E_USER_ERROR);
     }
     return $this->f3->build(rtrim('/' . $lang . $url, '/'), $params);
 }