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


PHP UriInterface::getFragment方法代码示例

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


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

示例1: resolve

 /**
  * Resolve a base URI with a relative URI and return a new URI.
  *
  * @param UriInterface $base Base URI
  * @param string       $rel  Relative URI
  *
  * @return UriInterface
  */
 public static function resolve(UriInterface $base, $rel)
 {
     if ($rel === null || $rel === '') {
         return $base;
     }
     if ($rel instanceof UriInterface) {
         $relParts = ['scheme' => $rel->getScheme(), 'host' => $rel->getHost(), 'port' => $rel->getPort(), 'path' => $rel->getPath(), 'query' => $rel->getQuery(), 'fragment' => $rel->getFragment()];
     } else {
         $relParts = parse_url($rel) + ['scheme' => '', 'host' => '', 'port' => '', 'path' => '', 'query' => '', 'fragment' => ''];
     }
     if (!empty($relParts['scheme']) && !empty($relParts['host'])) {
         return $rel instanceof UriInterface ? $rel : self::fromParts($relParts);
     }
     $parts = ['scheme' => $base->getScheme(), 'host' => $base->getHost(), 'port' => $base->getPort(), 'path' => $base->getPath(), 'query' => $base->getQuery(), 'fragment' => $base->getFragment()];
     if (!empty($relParts['host'])) {
         $parts['host'] = $relParts['host'];
         $parts['port'] = $relParts['port'];
         $parts['path'] = self::removeDotSegments($relParts['path']);
         $parts['query'] = $relParts['query'];
         $parts['fragment'] = $relParts['fragment'];
     } elseif (!empty($relParts['path'])) {
         if (substr($relParts['path'], 0, 1) == '/') {
             $parts['path'] = self::removeDotSegments($relParts['path']);
             $parts['query'] = $relParts['query'];
             $parts['fragment'] = $relParts['fragment'];
         } else {
             if (!empty($parts['host']) && empty($parts['path'])) {
                 $mergedPath = '/';
             } else {
                 $mergedPath = substr($parts['path'], 0, strrpos($parts['path'], '/') + 1);
             }
             $parts['path'] = self::removeDotSegments($mergedPath . $relParts['path']);
             $parts['query'] = $relParts['query'];
             $parts['fragment'] = $relParts['fragment'];
         }
     } elseif (!empty($relParts['query'])) {
         $parts['query'] = $relParts['query'];
     } elseif ($relParts['fragment'] != null) {
         $parts['fragment'] = $relParts['fragment'];
     }
     return static::fromParts($parts);
 }
开发者ID:iwillhappy1314,项目名称:laravel-admin,代码行数:50,代码来源:Uri.php

示例2: resolve

 /**
  * Resolve a base URI with a relative URI and return a new URI.
  *
  * @param UriInterface             $base Base URI
  * @param null|string|UriInterface $rel  Relative URI
  *
  * @throws \InvalidArgumentException
  *
  * @return UriInterface
  */
 public static function resolve(UriInterface $base, $rel = null)
 {
     if ($rel === null || $rel === '') {
         return $base;
     }
     if (!$rel instanceof UriInterface) {
         $rel = new self($rel);
     }
     // Return the relative uri as-is if it has a scheme.
     if ($rel->getScheme()) {
         return $rel->withPath(static::removeDotSegments($rel->getPath()));
     }
     $relParts = ['scheme' => $rel->getScheme(), 'authority' => $rel->getAuthority(), 'path' => $rel->getPath(), 'query' => $rel->getQuery(), 'fragment' => $rel->getFragment()];
     $parts = ['scheme' => $base->getScheme(), 'authority' => $base->getAuthority(), 'path' => $base->getPath(), 'query' => $base->getQuery(), 'fragment' => $base->getFragment()];
     if (!empty($relParts['path'])) {
         if (strpos($relParts['path'], '/') === 0) {
             $parts['path'] = self::removeDotSegments($relParts['path']);
             $parts['query'] = $relParts['query'];
             $parts['fragment'] = $relParts['fragment'];
         } else {
             $mergedPath = substr($parts['path'], 0, strrpos($parts['path'], '/') + 1);
             $parts['path'] = self::removeDotSegments($mergedPath . $relParts['path']);
             $parts['query'] = $relParts['query'];
             $parts['fragment'] = $relParts['fragment'];
         }
     } elseif (!empty($relParts['query'])) {
         $parts['query'] = $relParts['query'];
     } elseif ($relParts['fragment'] !== null) {
         $parts['fragment'] = $relParts['fragment'];
     }
     return new self(static::createUriString($parts['scheme'], $parts['authority'], $parts['path'], $parts['query'], $parts['fragment']));
 }
开发者ID:webservices-nl,项目名称:common,代码行数:42,代码来源:Uri.php

示例3: formatFragment

 /**
  * Format a URI Fragment component according to the Formatter properties
  *
  * @param UriInterface|Uri $uri
  *
  * @return string
  */
 protected function formatFragment($uri)
 {
     $fragment = $uri->getFragment();
     if ($this->preserveFragment || '' != $fragment) {
         $fragment = '#' . $fragment;
     }
     return $fragment;
 }
开发者ID:barryvdh,项目名称:uri,代码行数:15,代码来源:Formatter.php

示例4: withUri

 /**
  * Returns an instance with the provided URI.
  *
  * This method MUST update the Host header of the returned request by
  * default if the URI contains a host component. If the URI does not
  * contain a host component, any pre-existing Host header MUST be carried
  * over to the returned request.
  *
  * You can opt-in to preserving the original state of the Host header by
  * setting `$preserveHost` to `true`. When `$preserveHost` is set to
  * `true`, this method interacts with the Host header in the following ways:
  *
  * - If the the Host header is missing or empty, and the new URI contains
  *   a host component, this method MUST update the Host header in the returned
  *   request.
  * - If the Host header is missing or empty, and the new URI does not contain a
  *   host component, this method MUST NOT update the Host header in the returned
  *   request.
  * - If a Host header is present and non-empty, this method MUST NOT update
  *   the Host header in the returned request.
  *
  * @link http://tools.ietf.org/html/rfc3986#section-4.3
  *
  * @param  UriInterface $uri          New request URI to use.
  * @param  bool         $preserveHost Preserve the original state of the Host header.
  * @return self
  */
 public function withUri(UriInterface $uri, $preserveHost = false)
 {
     $request = clone $this;
     $request->scheme($uri->getScheme());
     $userInfo = $uri->getUserInfo();
     $parts = explode(':', $userInfo);
     $request->username($parts[0] ?: null);
     $request->password(!empty($parts[1]) ? $parts[1] : null);
     $request->port($uri->getPort());
     if ($preserveHost) {
         $host = $request->headers['Host'];
         $request->host($uri->getHost());
         $request->headers['Host'] = $host;
     } else {
         $request->host($uri->getHost());
     }
     $request->path($uri->getPath());
     $request->query($uri->getQuery());
     $request->fragment($uri->getFragment());
     return $request;
 }
开发者ID:crysalead,项目名称:net,代码行数:48,代码来源:RequestTrait.php

示例5: resolve

 /**
  * Converts the relative URI into a new URI that is resolved against the base URI.
  *
  * @param UriInterface $base Base URI
  * @param UriInterface $rel  Relative URI
  *
  * @return UriInterface
  * @link http://tools.ietf.org/html/rfc3986#section-5.2
  */
 public static function resolve(UriInterface $base, UriInterface $rel)
 {
     if ((string) $rel === '') {
         // we can simply return the same base URI instance for this same-document reference
         return $base;
     }
     if ($rel->getScheme() != '') {
         return $rel->withPath(self::removeDotSegments($rel->getPath()));
     }
     if ($rel->getAuthority() != '') {
         $targetAuthority = $rel->getAuthority();
         $targetPath = self::removeDotSegments($rel->getPath());
         $targetQuery = $rel->getQuery();
     } else {
         $targetAuthority = $base->getAuthority();
         if ($rel->getPath() === '') {
             $targetPath = $base->getPath();
             $targetQuery = $rel->getQuery() != '' ? $rel->getQuery() : $base->getQuery();
         } else {
             if ($rel->getPath()[0] === '/') {
                 $targetPath = $rel->getPath();
             } else {
                 if ($targetAuthority != '' && $base->getPath() === '') {
                     $targetPath = '/' . $rel->getPath();
                 } else {
                     $lastSlashPos = strrpos($base->getPath(), '/');
                     if ($lastSlashPos === false) {
                         $targetPath = $rel->getPath();
                     } else {
                         $targetPath = substr($base->getPath(), 0, $lastSlashPos + 1) . $rel->getPath();
                     }
                 }
             }
             $targetPath = self::removeDotSegments($targetPath);
             $targetQuery = $rel->getQuery();
         }
     }
     return new Uri(Uri::composeComponents($base->getScheme(), $targetAuthority, $targetPath, $targetQuery, $rel->getFragment()));
 }
开发者ID:nystudio107,项目名称:instantanalytics,代码行数:48,代码来源:UriResolver.php

示例6: s3MVC_UriToString

/**
 * 
 * Converts a uri object to a string in the format <scheme>://<server_address>/<path>?<query_string>#<fragment>
 * 
 * @param \Psr\Http\Message\UriInterface $uri uri object to be converted to a string
 * 
 * @return string the string represntation of the uri object. 
 *                Eg. http://someserver.com/controller/action
 */
function s3MVC_UriToString(\Psr\Http\Message\UriInterface $uri)
{
    $scheme = $uri->getScheme();
    $authority = $uri->getAuthority();
    $basePath = s3MVC_GetBaseUrlPath();
    $path = $uri->getPath();
    $query = $uri->getQuery();
    $fragment = $uri->getFragment();
    $path = $basePath . '/' . ltrim($path, '/');
    return ($scheme ? $scheme . ':' : '') . ($authority ? '//' . $authority : '') . $path . ($query ? '?' . $query : '') . ($fragment ? '#' . $fragment : '');
}
开发者ID:rotexsoft,项目名称:slim3-skeleton-mvc-tools,代码行数:20,代码来源:framework-helpers.php

示例7: formatUri

 /**
  * Format a Interfaces\Schemes\Uri according to the Formatter properties
  *
  * @param Uri|UriInterface $uri
  *
  * @return string
  */
 protected function formatUri($uri)
 {
     $scheme = $uri->getScheme();
     if ('' !== $scheme) {
         $scheme .= ':';
     }
     $query = $this->formatUriPart(new Query($uri->getQuery()));
     if ('' !== $query) {
         $query = '?' . $query;
     }
     $fragment = $uri->getFragment();
     if ('' !== $fragment) {
         $fragment = '#' . $fragment;
     }
     $auth = $this->formatAuthority($uri);
     return $scheme . $auth . $this->formatPath($uri->getPath(), $auth) . $query . $fragment;
 }
开发者ID:burguin,项目名称:test02,代码行数:24,代码来源:Formatter.php

示例8: join

 /**
  * {@inheritdoc}
  */
 public function join(UriInterface $uriToJoin)
 {
     // other host
     if ($uriToJoin->getScheme() !== '' || $uriToJoin->getHost() !== '') {
         return clone $uriToJoin;
     }
     $uriToReturn = clone $this;
     // current path.
     if ($uriToJoin->getPath() === '' || $uriToJoin->getPath() === '.') {
         return $uriToReturn;
     }
     $newPathItems = explode('/', $uriToReturn->path);
     $pathItemToJoin = explode('/', $uriToJoin->getPath());
     if (isset($pathItemToJoin[0])) {
         array_pop($newPathItems);
     }
     $newPathItems = array_merge($newPathItems, $pathItemToJoin);
     $pathItemsToReturn = [];
     foreach ($newPathItems as $item) {
         if ($item === '') {
             $pathItemsToReturn = [$item];
         } elseif ($item === '.') {
             continue;
         } elseif ($item === '..') {
             array_pop($pathItemsToReturn);
         } else {
             array_push($pathItemsToReturn, $item);
         }
     }
     if (isset($pathItemsToReturn[0]) && $pathItemsToReturn[0] !== '') {
         array_unshift($pathItemsToReturn, '');
     }
     $uriToReturn->path = implode('/', $pathItemsToReturn);
     $uriToReturn->query = $uriToJoin->getQuery();
     $uriToReturn->fragment = $uriToJoin->getFragment();
     return $uriToReturn;
 }
开发者ID:wandu,项目名称:http,代码行数:40,代码来源:Uri.php

示例9: runMatches

 protected function runMatches(UriInterface $uri)
 {
     return $uri->getFragment() == $this->expected;
 }
开发者ID:oscarotero,项目名称:psr7-unitesting,代码行数:4,代码来源:Fragment.php


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