本文整理汇总了PHP中Psr\Http\Message\RequestInterface::getHeaderLine方法的典型用法代码示例。如果您正苦于以下问题:PHP RequestInterface::getHeaderLine方法的具体用法?PHP RequestInterface::getHeaderLine怎么用?PHP RequestInterface::getHeaderLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Psr\Http\Message\RequestInterface
的用法示例。
在下文中一共展示了RequestInterface::getHeaderLine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: signRequest
public function signRequest(RequestInterface $request, CredentialsInterface $credentials)
{
$params = Psr7\parse_query($request->getBody());
$params['Timestamp'] = gmdate('c');
$params['SignatureVersion'] = '2';
$params['SignatureMethod'] = 'HmacSHA256';
$params['AWSAccessKeyId'] = $credentials->getAccessKeyId();
if ($token = $credentials->getSecurityToken()) {
$params['SecurityToken'] = $token;
}
// build string to sign
$sign = $request->getMethod() . "\n" . $request->getHeaderLine('Host') . "\n" . '/' . "\n" . $this->getCanonicalizedParameterString($params);
$params['Signature'] = base64_encode(hash_hmac('sha256', $sign, $credentials->getSecretKey(), true));
return $request->withBody(Psr7\stream_for(http_build_query($params)));
}
示例2: signResponse
/**
* {@inheritDoc}
*/
public function signResponse(ResponseInterface $response)
{
$authHeader = AuthorizationHeader::createFromRequest($this->request);
$parts = [$authHeader->getNonce(), $this->request->getHeaderLine('X-Authorization-Timestamp'), (string) $response->getBody()];
$message = implode("\n", $parts);
$signature = $this->digest->sign($message, $this->key->getSecret());
/** @var \Psr\Http\Message\ResponseInterface $response */
$response = $response->withHeader('X-Server-Authorization-HMAC-SHA256', $signature);
return $response;
}
示例3: getOverrideMethod
/**
* Returns the override method.
*
* @param RequestInterface $request
*
* @return string|null
*/
private function getOverrideMethod(RequestInterface $request)
{
$method = $request->getHeaderLine(self::HEADER);
if (!empty($method) && $method !== $request->getMethod()) {
return strtoupper($method);
}
}
示例4: renderRequest
/**
* Render a PSR-7 request.
*
* @param RequestInterface $request
* @return string
*/
public function renderRequest(RequestInterface $request)
{
$return = '';
$return .= sprintf("URL: %s\n", $request->getUri());
$return .= sprintf("METHOD: %s\n", $request->getMethod());
if ($request->getHeaders()) {
$return .= 'HEADERS:';
}
$indent = false;
foreach ($request->getHeaders() as $name => $values) {
if ($indent) {
$return .= str_repeat(' ', 8);
}
$return .= sprintf(" %s: %s\n", $name, implode(', ', $values));
$indent = true;
}
if ($body = (string) $request->getBody()) {
$return .= 'BODY: ';
switch ($request->getHeaderLine('Content-Type')) {
case 'application/json':
$return .= json_encode(json_decode($body, true), JSON_PRETTY_PRINT);
break;
default:
$return .= $body;
break;
}
$return .= "\n";
}
return $return;
}
示例5: getRequestHeaders
/**
* @param RequestInterface $request
* @return string[]
*/
protected function getRequestHeaders(RequestInterface $request)
{
$headers = array();
foreach (array_keys($request->getHeaders()) as $name) {
$headers[] = $name . ': ' . $request->getHeaderLine($name);
}
return $headers;
}
示例6: isAcceptable
/**
* Is the strategy acceptable for this request?
*
* @param \Psr\Http\Message\RequestInterface $request The request
*
* @return bool Returns true on success, false otherwise
*/
public function isAcceptable(RequestInterface $request)
{
$accept = $request->getHeaderLine('Accept');
if ($accept && preg_match('#^application/([^+\\s]+\\+)?json#', $accept)) {
return true;
}
return false;
}
示例7: __invoke
/**
* Execute the middleware.
*
* @param RequestInterface $request
* @param ResponseInterface $response
* @param callable $next
*
* @return ResponseInterface
*/
public function __invoke(RequestInterface $request, ResponseInterface $response, callable $next)
{
$authorization = self::parseAuthorizationHeader($request->getHeaderLine('Authorization'));
if ($authorization && $this->checkUserPassword($authorization['username'], $authorization['password'])) {
return $next($request, $response);
}
return $response->withStatus(401)->withHeader('WWW-Authenticate', 'Basic realm="' . $this->realm . '"');
}
示例8: render
public function render(RequestInterface $request, ResponseInterface $response, $data)
{
$mediaType = $this->determineMediaType($request->getHeaderLine('Accept'));
$output = $this->renderOutput($mediaType, $data);
$response = $this->writeBody($response, $output);
$response = $response->withHeader('Content-type', $mediaType);
return $response;
}
示例9: detect
public function detect()
{
if ($this->detected === null) {
$headers = $this->request->getHeaders();
$userAgent = $this->request->getHeaderLine('user-agent');
if ($this->detector->isMobile($headers, $userAgent)) {
$this->detected = 'mobile';
} else {
if ($this->detector->isTablet($headers, $userAgent)) {
$this->detected = 'tablet';
} else {
$this->detected = 'desktop';
}
}
}
return $this->detected;
}
示例10: normalizeCustomHeaders
/**
* Normalizes the custom headers for signing.
*
* @return string[]
* An array of normalized headers.
*/
protected function normalizeCustomHeaders()
{
$headers = [];
// The spec requires that headers are sorted by header name.
sort($this->headers);
foreach ($this->headers as $header) {
if ($this->request->hasHeader($header)) {
$headers[] = strtolower($header) . ':' . $this->request->getHeaderLine($header);
}
}
return $headers;
}
示例11: forgeServerGlobal
/**
* Take a request and update the $_SERVER global to match
*
* @param RequestInterface $request
*/
private function forgeServerGlobal(RequestInterface $request)
{
$_SERVER['REQUEST_URI'] = $request->getUri()->getPath();
$_SERVER['REQUEST_METHOD'] = $request->getMethod();
$_SERVER['QUERY_STRING'] = $request->getUri()->getQuery();
if ($request->hasHeader('Content-Type')) {
$_SERVER['CONTENT_TYPE'] = $request->getHeaderLine('Content-Type');
}
if ($request->hasHeader('Referer')) {
$_SERVER['HTTP_REFERER'] = $request->getHeaderLine('Referer');
}
if ($request->hasHeader('X-Requested-with')) {
$_SERVER['HTTP_X_REQUESTED_WITH'] = $request->getHeaderLine('X-Requested-With');
}
if ($request->hasHeader('User-Agent')) {
$_SERVER['HTTP_USER_AGENT'] = $request->getHeaderLine('User-Agent');
}
if ($request->hasHeader('X-Forwarded-For')) {
$_SERVER['HTTP_X_FORWARDED_FOR'] = $request->getHeaderLine('X-Forwarded-For');
}
return $this;
}
示例12: render
public function render(RequestInterface $request, ResponseInterface $response, $data)
{
$mediaType = $this->determineMediaType($request->getHeaderLine('Accept'));
$mediaSubType = explode('/', $mediaType)[1];
$dataIsValidForMediatype = $this->isDataValidForMediaType($mediaSubType, $data);
if (!$dataIsValidForMediatype) {
throw new RuntimeException('Data for mediaType ' . $mediaType . ' must be ' . implode($this->mediaSubtypesToAllowedDataTypesMap[$mediaSubType], ' or '));
}
$output = $this->renderOutput($mediaType, $data);
$response = $this->writeBody($response, $output);
$response = $response->withHeader('Content-type', $mediaType);
return $response;
}
示例13: login
/**
* Login or check the user credentials.
*
* @param RequestInterface $request
*
* @return bool
*/
private function login(RequestInterface $request)
{
//Check header
$authorization = self::parseAuthorizationHeader($request->getHeaderLine('Authorization'));
if (!$authorization) {
return false;
}
//Check whether user exists
if (!isset($this->users[$authorization['username']])) {
return false;
}
//Check authentication
return $this->checkAuthentication($authorization, $request->getMethod(), $this->users[$authorization['username']]);
}
示例14: render
public function render(RequestInterface $request, ResponseInterface $response, $data)
{
$contentType = $this->determineMediaType($request->getHeaderLine('Accept'));
$output = $this->renderOutput($contentType, $data);
$response = $this->writeBody($response, $output);
// set the HAL content type for JSON or XML
if (stripos($contentType, 'json')) {
$contentType = 'application/hal+json';
} elseif (stripos($contentType, 'xml')) {
$contentType = 'application/hal+xml';
}
$response = $response->withHeader('Content-type', $contentType);
return $response;
}
示例15: assertValidBody
/**
* @param RequestInterface $request
*/
private function assertValidBody(RequestInterface $request)
{
$body = $request->getBody()->getContents();
$method = $request->getMethod();
$path = $request->getUri()->getPath();
$contentType = $request->getHeaderLine('Content-Type');
$schemaBody = $this->schemaHelper->getRequestBody($method, $path, $contentType);
try {
$schemaBody->getSchema()->validate($body);
} catch (InvalidSchemaException $exception) {
$message = sprintf('Request body for %s %s with content type %s does not match schema: %s', strtoupper($method), $path, $contentType, $this->getSchemaErrorsAsString($exception->getErrors()));
throw new ValidatorRequestException($message, 0, $exception);
}
}