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


PHP UriInterface::withQuery方法代码示例

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


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

示例1: createUrlFromUri

 /**
  * @param string $specification
  * @return string
  */
 private function createUrlFromUri($specification)
 {
     preg_match('%^(?P<path>[^?#]*)(?:(?:\\?(?P<query>[^#]*))?(?:\\#(?P<fragment>.*))?)$%', (string) $specification, $matches);
     $path = $matches['path'];
     $query = isset($matches['query']) ? $matches['query'] : '';
     $fragment = isset($matches['fragment']) ? $matches['fragment'] : '';
     $uri = $this->uri->withQuery('')->withFragment('');
     // Relative path
     if (!empty($path) && '/' !== $path[0]) {
         $path = rtrim($this->uri->getPath(), '/') . '/' . $path;
     }
     // Path present; set on URI
     if (!empty($path)) {
         $uri = $uri->withPath($path);
     }
     // Query present; set on URI
     if (!empty($query)) {
         $uri = $uri->withQuery($query);
     }
     // Fragment present; set on URI
     if (!empty($fragment)) {
         $uri = $uri->withFragment($fragment);
     }
     return (string) $uri;
 }
开发者ID:zendframework,项目名称:zend-expressive-helpers,代码行数:29,代码来源:ServerUrlHelper.php

示例2: handle

 /**
  * @param AccessToken $accessToken
  * @param UriInterface $destination
  * @return Response
  */
 public function handle(AccessToken $accessToken, UriInterface $destination)
 {
     $claims = $this->userService->getUserClaims($accessToken)->toArray();
     $jwt = $this->encoderService->encode($claims);
     $q = $destination->getQuery();
     $q .= ($q ? '&' : '') . 'jwt=' . $jwt;
     return new RedirectResponse((string) $destination->withQuery($q));
 }
开发者ID:cultuurnet,项目名称:jwt-provider,代码行数:13,代码来源:JwtOAuthCallbackHandler.php

示例3: addQueryParameters

 /**
  * Merges additional query parameters with current query parameters (possibly overwriting (some of) them)
  *
  * @param UriInterface $uri
  * @param array $queryParameters Query parameters to add / overwrite
  * @return UriInterface
  */
 public static function addQueryParameters(UriInterface $uri, array $queryParameters)
 {
     $originalQuery = $uri->getQuery();
     $originalQueryParameters = [];
     parse_str($originalQuery, $originalQueryParameters);
     $newQueryParameters = array_replace_recursive($originalQueryParameters, $queryParameters);
     $newQuery = http_build_query($newQueryParameters);
     $newUri = $uri->withQuery($newQuery);
     return $newUri;
 }
开发者ID:subscribo,项目名称:psr-http-message-tools,代码行数:17,代码来源:UriFactory.php

示例4: withQueryValue

 /**
  * Create a new URI with a specific query string value.
  *
  * Any existing query string values that exactly match the provided key are
  * removed and replaced with the given key value pair.
  *
  * Note: this function will convert "=" to "%3D" and "&" to "%26".
  *
  * @param UriInterface $uri URI to use as a base.
  * @param string $key   Key to set.
  * @param string $value Value to set.
  *
  * @return UriInterface
  */
 public static function withQueryValue(UriInterface $uri, $key, $value)
 {
     $current = $uri->getQuery();
     $key = strtr($key, self::$replaceQuery);
     if (!$current) {
         $result = [];
     } else {
         $result = [];
         foreach (explode('&', $current) as $part) {
             if (explode('=', $part)[0] !== $key) {
                 $result[] = $part;
             }
         }
     }
     if ($value !== null) {
         $result[] = $key . '=' . strtr($value, self::$replaceQuery);
     } else {
         $result[] = $key;
     }
     return $uri->withQuery(implode('&', $result));
 }
开发者ID:alekitto,项目名称:api-connector-bundle,代码行数:35,代码来源:Uri.php

示例5: withoutQueryValue

 /**
  * Create a new URI with a specific query string value removed.
  *
  * Any existing query string values that exactly match the provided key are removed.
  *
  * Note: this function will convert "=" to "%3D" and "&" to "%26".
  *
  * @param UriInterface $uri URI to use as a base.
  * @param string       $key Query string key value pair to remove.
  *
  * @throws \InvalidArgumentException
  *
  * @return UriInterface
  */
 public static function withoutQueryValue(UriInterface $uri, $key)
 {
     if ($uri->getQuery() === null) {
         return $uri;
     }
     $result = [];
     foreach (explode('&', $uri->getQuery()) as $part) {
         if (explode('=', $part)[0] !== $key) {
             $result[] = $part;
         }
     }
     return $uri->withQuery(implode('&', $result));
 }
开发者ID:webservices-nl,项目名称:common,代码行数:27,代码来源:Uri.php

示例6: withAddedQueryValues

 public static function withAddedQueryValues(UriInterface $uri, array $queryValues) : UriInterface
 {
     $current = $uri->getQuery();
     if (false === empty($current)) {
         parse_str($current, $values);
         foreach ($values as $key => $value) {
             if (false === isset($queryValues[$key])) {
                 $queryValues[$key] = $value;
             }
         }
     }
     $result = [];
     foreach ($queryValues as $key => $value) {
         $result[] = $key . '=' . $value;
     }
     return $uri->withQuery(implode('&', $result));
 }
开发者ID:ThrusterIO,项目名称:http-message,代码行数:17,代码来源:Uri.php

示例7: getEnumFacet

 protected function getEnumFacet($facetName, $facetConfig, UriInterface $searchUri, $queryParams)
 {
     $attributeName = $facetConfig['attribute'];
     $cache = $this->get('app.cache');
     $cacheKey = $facetName . '-facet-' . $this->locale;
     $typeData = $this->get('app.repository.productType')->getTypes();
     if (!$cache->has($cacheKey)) {
         $facetValues = [];
         /**
          * @var ProductTypeCollection $typeData
          */
         foreach ($typeData as $productType) {
             /**
              * @var AttributeDefinition $attribute
              */
             $attribute = $productType->getAttributes()->getByName($attributeName);
             if (is_null($attribute)) {
                 continue;
             }
             /**
              * @var LocalizedEnumType $attributeType
              */
             $attributeType = $attribute->getType();
             $values = $attributeType->getValues();
             foreach ($values as $value) {
                 if (isset($facetValues[$value->getKey()])) {
                     continue;
                 }
                 $facetEntry = new ViewData();
                 $facetEntry->value = $value->getKey();
                 $facetEntry->label = (string) $value->getLabel();
                 $facetValues[$value->getKey()] = $facetEntry;
             }
         }
         $cache->store($cacheKey, serialize($facetValues));
     } else {
         $facetValues = unserialize($cache->fetch($cacheKey));
     }
     $facetData = new ViewData();
     $facetData->displayList = $facetConfig['display'] == 'list';
     $facetData->selectFacet = true;
     $facetData->facet = new ViewData();
     if ($facetConfig['multi'] == true) {
         $facetData->facet->multiSelect = $facetConfig['multi'];
     }
     $facetData->facet->available = true;
     $facetData->facet->label = $this->trans('filters.' . $facetName, [], 'catalog');
     $facetData->facet->key = $facetName;
     $limitedOptions = new ViewDataCollection();
     $selectedValues = array_diff_key($queryParams, [$facetName => true]);
     $facetData->facet->clearUri = $searchUri->withQuery(\GuzzleHttp\Psr7\build_query($selectedValues));
     foreach ($this->facets->getByName($facetName)->getTerms() as $term) {
         $key = $term->getTerm();
         $facetEntry = $facetValues[$term->getTerm()];
         $facetSelection = isset($queryParams[$facetName]) ? $queryParams[$facetName] : [];
         if (!is_array($facetSelection)) {
             $facetSelection = [$facetSelection];
         }
         if (in_array($key, $facetSelection)) {
             $facetEntry->selected = true;
             $uriValues = array_merge($selectedValues, [$facetName => array_diff($facetSelection, [$key])]);
         } else {
             $uriValues = array_merge($selectedValues, [$facetName => array_merge($facetSelection, [$key])]);
         }
         $uri = $searchUri->withQuery(\GuzzleHttp\Psr7\build_query($uriValues));
         $facetEntry->uri = $uri;
         $facetEntry->count = $term->getCount();
         $limitedOptions->add($facetEntry);
     }
     $facetData->facet->limitedOptions = $limitedOptions;
     return $facetData;
 }
开发者ID:sphereio,项目名称:commercetools-sunrise-php,代码行数:72,代码来源:CatalogController.php

示例8: withQueryValue

 /**
  * Creates a new URI with a specific query string value.
  *
  * Any existing query string values that exactly match the provided key are
  * removed and replaced with the given key value pair.
  *
  * A value of null will set the query string key without a value, e.g. "key"
  * instead of "key=value".
  *
  * @param UriInterface $uri   URI to use as a base.
  * @param string       $key   Key to set.
  * @param string|null  $value Value to set
  *
  * @return UriInterface
  */
 public static function withQueryValue(UriInterface $uri, $key, $value)
 {
     $current = $uri->getQuery();
     if ($current === '') {
         $result = [];
     } else {
         $decodedKey = rawurldecode($key);
         $result = array_filter(explode('&', $current), function ($part) use($decodedKey) {
             return rawurldecode(explode('=', $part)[0]) !== $decodedKey;
         });
     }
     // Query string separators ("=", "&") within the key or value need to be encoded
     // (while preventing double-encoding) before setting the query string. All other
     // chars that need percent-encoding will be encoded by withQuery().
     $key = strtr($key, self::$replaceQuery);
     if ($value !== null) {
         $result[] = $key . '=' . strtr($value, self::$replaceQuery);
     } else {
         $result[] = $key;
     }
     return $uri->withQuery(implode('&', $result));
 }
开发者ID:nystudio107,项目名称:instantanalytics,代码行数:37,代码来源:Uri.php

示例9: s3MVC_addQueryStrParamToUri

/**
 * 
 * Adds a query string parameter key/value pair to a uri object.
 * 
 * Given a uri object $uri1 representing http://someserver.com/controller/action?param1=val1 
 * s3MVC_addQueryStrParamToUri($uri1, 'param2', 'val2') will return a new uri object representing
 * http://someserver.com/controller/action?param1=val1&param2=val2
 * 
 * @param \Psr\Http\Message\UriInterface $uri
 * @param string $param_name
 * @param string $param_value
 * 
 * @return \Psr\Http\Message\UriInterface
 */
function s3MVC_addQueryStrParamToUri(\Psr\Http\Message\UriInterface $uri, $param_name, $param_value)
{
    $query_params = [];
    parse_str($uri->getQuery(), $query_params);
    // Extract existing query string params to an array
    $query_params[$param_name] = $param_value;
    // Add new param the query string params array
    return $uri->withQuery(http_build_query($query_params));
    // return a uri object with updated query params
}
开发者ID:rotexsoft,项目名称:slim3-skeleton-mvc-tools,代码行数:24,代码来源:framework-helpers.php

示例10: formLink

 /**
  * Forms an absolute link using the URI object from current reuqest.
  *
  * @param string $query Query string to use.
  *
  * @return string Absolute URI with given query.
  */
 protected function formLink($query)
 {
     $uri = $this->uri->withQuery($query);
     return $uri->__toString();
 }
开发者ID:foobar1643,项目名称:student-list,代码行数:12,代码来源:LinkGenerator.php

示例11: createUri

 /**
  * {@inheritdoc}
  */
 public function createUri($pageNumber)
 {
     return $this->uri->withQuery(http_build_query($this->getQuery() + [$this->pageParameter => $pageNumber]));
 }
开发者ID:jwdeitch,项目名称:components,代码行数:7,代码来源:Paginator.php

示例12: withQueryString

 /**
  * Create an UriInterface with the path information from `$server`. It uses the first part of
  * `$server['REQUEST_URI']` for this information.
  *
  * @param UriInterface $uri
  * @param array        $server
  *
  * @return UriInterface
  */
 private function withQueryString(UriInterface $uri, array $server) : UriInterface
 {
     if (isset($server['QUERY_STRING'])) {
         return $uri->withQuery($server['QUERY_STRING']);
     } else {
         if (isset($server['REQUEST_URI'])) {
             $requestUri = \explode('?', $server['REQUEST_URI'], 2);
             if (\count($requestUri) > 1) {
                 return $uri->withQuery($requestUri[1]);
             }
         }
     }
     return $uri;
 }
开发者ID:opsbears,项目名称:piccolo-web-io-standard,代码行数:23,代码来源:StandardInputProcessor.php

示例13: disconnectOxygenAsync

 /**
  * @param UriInterface $url
  * @param Session      $session
  *
  * @return Promise
  *
  * @resolves bool True if the module was just disconnected, false if it was already disconnected.
  *
  * @rejects  RequestException
  * @rejects  OxygenPageNotFoundException
  */
 public function disconnectOxygenAsync(UriInterface $url, Session $session)
 {
     return $this->client->getAsync($url->withQuery(\GuzzleHttp\Psr7\build_query(['q' => 'admin/config/oxygen/disconnect'])), [RequestOptions::COOKIES => $session->getCookieJar(), RequestOptions::AUTH => $session->getAuthData()])->then(function (ResponseInterface $response) use($url, $session) {
         $crawler = new Crawler((string) $response->getBody(), (string) $url);
         try {
             $form = $crawler->filter('form#oxygen-admin-disconnect')->form();
             if ($form->get('oxygen_connected')->getValue() === 'yes') {
                 return $this->client->requestAsync($form->getMethod(), $form->getUri(), [RequestOptions::COOKIES => $session->getCookieJar(), RequestOptions::AUTH => $session->getAuthData(), RequestOptions::HEADERS => ['referer' => $form->getUri()], RequestOptions::FORM_PARAMS => $form->getPhpValues()]);
             }
             return false;
         } catch (\Exception $e) {
             throw new OxygenPageNotFoundException();
         }
     })->then(function ($result) {
         if (!$result instanceof ResponseInterface) {
             // Module was already disconnected.
             return false;
         }
         // Module was successfully disconnected.
         return true;
     });
 }
开发者ID:Briareos,项目名称:Undine,代码行数:33,代码来源:Client.php


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