本文整理汇总了PHP中Zend\Http\PhpEnvironment\Request::getHeader方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::getHeader方法的具体用法?PHP Request::getHeader怎么用?PHP Request::getHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Http\PhpEnvironment\Request
的用法示例。
在下文中一共展示了Request::getHeader方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setRequest
/**
* @param Request $request
*/
public function setRequest(Request $request)
{
$header = $request->getHeader($this->headerName);
if ($header) {
$this->requestHeaderValue = $header->getFieldValue();
}
}
示例2: RequestAreAuthorized
public static function RequestAreAuthorized()
{
$request = new Request();
$authHeader = $request->getHeader('authorization');
if ($authHeader) {
list($jwt) = sscanf($authHeader->toString(), 'Authorization: Bearer %s');
if ($jwt) {
try {
$secretKey = "CoppinPannequinAudio";
JWT::$leeway = 5;
$token = JWT::decode($jwt, $secretKey, array('HS512'));
return $token;
} catch (Exception $e) {
return false;
}
return false;
}
return false;
}
return false;
}
示例3: Request
/**
* Validates a token.
*
* Automatically validates a token when a request has an header with authorization.
*
* @since 4.3.0
*
* @return int|false user-id when token is valid, false when it is invalid.
*/
function validate_token()
{
$request = new Request();
if ($request->isGet() || $request->isPost()) {
$authHeader = $request->getHeader('authorization');
if ($authHeader) {
list($jwt) = sscanf($authHeader->toString(), 'Authorization: Bearer %s');
if ($jwt) {
try {
$secretKey = base64_decode(get_option('jwt_secret'));
$token = JWT::decode($jwt, $secretKey, array('HS256'));
return $token->data->userId;
} catch (Exception $e) {
// FALSE if token is invalid
return false;
}
} else {
// FALSE if no token was passed
return false;
}
}
}
return false;
}
示例4: testRetrievingASingleValueForParameters
public function testRetrievingASingleValueForParameters()
{
$request = new Request();
$p = new \Zend\Stdlib\Parameters(array('foo' => 'bar'));
$request->setQuery($p);
$request->setPost($p);
$request->setFiles($p);
$request->setServer($p);
$request->setEnv($p);
$this->assertSame('bar', $request->getQuery('foo'));
$this->assertSame('bar', $request->getPost('foo'));
$this->assertSame('bar', $request->getFiles('foo'));
$this->assertSame('bar', $request->getServer('foo'));
$this->assertSame('bar', $request->getEnv('foo'));
$headers = new Headers();
$h = new GenericHeader('foo', 'bar');
$headers->addHeader($h);
$request->setHeaders($headers);
$this->assertSame($headers, $request->getHeaders());
$this->assertSame($h, $request->getHeaders()->get('foo'));
$this->assertSame($h, $request->getHeader('foo'));
}
示例5: Request
<?php
chdir(dirname(__DIR__));
require_once 'vendor/autoload.php';
use Zend\Config\Config;
use Zend\Config\Factory;
use Zend\Http\PhpEnvironment\Request;
/*
* Get all headers from the HTTP request
*/
$request = new Request();
if ($request->isGet()) {
$authHeader = $request->getHeader('authorization');
/*
* Look for the 'authorization' header
*/
if ($authHeader) {
/*
* Extract the jwt from the Bearer
*/
list($jwt) = sscanf($authHeader->toString(), 'Authorization: Bearer %s');
if ($jwt) {
try {
$config = Factory::fromFile('config/config.php', true);
/*
* decode the jwt using the key from config
*/
$secretKey = base64_decode($config->get('jwt')->get('key'));
$token = JWT::decode($jwt, $secretKey, [$config->get('jwt')->get('algorithm')]);
$asset = base64_encode(file_get_contents('http://lorempixel.com/200/300/cats/'));
/*
示例6: getHeader
/**
* Get all headers of a certain name/type.
*
* @param string $name Header name to retrieve.
* @param mixed|null $default Default value to use when the requested header is missing.
* @return bool|HeaderInterface
*/
public function getHeader($name, $default = false)
{
$header = parent::getHeader($name, $default);
if ($header instanceof HeaderInterface) {
return $header->getFieldValue();
}
return false;
}