本文整理汇总了PHP中Psr\Http\Message\RequestInterface::getHeader方法的典型用法代码示例。如果您正苦于以下问题:PHP RequestInterface::getHeader方法的具体用法?PHP RequestInterface::getHeader怎么用?PHP RequestInterface::getHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Psr\Http\Message\RequestInterface
的用法示例。
在下文中一共展示了RequestInterface::getHeader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getRequestId
/**
* @return string
*/
public function getRequestId()
{
if ($this->request->hasHeader($this->headerName)) {
return $this->request->getHeader($this->headerName);
}
return $this->fallback->getRequestId();
}
示例2: getHeader
/**
* {@inheritdoc}
*/
public function getHeader($header)
{
if (!$this->request->hasHeader($header)) {
if (strtolower($header) === 'host' && ($this->request->getUri() && $this->request->getUri()->getHost())) {
return array($this->getHostFromUri());
}
return array();
}
return $this->request->getHeader($header);
}
示例3: verifyAll
/**
* Given an array of the headers this method will run through all verification methods
* @param RequestInterface $request
* @return bool TRUE if all headers are valid, FALSE if 1 or more were invalid
*/
public function verifyAll(RequestInterface $request)
{
$passes = 0;
$passes += (int) $this->verifyMethod($request->getMethod());
$passes += (int) $this->verifyHTTPVersion($request->getProtocolVersion());
$passes += (int) $this->verifyRequestURI($request->getUri()->getPath());
$passes += (int) $this->verifyHost($request->getHeader('Host'));
$passes += (int) $this->verifyUpgradeRequest($request->getHeader('Upgrade'));
$passes += (int) $this->verifyConnection($request->getHeader('Connection'));
$passes += (int) $this->verifyKey($request->getHeader('Sec-WebSocket-Key'));
$passes += (int) $this->verifyVersion($request->getHeader('Sec-WebSocket-Version'));
return 8 === $passes;
}
示例4: __invoke
/**
* Invoke middleware
*
* @param RequestInterface $request PSR7 request object
* @param ResponseInterface $response PSR7 response object
* @param callable $next Next middleware callable
*
* @return ResponseInterface PSR7 response object
*/
public function __invoke(RequestInterface $request, ResponseInterface $response, callable $next)
{
$uri = $request->getUri();
if (false !== strpos($uri->getPath(), $this->route)) {
$authUser = $request->getHeader('PHP_AUTH_USER') ? $request->getHeader('PHP_AUTH_USER')[0] : null;
$authPass = $request->getHeader('PHP_AUTH_PW') ? $request->getHeader('PHP_AUTH_PW')[0] : null;
if ($authUser && $authPass && $authUser === $this->username && $authPass === $this->password) {
return $next($request, $response);
} else {
return $response->withStatus(401)->withHeader('WWW-Authenticate', sprintf('Basic realm="%s"', $this->realm));
}
}
return $next($request, $response);
}
示例5: requestContentTypeIsJson
/**
* @param RequestInterface $request
* @return bool
*/
protected function requestContentTypeIsJson(RequestInterface $request)
{
$contentTypes = $request->getHeader('Content-Type');
if (empty($contentTypes)) {
throw new InvalidArgumentException("Given request is missing Content-Type header");
}
$contentType = reset($contentTypes);
return substr($contentType, 0, 16) === self::JSON_MIME;
}
示例6: prepareHttpCUrl
/**
* Assigns options specific to handling HTTP requests.
* NOTE: THIS METHOD SHOULD BE CALLED ONLY FROM prepareCUrl()!
*
* @throws UnsupportedFeatureException Thrown if POST method was requested.
*/
private function prepareHttpCUrl()
{
if ($this->fetchRequest->getMethod() !== 'GET') {
throw new UnsupportedFeatureException('Request other than GET are not supported');
}
$headers = [];
foreach ($this->fetchRequest->getHeaders() as $name => $values) {
$headers[] = $name . ": " . implode(", ", $values);
}
curl_setopt_array($this->cUrl, [CURLOPT_AUTOREFERER => 1, CURLOPT_FOLLOWLOCATION => 1, CURLOPT_FAILONERROR => 1, CURLOPT_HTTP_VERSION => $this->fetchRequest->getProtocolVersion() === '1.0' ? CURL_HTTP_VERSION_1_0 : CURL_HTTP_VERSION_1_1, CURLOPT_USERAGENT => $this->fetchRequest->getHeader('User-Agent') ?: $this->getDefaultUserAgent(), CURLOPT_HTTPHEADER => $headers]);
}
示例7: __invoke
public function __invoke(RequestInterface $request) : Data
{
$tokens = array_filter(array_map([$this, 'parseToken'], $request->getHeader('Cookie')), function (Token $token) use($request) {
return $this->tokenValidator->__invoke($token, $request);
});
/* @var $token Token|bool */
$token = reset($tokens);
$session = $token ? $this->tokenSerializer->deSerialize($token) : Data::newEmptySession();
if (!$this->sessionValidator->__invoke($session, $request)) {
// if all validation fails, simply reset the session (scrap it)
return Data::newEmptySession();
}
return $session;
}
示例8: processResponse
/**
* @param RequestInterface $request
* @param array $options
* @param ResponseInterface|PromiseInterface $response
*
* @return ResponseInterface|PromiseInterface
*/
public function processResponse(RequestInterface $request, array $options, ResponseInterface $response)
{
$response = $response->withHeader('X-Blackfire-Profile-Uuid', $request->getHeader('X-Blackfire-Profile-Uuid'));
if (!$response->hasHeader('X-Blackfire-Response')) {
return $response;
}
parse_str($response->getHeader('X-Blackfire-Response')[0], $values);
if (!isset($values['continue']) || 'true' !== $values['continue']) {
return $response;
}
Psr7\rewind_body($request);
/* @var PromiseInterface|ResponseInterface $promise */
return $this($request, $options);
}
示例9: __invoke
/**
* @param RequestInterface $request
* @param callable $next
* @return mixed
*/
public function __invoke(RequestInterface $request, callable $next)
{
$isXHR = in_array('XMLHttpRequest', $request->getHeader('X-Requested-With'), true);
switch ($this->state) {
case self::ONLY_XHR:
if (!$isXHR) {
return null;
}
break;
case self::ONLY_NO_XHR:
if ($isXHR) {
return null;
}
break;
}
return $next($request);
}
示例10: getPayloadFromRequest
/**
* Get request payload from request object.
*
* @todo check $request->getHeaderLine('content-type') ??
*
* @param RequestInterface $request
* @return array
*
* @throws \Exception
*/
private function getPayloadFromRequest(RequestInterface $request)
{
$contentType = $request->getHeader('Content-Type');
$expected = 'application/json; charset=UTF-8';
if (empty($contentType) || $expected != $contentType[0]) {
throw new \Exception('Expected Content-Type: ' . $expected);
}
$payload = json_decode($request->getBody(), true);
switch (json_last_error()) {
case JSON_ERROR_DEPTH:
throw new \Exception('Invalid JSON, maximum stack depth exceeded.', 400);
case JSON_ERROR_UTF8:
throw new \Exception('Malformed UTF-8 characters, possibly incorrectly encoded.', 400);
case JSON_ERROR_SYNTAX:
case JSON_ERROR_CTRL_CHAR:
case JSON_ERROR_STATE_MISMATCH:
throw new \Exception('Invalid JSON.', 400);
}
return is_null($payload) ? [] : $payload;
}
示例11: handshake
/**
* {@inheritdoc}
*/
public function handshake(RequestInterface $request)
{
if (true !== $this->verifier->verifyMethod($request->getMethod())) {
return new Response(405);
}
if (true !== $this->verifier->verifyHTTPVersion($request->getProtocolVersion())) {
return new Response(505);
}
if (true !== $this->verifier->verifyRequestURI($request->getUri()->getPath())) {
return new Response(400);
}
if (true !== $this->verifier->verifyHost($request->getHeader('Host'))) {
return new Response(400);
}
if (true !== $this->verifier->verifyUpgradeRequest($request->getHeader('Upgrade'))) {
return new Response(400, [], '1.1', null, 'Upgrade header MUST be provided');
}
if (true !== $this->verifier->verifyConnection($request->getHeader('Connection'))) {
return new Response(400, [], '1.1', null, 'Connection header MUST be provided');
}
if (true !== $this->verifier->verifyKey($request->getHeader('Sec-WebSocket-Key'))) {
return new Response(400, [], '1.1', null, 'Invalid Sec-WebSocket-Key');
}
if (true !== $this->verifier->verifyVersion($request->getHeader('Sec-WebSocket-Version'))) {
return new Response(426, ['Sec-WebSocket-Version' => $this->getVersionNumber()]);
}
$headers = [];
$subProtocols = $request->getHeader('Sec-WebSocket-Protocol');
if (count($subProtocols) > 0 || count($this->_supportedSubProtocols) > 0 && $this->_strictSubProtocols) {
$subProtocols = array_map('trim', explode(',', implode(',', $subProtocols)));
$match = array_reduce($subProtocols, function ($accumulator, $protocol) {
return $accumulator ?: (isset($this->_supportedSubProtocols[$protocol]) ? $protocol : null);
}, null);
if ($this->_strictSubProtocols && null === $match) {
return new Response(400, [], '1.1', null, 'No Sec-WebSocket-Protocols requested supported');
}
if (null !== $match) {
$headers['Sec-WebSocket-Protocol'] = $match;
}
}
return new Response(101, array_merge($headers, ['Upgrade' => 'websocket', 'Connection' => 'Upgrade', 'Sec-WebSocket-Accept' => $this->sign((string) $request->getHeader('Sec-WebSocket-Key')[0]), 'X-Powered-By' => 'RxPHPWebsocket']));
}
示例12: adapt
public function adapt(array $tokens = [], $status = 200, array $headers = [])
{
list($contentType, $body) = $this->encoder->encode($this->request->getHeader('Accept'), $tokens);
return new Response($this->asStream($body), $status, $this->getHeadersForResponse($contentType, $headers));
}
示例13: getRequestHostHeader
/**
* @param RequestInterface $request
*
* @return null|string
*/
private function getRequestHostHeader(RequestInterface $request)
{
$hostHeaderValue = $request->getHeader(CorsRequestHeaders::HOST);
$host = empty($hostHeaderValue) === true ? null : $hostHeaderValue[0];
return $host;
}
示例14: 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;
}
示例15: remove
/**
* @param Request $request
* @param Response $response
* @param $args
* @return Response
* @throws \Doctrine\ORM\EntityNotFoundException
*/
public function remove(Request $request, Response $response, $args)
{
foreach (explode(',', $request->getHeader('id')[0]) as $id) {
$ticket = $this->em->find('App\\Entity\\Ticket', $id);
if ($ticket) {
$this->em->remove($ticket);
} else {
throw new EntityNotFoundException();
}
}
$this->em->flush();
return $response;
}