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


PHP RequestInterface::getUri方法代码示例

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


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

示例1: __invoke

 /**
  * Call the middleware
  */
 public function __invoke(RequestInterface $request, ResponseInterface $response, callable $next)
 {
     $scheme = $request->getUri()->getScheme();
     $host = $request->getUri()->getHost();
     /* If rules say we should not authenticate call next and return. */
     if (false === $this->shouldAuthenticate($request)) {
         return $next($request, $response);
     }
     /* HTTP allowed only if secure is false or server is in relaxed array. */
     if ("https" !== $scheme && true === $this->options["secure"]) {
         if (!in_array($host, $this->options["relaxed"])) {
             $message = sprintf("Insecure use of middleware over %s denied by configuration.", strtoupper($scheme));
             throw new \RuntimeException($message);
         }
     }
     /* If token cannot be found return with 401 Unauthorized. */
     if (false === ($token = $this->fetchToken($request))) {
         return $this->error($request, $response, ["message" => $this->message])->withStatus(401);
     }
     /* If token cannot be decoded return with 401 Unauthorized. */
     if (false === ($decoded = $this->decodeToken($token))) {
         return $this->error($request, $response, ["message" => $this->message])->withStatus(401);
     }
     /* If callback returns false return with 401 Unauthorized. */
     if (is_callable($this->options["callback"])) {
         $params = ["decoded" => $decoded];
         if (false === $this->options["callback"]($request, $response, $params)) {
             return $this->error($request, $response, ["message" => $this->message || "Callback returned false"])->withStatus(401);
         }
     }
     /* Everything ok, call next middleware and return. */
     return $next($request, $response);
 }
开发者ID:djbakerman,项目名称:botjack,代码行数:36,代码来源:JwtAuthentication.php

示例2: getLastRequestPath

 /**
  * @return string|null
  */
 public function getLastRequestPath()
 {
     if (is_null($this->lastRequest)) {
         return null;
     }
     return $this->lastRequest->getUri();
 }
开发者ID:survos,项目名称:platform-api-php,代码行数:10,代码来源:GuzzleListener.php

示例3: describe

 /**
  * @param \Psr\Http\Message\RequestInterface $request
  * @param \Psr\Http\Message\ResponseInterface $response
  *
  * @return string
  */
 protected function describe(RequestInterface $request, ResponseInterface $response = null)
 {
     if (!$response) {
         return sprintf('%s %s failed', $request->getMethod(), $request->getUri());
     }
     return sprintf('%s %s returned %s %s', $request->getMethod(), $request->getUri(), $response->getStatusCode(), $response->getReasonPhrase());
 }
开发者ID:hannesvdvreken,项目名称:guzzle-profiler,代码行数:13,代码来源:DescriptionMaker.php

示例4: signRequest

 public function signRequest(RequestInterface $request, CredentialsInterface $credentials)
 {
     $params = Psr7\parse_query($request->getBody()->__toString());
     $params['SignatureVersion'] = '2';
     $params['SignatureMethod'] = 'HmacSHA256';
     $params['AWSAccessKeyId'] = $credentials->getAccessKeyId();
     if ($credentials->getSecurityToken()) {
         $params['MWSAuthToken'] = $credentials->getSecurityToken();
     }
     $params['Timestamp'] = gmdate(self::ISO8601_BASIC);
     ksort($params);
     $canonicalizedQueryString = $this->getCanonicalizedQuery($params);
     $stringToSign = implode("\n", [$request->getMethod(), $request->getUri()->getHost(), $request->getUri()->getPath(), $canonicalizedQueryString]);
     // calculate HMAC with SHA256 and base64-encoding
     $signature = base64_encode(hash_hmac('sha256', $stringToSign, $credentials->getSecretKey(), TRUE));
     // encode the signature for the request
     $signature = str_replace('%7E', '~', rawurlencode($signature));
     $signature = str_replace('+', '%20', $signature);
     $signature = str_replace('*', '%2A', $signature);
     $queryString = $canonicalizedQueryString . "&Signature=" . $signature;
     if ($request->getMethod() === 'POST') {
         return new Request('POST', $request->getUri(), ['Content-Length' => strlen($queryString), 'Content-Type' => 'application/x-www-form-urlencoded'], $queryString);
     } else {
         return new Request('GET', $request->getUri()->withQuery($queryString));
     }
 }
开发者ID:ecoco,项目名称:aws-sdk-php,代码行数:26,代码来源:SignatureV2.php

示例5: getUri

 /**
  * @return string
  */
 public function getUri()
 {
     if (!$this->request) {
         return null;
     }
     return (string) $this->request->getUri();
 }
开发者ID:BureauPieper,项目名称:storee-php-client,代码行数:10,代码来源:EffectiveUrlMiddleware.php

示例6: to

 /**
  * Forward the request to the target url and return the response.
  *
  * @param  string $target
  * @throws UnexpectedValueException
  * @return Response
  */
 public function to($target)
 {
     if (is_null($this->request)) {
         throw new UnexpectedValueException('Missing request instance.');
     }
     $target = new Uri($target);
     // Overwrite target scheme and host.
     $uri = $this->request->getUri()->withScheme($target->getScheme())->withHost($target->getHost());
     // Check for custom port.
     if ($port = $target->getPort()) {
         $uri = $uri->withPort($port);
     }
     // Check for subdirectory.
     if ($path = $target->getPath()) {
         $uri = $uri->withPath(rtrim($path, '/') . '/' . ltrim($uri->getPath(), '/'));
     }
     $request = $this->request->withUri($uri);
     $stack = $this->filters;
     $stack[] = function (RequestInterface $request, ResponseInterface $response, callable $next) {
         $response = $this->adapter->send($request);
         return $next($request, $response);
     };
     $relay = (new RelayBuilder())->newInstance($stack);
     return $relay($request, new Response());
 }
开发者ID:kangkot,项目名称:php-proxy,代码行数:32,代码来源:Proxy.php

示例7: handleRequest

 /**
  * {@inheritdoc}
  */
 public function handleRequest(RequestInterface $request, callable $next, callable $first)
 {
     if ($this->replace || $request->getUri()->getHost() === '') {
         $uri = $request->getUri()->withHost($this->host->getHost())->withScheme($this->host->getScheme())->withPort($this->host->getPort());
         $request = $request->withUri($uri);
     }
     return $next($request);
 }
开发者ID:php-http,项目名称:client-common,代码行数:11,代码来源:AddHostPlugin.php

示例8: processing

 /**
  * @param RequestInterface $request
  *
  * @return string|null
  */
 protected function processing(RequestInterface $request)
 {
     $key = sprintf('%s?%s', $request->getUri()->getPath(), $request->getUri()->getQuery());
     if ($request->getMethod() == 'GET' && isset($this->data[$key])) {
         return $this->data[$key];
     }
     return null;
 }
开发者ID:paul-schulleri,项目名称:DesignPatternsPHP,代码行数:13,代码来源:HttpInMemoryCacheHandler.php

示例9: getGet

 /**
  * @param $champ
  * @return mixed
  */
 public function getGet($champ)
 {
     parse_str($this->request->getUri()->getQuery(), $tab);
     if (!isset($tab[$champ])) {
         return null;
     }
     return $tab[$champ];
 }
开发者ID:eleparquier,项目名称:nj_server,代码行数:12,代码来源:HTTP.php

示例10: convertGetToPost

 /**
  * Converts default GET request to a POST request
  *
  * Avoiding length restriction in query
  *
  * @param RequestInterface $r GET request to be converted
  * @return RequestInterface $req converted POST request
  */
 public static function convertGetToPost(RequestInterface $r)
 {
     if ($r->getMethod() === 'POST') {
         return $r;
     }
     $query = $r->getUri()->getQuery();
     $req = $r->withMethod('POST')->withBody(Psr7\stream_for($query))->withHeader('Content-Length', strlen($query))->withHeader('Content-Type', 'application/x-www-form-urlencoded')->withUri($r->getUri()->withQuery(''));
     return $req;
 }
开发者ID:Afrozaar,项目名称:wp-api-v2-afrozaar-extras,代码行数:17,代码来源:CloudSearchDomainClient.php

示例11: __invoke

 /**
  * {@inheritdoc}
  */
 public function __invoke(Request $request, Response $response, callable $next)
 {
     // Prepare default URL
     // TODO: Improve URI modification
     $uri = $this->uri;
     $uri = $uri->withPath($uri->getPath() . '/' . ltrim($request->getUri()->getPath(), '/'));
     $uri = $uri->withQuery($request->getUri()->getQuery());
     $request = $request->withUri($uri);
     return $next($request, $response);
 }
开发者ID:Teknologica,项目名称:rebilly-php,代码行数:13,代码来源:BaseUri.php

示例12: getToken

 /**
  * @param array $claims
  * @return string
  */
 public function getToken(array $claims = [])
 {
     $issuer = (string) $this->request->getUri();
     $issued_at = $this->config->getTimestamp();
     $expiration = $issued_at + $this->config->getTtl();
     $key = $this->config->getPublicKey();
     $algorithm = $this->config->getAlgorithm();
     $claims += ['iss' => $issuer, 'iat' => $issued_at, 'exp' => $expiration];
     return JWT::encode($claims, $key, $algorithm);
 }
开发者ID:JasonBusse,项目名称:rest_scheduler,代码行数:14,代码来源:FirebaseGenerator.php

示例13: __invoke

 /**
  * Inject credentials information into the query parameters
  *
  * @param RequestInterface $request
  * @param array            $options
  *
  * @return GuzzleResponseInterface
  */
 public function __invoke(RequestInterface $request, array $options)
 {
     if ($request->getUri()->getScheme() == 'https' && $options['auth'] == static::AUTH_NAME) {
         $uri = Uri::withQueryValue($request->getUri(), 'client_id', $this->userKey ?: $this->apiKey);
         $uri = Uri::withQueryValue($uri, 'client_secret', $this->secret);
         $request = $request->withUri($uri);
     }
     $fn = $this->nextHandler;
     return $fn($request, $options);
 }
开发者ID:graze,项目名称:gigya-client,代码行数:18,代码来源:CredentialsAuthMiddleware.php

示例14: getPath

 protected function getPath(RequestInterface $request)
 {
     $path = $this->path . DIRECTORY_SEPARATOR . strtolower($request->getMethod()) . DIRECTORY_SEPARATOR . $request->getUri()->getHost() . DIRECTORY_SEPARATOR;
     $rpath = $request->getUri()->getPath();
     if ($rpath && $rpath !== '/') {
         $rpath = substr($rpath, 0, 1) === '/' ? substr($rpath, 1) : $rpath;
         $rpath = substr($rpath, -1, 1) === '/' ? substr($rpath, 0, -1) : $rpath;
         $path .= str_replace("/", "_", $rpath) . DIRECTORY_SEPARATOR;
     }
     return $path;
 }
开发者ID:Lidbetter,项目名称:GuzzleRecorder,代码行数:11,代码来源:GuzzleRecorder.php

示例15: getToken

 /**
  * @param array $claims
  * @return string
  */
 public function getToken(array $claims = [])
 {
     $issuer = (string) $this->request->getUri();
     $issued_at = $this->config->getTimestamp();
     $expiration = $issued_at + $this->config->getTtl();
     $key = $this->config->getPrivateKey();
     foreach ($claims as $name => $value) {
         $this->builder->set($name, $value);
     }
     $token = $this->builder->setIssuer($issuer)->setIssuedAt($issued_at)->setExpiration($expiration)->sign($this->signer, $key)->getToken();
     return (string) $token;
 }
开发者ID:JasonBusse,项目名称:rest_scheduler,代码行数:16,代码来源:LcobucciGenerator.php


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