當前位置: 首頁>>代碼示例>>PHP>>正文


PHP RequestInterface::getRequestTarget方法代碼示例

本文整理匯總了PHP中Psr\Http\Message\RequestInterface::getRequestTarget方法的典型用法代碼示例。如果您正苦於以下問題:PHP RequestInterface::getRequestTarget方法的具體用法?PHP RequestInterface::getRequestTarget怎麽用?PHP RequestInterface::getRequestTarget使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Psr\Http\Message\RequestInterface的用法示例。


在下文中一共展示了RequestInterface::getRequestTarget方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: handleRequest

 /**
  * {@inheritdoc}
  */
 public function handleRequest(RequestInterface $request, callable $next, callable $first)
 {
     // Check in storage
     if (array_key_exists($request->getRequestTarget(), $this->redirectStorage)) {
         $uri = $this->redirectStorage[$request->getRequestTarget()]['uri'];
         $statusCode = $this->redirectStorage[$request->getRequestTarget()]['status'];
         $redirectRequest = $this->buildRedirectRequest($request, $uri, $statusCode);
         return $first($redirectRequest);
     }
     return $next($request)->then(function (ResponseInterface $response) use($request, $first) {
         $statusCode = $response->getStatusCode();
         if (!array_key_exists($statusCode, $this->redirectCodes)) {
             return $response;
         }
         $uri = $this->createUri($response, $request);
         $redirectRequest = $this->buildRedirectRequest($request, $uri, $statusCode);
         $chainIdentifier = spl_object_hash((object) $first);
         if (!array_key_exists($chainIdentifier, $this->circularDetection)) {
             $this->circularDetection[$chainIdentifier] = [];
         }
         $this->circularDetection[$chainIdentifier][] = $request->getRequestTarget();
         if (in_array($redirectRequest->getRequestTarget(), $this->circularDetection[$chainIdentifier])) {
             throw new CircularRedirectionException('Circular redirection detected', $request, $response);
         }
         if ($this->redirectCodes[$statusCode]['permanent']) {
             $this->redirectStorage[$request->getRequestTarget()] = ['uri' => $uri, 'status' => $statusCode];
         }
         // Call redirect request in synchrone
         $redirectPromise = $first($redirectRequest);
         return $redirectPromise->wait();
     });
 }
開發者ID:php-http,項目名稱:plugins,代碼行數:35,代碼來源:RedirectPlugin.php

示例2: request

 /**
  * Send a request to the server and return a Response object with the response.
  *
  * @param   RequestInterface $request The request object to send.
  *
  * @return  ResponseInterface
  *
  * @since   2.1
  */
 public function request(RequestInterface $request)
 {
     $uri = $request->getUri()->withPath(null)->withQuery(null)->withFragment(null);
     $uri = $uri . $request->getRequestTarget();
     $request = $request->withRequestTarget($uri);
     return $this->doRequest($request);
 }
開發者ID:kaiwa,項目名稱:http,代碼行數:16,代碼來源:AbstractTransport.php

示例3: formatRequest

 /**
  * {@inheritdoc}
  */
 public function formatRequest(RequestInterface $request)
 {
     $message = sprintf("%s %s HTTP/%s\n", $request->getMethod(), $request->getRequestTarget(), $request->getProtocolVersion());
     foreach ($request->getHeaders() as $name => $values) {
         $message .= $name . ': ' . implode(', ', $values) . "\n";
     }
     return $this->addBody($request, $message);
 }
開發者ID:php-http,項目名稱:message,代碼行數:11,代碼來源:FullHttpMessageFormatter.php

示例4: transformRequestHeadersToString

 /**
  * Produce the header of request as a string based on a PSR Request
  *
  * @param RequestInterface $request
  *
  * @return string
  */
 protected function transformRequestHeadersToString(RequestInterface $request)
 {
     $message = vsprintf('%s %s HTTP/%s', [strtoupper($request->getMethod()), $request->getRequestTarget(), $request->getProtocolVersion()]) . "\r\n";
     foreach ($request->getHeaders() as $name => $values) {
         $message .= $name . ': ' . implode(', ', $values) . "\r\n";
     }
     $message .= "\r\n";
     return $message;
 }
開發者ID:printu,項目名稱:socket-client,代碼行數:16,代碼來源:RequestWriter.php

示例5:

 function it_creates_an_http_exception(RequestInterface $request, ResponseInterface $response)
 {
     $request->getRequestTarget()->willReturn('/uri');
     $request->getMethod()->willReturn('GET');
     $response->getStatusCode()->willReturn(100);
     $response->getReasonPhrase()->willReturn('Continue');
     $e = $this->create($request, $response);
     $e->shouldHaveType('Http\\Client\\Exception\\HttpException');
     $e->getMessage()->shouldReturn('[url] /uri [http method] GET [status code] 100 [reason phrase] Continue');
 }
開發者ID:joelwurtz,項目名稱:php-http-master,代碼行數:10,代碼來源:HttpExceptionSpec.php

示例6: getFileName

 protected function getFileName(RequestInterface $request)
 {
     $result = trim($request->getMethod() . ' ' . $request->getRequestTarget()) . ' HTTP/' . $request->getProtocolVersion();
     foreach ($request->getHeaders() as $name => $values) {
         if (array_key_exists(strtoupper($name), $this->ignored_headers)) {
             continue;
         }
         $result .= "\r\n{$name}: " . implode(', ', $values);
     }
     $request = $result . "\r\n\r\n" . $request->getBody();
     return md5((string) $request) . ".txt";
 }
開發者ID:Lidbetter,項目名稱:GuzzleRecorder,代碼行數:12,代碼來源:GuzzleRecorder.php

示例7: toString

 /**
  * Serialize a request message to a string.
  *
  * @param RequestInterface $request
  * @return string
  */
 public static function toString(RequestInterface $request)
 {
     $headers = self::serializeHeaders($request->getHeaders());
     $body = (string) $request->getBody();
     $format = '%s %s HTTP/%s%s%s';
     if (!empty($headers)) {
         $headers = "\r\n" . $headers;
     }
     if (!empty($body)) {
         $headers .= "\r\n\r\n";
     }
     return sprintf($format, $request->getMethod(), $request->getRequestTarget(), $request->getProtocolVersion(), $headers, $body);
 }
開發者ID:deepfreeze,項目名稱:zend-diactoros,代碼行數:19,代碼來源:Serializer.php

示例8: create

 public static function create(RequestInterface $request, ResponseInterface $response, HalResource $resource, $previous = null, $message = null)
 {
     if (!$message) {
         $code = $response->getStatusCode();
         if ($code >= 400 && $code < 500) {
             $message = 'Client error';
         } elseif ($code >= 500 && $code < 600) {
             $message = 'Server error';
         } else {
             $message = 'Unsuccessful response';
         }
     }
     $message = sprintf('%s [url] %s [http method] %s [status code] %s [reason phrase] %s.', $message, $request->getRequestTarget(), $request->getMethod(), $response->getStatusCode(), $response->getReasonPhrase());
     return new self($message, $request, $response, $resource, $previous);
 }
開發者ID:jsor,項目名稱:hal-client,代碼行數:15,代碼來源:BadResponseException.php

示例9: toString

 /**
  * Serialize a request message to a string.
  *
  * @param RequestInterface $request
  * @return string
  */
 public static function toString(RequestInterface $request)
 {
     $httpMethod = $request->getMethod();
     if (empty($httpMethod)) {
         throw new UnexpectedValueException('Object can not be serialized because HTTP method is empty');
     }
     $headers = self::serializeHeaders($request->getHeaders());
     $body = (string) $request->getBody();
     $format = '%s %s HTTP/%s%s%s';
     if (!empty($headers)) {
         $headers = "\r\n" . $headers;
     }
     if (!empty($body)) {
         $headers .= "\r\n\r\n";
     }
     return sprintf($format, $httpMethod, $request->getRequestTarget(), $request->getProtocolVersion(), $headers, $body);
 }
開發者ID:zendframework,項目名稱:zend-diactoros,代碼行數:23,代碼來源:Serializer.php

示例10: create

 /**
  * {@inheritdoc}
  */
 public static function create(HttpRequestInterface $request, HttpResponseInterface $response = null, Exception $previous = null, array $handlerContext = null)
 {
     if ($request instanceof RequestInterface && $response instanceof ResponseInterface) {
         static $clientErrorCodes = [-32600, -32601, -32602, -32700];
         $errorCode = $response->getRpcErrorCode();
         if (in_array($errorCode, $clientErrorCodes)) {
             $label = 'Client RPC error response';
             $className = __NAMESPACE__ . '\\ClientException';
         } else {
             $label = 'Server RPC error response';
             $className = __NAMESPACE__ . '\\ServerException';
         }
         $message = $label . ' [uri] ' . $request->getRequestTarget() . ' [method] ' . $request->getRpcMethod() . ' [error code] ' . $errorCode . ' [error message] ' . $response->getRpcErrorMessage();
         return new $className($message, $request, $response, $previous);
     }
     return parent::create($request, $response, $previous);
 }
開發者ID:yashb,項目名稱:generator,代碼行數:20,代碼來源:RequestException.php

示例11: normalizeRequestToString

 /**
  * Normalize a request to string.
  *
  * @param RequestInterface $request
  *
  * @return string
  */
 public function normalizeRequestToString(RequestInterface $request)
 {
     return sprintf('%s %s %s', $request->getMethod(), $request->getRequestTarget(), $request->getProtocolVersion());
 }
開發者ID:Nyholm,項目名稱:plugins,代碼行數:11,代碼來源:Normalizer.php

示例12: runMatches

 protected function runMatches(RequestInterface $request)
 {
     return $request->getRequestTarget() == $this->expected;
 }
開發者ID:oscarotero,項目名稱:psr7-unitesting,代碼行數:4,代碼來源:RequestTarget.php

示例13: getRequestTarget

 /**
  * @return string
  */
 public function getRequestTarget()
 {
     return $this->request->getRequestTarget();
 }
開發者ID:bweston92,項目名稱:expressive-async,代碼行數:7,代碼來源:ServerRequest.php

示例14: create

 /**
  * Factory method to create a new exception with a normalized error message
  *
  * @param RequestInterface  $request
  * @param ResponseInterface $response
  * @param \Exception|null   $previous
  *
  * @return HttpException
  */
 public static function create(RequestInterface $request, ResponseInterface $response, \Exception $previous = null)
 {
     $message = sprintf('[url] %s [http method] %s [status code] %s [reason phrase] %s', $request->getRequestTarget(), $request->getMethod(), $response->getStatusCode(), $response->getReasonPhrase());
     return new self($message, $request, $response, $previous);
 }
開發者ID:xabbuh,項目名稱:httplug,代碼行數:14,代碼來源:HttpException.php

示例15: getName

 /**
  * GetName
  *
  * @param Request $request request
  *
  * @return string
  *
  * @access protected
  */
 protected function getName(Request $request)
 {
     if (!($path = $request->getAttribute('jnjxp/viewd:script'))) {
         $path = parse_url($request->getRequestTarget(), PHP_URL_PATH);
         $path = trim($path, '/');
     }
     $name = $this->prefix . DIRECTORY_SEPARATOR . ($path ? $path : 'index');
     return $name;
 }
開發者ID:jnjxp,項目名稱:viewd,代碼行數:18,代碼來源:Viewd.php


注:本文中的Psr\Http\Message\RequestInterface::getRequestTarget方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。