当前位置: 首页>>代码示例>>PHP>>正文


PHP Url::getQuery方法代码示例

本文整理汇总了PHP中Url::getQuery方法的典型用法代码示例。如果您正苦于以下问题:PHP Url::getQuery方法的具体用法?PHP Url::getQuery怎么用?PHP Url::getQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Url的用法示例。


在下文中一共展示了Url::getQuery方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testUrl

 function testUrl()
 {
     $url = new Url(self::TEST_URL);
     $this->assertEquals($url->getFull(), self::TEST_URL);
     $this->assertEquals($url->getScheme(), 'https');
     $this->assertEquals($url->getHost(), 'www.google.com');
     $this->assertEquals($url->getPort(), '80');
     $this->assertEquals($url->getPath(), '/some_path');
     // The HTML entities remain intact
     $this->assertEquals($url->getQuery(), 'some=query&something=%20weird');
     // The HTML entities are resolved
     $this->assertEquals($url->getParam('some'), 'query');
     $this->assertEquals($url->getParam('something'), ' weird');
     $this->assertEquals($url->getParams(), ['some' => 'query', 'something' => ' weird']);
     $this->assertEquals($url->getFragment(), 'some_fragment');
     $this->assertEquals($url->getUser(), 'user');
     $this->assertEquals($url->getPass(), 'pass');
 }
开发者ID:inad9300,项目名称:bed.php,代码行数:18,代码来源:UrlTest.php

示例2: baseString

 /**
  * Generate a base string for a RSA-SHA1 signature
  * based on the given a url, method, and any parameters.
  *
  * @param Url    $url
  * @param string $method
  * @param array  $parameters
  *
  * @return string
  */
 protected function baseString(Url $url, $method = 'POST', array $parameters = [])
 {
     $baseString = rawurlencode($method) . '&';
     $schemeHostPath = $url->getScheme() . '://' . $url->getHost();
     if ($url->getPort() != '') {
         $schemeHostPath .= ':' . $url->getPort();
     }
     if ($url->getPath() != '') {
         $schemeHostPath .= $url->getPath();
     }
     $baseString .= rawurlencode($schemeHostPath) . '&';
     $data = [];
     parse_str($url->getQuery(), $query);
     foreach (array_merge($query, $parameters) as $key => $value) {
         $data[rawurlencode($key)] = rawurlencode($value);
     }
     ksort($data);
     array_walk($data, function (&$value, $key) {
         $value = $key . '=' . $value;
     });
     $baseString .= rawurlencode(implode('&', $data));
     return $baseString;
 }
开发者ID:socialiteproviders,项目名称:jira,代码行数:33,代码来源:RsaSha1Signature.php

示例3: linkTo

 /**
  * get a link from the current URL to another one
  * @param  UrlInterface|string $url the URL to link to
  * @param  boolean $forceAbsolute   should an absolute path be used, defaults to `true`)
  * @return string  the link
  */
 public function linkTo($url, $forceAbsolute = true)
 {
     if (is_string($url)) {
         $url = new Url($url);
     }
     $str = (string) $url;
     if ($this->getScheme() !== $url->getScheme()) {
         return $str;
     }
     $str = preg_replace('(^[^/]+//)', '', $str);
     if ($this->getHost() !== $url->getHost() || $this->getPort() !== $url->getPort()) {
         return '//' . $str;
     }
     $str = preg_replace('(^[^/]+)', '', $str);
     if ($this->getPath() !== $url->getPath()) {
         if ($forceAbsolute) {
             return $str;
         }
         $cnt = 0;
         $tseg = $this->getSegments();
         $useg = $url->getSegments();
         foreach ($tseg as $k => $v) {
             if (!isset($useg[$k]) || $useg[$k] !== $v) {
                 break;
             }
             $cnt++;
         }
         $str = './' . str_repeat('../', count($useg) - $cnt) . implode('/', array_slice($useg, $cnt));
         if ($url->getQuery()) {
             $str .= '?' . $url->getQuery();
         }
         if ($url->getFragment()) {
             $str .= '#' . $url->getFragment();
         }
         return $str;
     }
     $str = preg_replace('(^[^?]+)', '', $str);
     if ($this->getQuery() !== $url->getQuery() || $url->getFragment() === null) {
         return $str;
     }
     return '#' . $url->getFragment();
 }
开发者ID:vakata,项目名称:http,代码行数:48,代码来源:Url.php

示例4: formatLink

 public function formatLink(Url $url)
 {
     // save and reset query to save variable order
     $query = $url->getQuery();
     $url->setQuery([]);
     // extract path to separate params and remove actions
     $parts = explode(self::REWRITE_PARAM_TO_ACTION_DELIMITER, $url->getPath());
     foreach ($parts as $part) {
         // only extract "normal" parameters, avoid actions
         if (strpos($part, '-action') === false) {
             $paths = explode('/', strip_tags($part));
             array_shift($paths);
             // create key => value pairs from the current request
             $x = 0;
             while ($x <= count($paths) - 1) {
                 if (isset($paths[$x + 1])) {
                     $url->setQueryParameter($paths[$x], $paths[$x + 1]);
                 }
                 // increment by 2, because the next offset is the key!
                 $x = $x + 2;
             }
         }
     }
     // reset the path to not have duplicate path due to generic param generation
     $url->setPath(null);
     // merge query now to overwrite values already contained in the url
     $url->mergeQuery($query);
     $resultUrl = $this->getFormattedBaseUrl($url);
     $query = $url->getQuery();
     if (count($query) > 0) {
         // get URL mappings and try to resolve mapped actions
         $mappings = $this->getActionUrMappingTokens();
         foreach ($query as $name => $value) {
             // allow empty params that are action definitions to not
             // exclude actions with no params!
             if (!$this->isValueEmpty($value) || $this->isValueEmpty($value) && strpos($name, '-action') !== false || $this->isValueEmpty($value) && in_array($name, $mappings) !== false) {
                 if (strpos($name, '-action') === false && in_array($name, $mappings) === false) {
                     $resultUrl .= '/' . $name . '/' . $value;
                 } else {
                     // action blocks must be separated with group indicator
                     // to be able to parse the parameters
                     $resultUrl .= self::REWRITE_PARAM_TO_ACTION_DELIMITER . $name;
                     // check whether value is empty and append action only
                     if (!$this->isValueEmpty($value)) {
                         $resultUrl .= '/' . $value;
                     }
                 }
             }
         }
     }
     // apply query to detect duplicate action definitions
     $actions = $this->getActionsUrlRepresentation($query, true);
     if (!empty($actions)) {
         $resultUrl .= self::REWRITE_PARAM_TO_ACTION_DELIMITER . $actions;
     }
     // encode blanks if desired
     if ($this->getEncodeBlanks() === true) {
         $resultUrl = strtr($resultUrl, [' ' => '%20']);
     }
     return $this->sanitizeUrl($this->appendAnchor($resultUrl, $url));
 }
开发者ID:GeneralCrime,项目名称:code,代码行数:61,代码来源:RewriteLinkScheme.php

示例5: testGetQuery

 public function testGetQuery()
 {
     $this->assertEquals('search=hello&page=2', $this->absoluteUrl->getQuery());
 }
开发者ID:starweb,项目名称:starlit-utils,代码行数:4,代码来源:UrlTest.php

示例6: resolve

 /**
  * Resolve given relative Url using this url
  * @param Url $Url
  * @return Url
  */
 public function resolve($Url)
 {
     $new = clone $this;
     if (!$Url->getHost()) {
         $new->setHost($this->getHost());
         $new->setProtocol($this->getProtocol());
         $new->setPort($this->getPort());
     }
     $new->setQuery($Url->getQuery());
     /* @var $new Url */
     if (String::StartsWith($Url->getPath(), '/')) {
         $new->setPath($Url->getPath());
         return $new;
     } else {
         $file = basename($Url->getPath());
         $path = trim(trim(dirname($this->getPath()), '/') . '/' . trim(dirname($Url->getPath()), '/'), '/');
         $parts = explode('/', $path);
         $resolved = array();
         foreach ($parts as $part) {
             switch ($part) {
                 case '.':
                 case '':
                     //Do nothing...
                     break;
                 case '..':
                     array_pop($resolved);
                     break;
                 default:
                     array_push($resolved, $part);
                     break;
             }
         }
         if (count($resolved) > 0) {
             $new->setPath('/' . implode('/', $resolved) . '/' . $file);
         } else {
             $new->setPath('/' . $file);
         }
         return $new;
     }
 }
开发者ID:hofmeister,项目名称:Pimple,代码行数:45,代码来源:Url.php


注:本文中的Url::getQuery方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。