本文整理汇总了PHP中Psr\Http\Message\RequestInterface::getCookieParams方法的典型用法代码示例。如果您正苦于以下问题:PHP RequestInterface::getCookieParams方法的具体用法?PHP RequestInterface::getCookieParams怎么用?PHP RequestInterface::getCookieParams使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Psr\Http\Message\RequestInterface
的用法示例。
在下文中一共展示了RequestInterface::getCookieParams方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fetchToken
/**
* Fetch the access token
*
* @return string|null Base64 encoded JSON Web Token or null if not found.
*/
public function fetchToken(RequestInterface $request)
{
/* If using PHP in CGI mode and non standard environment */
$server_params = $request->getServerParams();
if (isset($server_params[$this->options["environment"]])) {
$message = "Using token from environent";
$header = $server_params[$this->options["environment"]];
} else {
$message = "Using token from request header";
$header = $request->getHeader("Authorization");
$header = isset($header[0]) ? $header[0] : "";
}
if (preg_match("/Bearer\\s+(.*)\$/i", $header, $matches)) {
$this->log(LogLevel::DEBUG, $message);
return $matches[1];
}
/* Bearer not found, try a cookie. */
$cookie_params = $request->getCookieParams();
if (isset($cookie_params[$this->options["cookie"]])) {
$this->log(LogLevel::DEBUG, "Using token from cookie");
$this->log(LogLevel::DEBUG, $cookie_params[$this->options["cookie"]]);
return $cookie_params[$this->options["cookie"]];
}
/* If everything fails log and return false. */
$this->message = "Token not found";
$this->log(LogLevel::WARNING, $this->message);
return false;
}
示例2: fetchToken
/**
* Fetch the access token
*
* @return string|null Base64 encoded JSON Web Token or null if not found.
*/
public function fetchToken(RequestInterface $request)
{
/* If using PHP in CGI mode and non standard environment */
$server_params = $request->getServerParams();
$header = "";
/* Check for each given environment */
foreach ((array) $this->options["environment"] as $environment) {
if (isset($server_params[$environment])) {
$message = "Using token from environment";
$header = $server_params[$environment];
}
}
/* Nothing in environment, try header instead */
if (empty($header)) {
$message = "Using token from request header";
$headers = $request->getHeader("Authorization");
$header = isset($headers[0]) ? $headers[0] : "";
}
/* Try apache_request_headers() as last resort */
if (empty($header) && function_exists("apache_request_headers")) {
$headers = apache_request_headers();
$header = isset($headers["Authorization"]) ? $headers["Authorization"] : "";
}
if (preg_match("/Bearer\\s+(.*)\$/i", $header, $matches)) {
$this->log(LogLevel::DEBUG, $message);
return $matches[1];
}
/* Bearer not found, try a cookie. */
$cookie_params = $request->getCookieParams();
if (isset($cookie_params[$this->options["cookie"]])) {
$this->log(LogLevel::DEBUG, "Using token from cookie");
$this->log(LogLevel::DEBUG, $cookie_params[$this->options["cookie"]]);
return $cookie_params[$this->options["cookie"]];
}
/* If everything fails log and return false. */
$this->message = "Token not found";
$this->log(LogLevel::WARNING, $this->message);
return false;
}