本文整理汇总了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();
});
}
示例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);
}
示例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);
}
示例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;
}
示例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');
}
示例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";
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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());
}
示例12: runMatches
protected function runMatches(RequestInterface $request)
{
return $request->getRequestTarget() == $this->expected;
}
示例13: getRequestTarget
/**
* @return string
*/
public function getRequestTarget()
{
return $this->request->getRequestTarget();
}
示例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);
}
示例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;
}