本文整理汇总了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);
}
示例2: getLastRequestPath
/**
* @return string|null
*/
public function getLastRequestPath()
{
if (is_null($this->lastRequest)) {
return null;
}
return $this->lastRequest->getUri();
}
示例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());
}
示例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));
}
}
示例5: getUri
/**
* @return string
*/
public function getUri()
{
if (!$this->request) {
return null;
}
return (string) $this->request->getUri();
}
示例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());
}
示例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);
}
示例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;
}
示例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];
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}