本文整理汇总了PHP中Psr\Http\Message\ServerRequestInterface::getHeaders方法的典型用法代码示例。如果您正苦于以下问题:PHP ServerRequestInterface::getHeaders方法的具体用法?PHP ServerRequestInterface::getHeaders怎么用?PHP ServerRequestInterface::getHeaders使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Psr\Http\Message\ServerRequestInterface
的用法示例。
在下文中一共展示了ServerRequestInterface::getHeaders方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getData
/**
* {@inheritdoc}
*/
public function getData()
{
$headers = [];
foreach ($this->request->getHeaders() as $name => $values) {
$headers[$name] = implode(', ', $values);
}
$data = ['SERVER' => $this->request->getServerParams(), 'QUERY' => $this->request->getQueryParams(), 'COOKIES' => $this->request->getCookieParams(), 'HEADERS' => $headers, 'ATTRIBUTES' => $this->request->getAttributes()];
return $data;
}
示例2: toZend
/**
* Convert a PSR-7 ServerRequest to a Zend\Http server-side request.
*
* @param ServerRequestInterface $psr7Request
* @param bool $shallow Whether or not to convert without body/file
* parameters; defaults to false, meaning a fully populated request
* is returned.
* @return Zend\Request
*/
public static function toZend(ServerRequestInterface $psr7Request, $shallow = false)
{
if ($shallow) {
return new Zend\Request($psr7Request->getMethod(), $psr7Request->getUri(), $psr7Request->getHeaders(), $psr7Request->getCookieParams(), $psr7Request->getQueryParams(), [], [], $psr7Request->getServerParams());
}
$zendRequest = new Zend\Request($psr7Request->getMethod(), $psr7Request->getUri(), $psr7Request->getHeaders(), $psr7Request->getCookieParams(), $psr7Request->getQueryParams(), $psr7Request->getParsedBody() ?: [], self::convertUploadedFiles($psr7Request->getUploadedFiles()), $psr7Request->getServerParams());
$zendRequest->setContent($psr7Request->getBody());
return $zendRequest;
}
示例3: getHeaders
public function getHeaders()
{
if (!isset($this->headers)) {
$this->headers = array();
foreach ($this->request->getHeaders() as $header => $values) {
$this->headers[strtolower($header)] = end($values);
}
}
return $this->headers;
}
示例4: createRequest
/**
* {@inheritdoc}
*/
public function createRequest(ServerRequestInterface $psrRequest)
{
$parsedBody = $psrRequest->getParsedBody();
$parsedBody = is_array($parsedBody) ? $parsedBody : array();
$request = new Request($psrRequest->getQueryParams(), $parsedBody, $psrRequest->getAttributes(), $psrRequest->getCookieParams(), $this->getFiles($psrRequest->getUploadedFiles()), $psrRequest->getServerParams(), $psrRequest->getBody()->__toString());
$request->headers->replace($psrRequest->getHeaders());
return $request;
}
示例5: convertRequestFromPsr7
/**
* Converts a PSR-7 request into an OAuth2 request.
*
* @param ServerRequestInterface $psrRequest
* @return Request
*/
public static function convertRequestFromPsr7(ServerRequestInterface $psrRequest)
{
$headers = [];
foreach ($psrRequest->getHeaders() as $header => $value) {
$headers[$header] = implode(';', $value);
}
return new Request($psrRequest->getQueryParams(), is_array($psrRequest->getParsedBody()) ? $psrRequest->getParsedBody() : [], $psrRequest->getAttributes(), $psrRequest->getCookieParams(), self::getFiles($psrRequest->getUploadedFiles()), $psrRequest->getServerParams(), $psrRequest->getBody()->__toString(), $headers);
}
示例6: headers
/**
* Headers
* @return \PHPixie\HTTP\Data\Headers
*/
public function headers()
{
if ($this->headers === null) {
$data = $this->serverRequest->getHeaders();
$this->headers = $this->builder->headers($data);
}
return $this->headers;
}
示例7: createRequest
public static function createRequest(PsrServerRequestInterface $psrRequest)
{
$request = new Request(new Uri($psrRequest->getUri()), $psrRequest->getMethod(), $psrRequest->getHeaders(), $psrRequest->getBody());
$attributes = $psrRequest->getAttributes();
foreach ($attributes as $name => $value) {
$request->setAttribute($name, $value);
}
return $request;
}
示例8: __invoke
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null)
{
$tokenHeader = $request->getHeader('X-Auth-Token');
if (count($tokenHeader) > 0) {
$tokenHeaderValue = $tokenHeader[0];
} else {
$tokenHeaderValue = null;
}
$data = array('requestMethod' => $request->getMethod(), 'requestUri' => $request->getRequestTarget(), 'queryParams' => $request->getQueryParams(), 'formParams' => $request->getParsedBody(), 'rawBody' => (string) $request->getBody(), 'headers' => $request->getHeaders(), 'X-Auth-Token' => $tokenHeaderValue);
return new JsonResponse($data);
}
示例9: prettifyRequest
/**
* @param \Psr\Http\Message\ServerRequestInterface $request
* @return string
*/
protected function prettifyRequest(ServerRequestInterface $request)
{
$contents = "{$request->getMethod()} : {$request->getUri()->__toString()}\n";
$contents .= "HEADERS\n";
foreach ($request->getHeaders() as $name => $value) {
$contents .= " {$name} : {$request->getHeaderLine($name)}\n";
}
if ($body = $request->getBody()) {
$contents .= "BODY\n";
$contents .= "\"{$body->__toString()}\"\n";
}
return $contents;
}
示例10: __construct
/**
* Construct action request.
*
* @param \Psr\Http\Message\ServerRequestInterface $request Request to wrap.
*/
public function __construct(\Psr\Http\Message\ServerRequestInterface $request)
{
parent::__construct($request->getBody());
foreach ($request->getHeaders() as $name => $value) {
$this->setHeader($name, $value);
}
$this->protocolVersion = $request->getProtocolVersion();
$this->method = $request->getMethod();
$this->requestTarget = $request->getRequestTarget();
$this->uri = $request->getUri();
$this->attributes = $request->getAttributes();
$this->cookies = $request->getCookieParams();
$this->data = $request->getParsedBody();
$this->query = $request->getQueryParams();
$this->server = $request->getServerParams();
$this->files = $request->getUploadedFiles();
if (isset($this->server['SCRIPT_NAME'])) {
$this->attributes['basePath'] = dirname($this->server['SCRIPT_NAME']);
$this->attributes['scriptName'] = basename($this->server['SCRIPT_NAME']);
} else {
$this->attributes['basePath'] = '/';
$this->attributes['scriptName'] = 'index.php';
}
if (!isset($this->attributes['path'])) {
$this->attributes['path'] = self::findPath($this);
}
if (!isset($this->attributes['rewrite'])) {
$this->attributes['rewrite'] = false;
}
if (!isset($this->attributes['accepts'])) {
$this->attributes['accepts'] = [];
if (isset($this->server['HTTP_ACCEPT'])) {
$contentTypes = explode(',', $this->server['HTTP_ACCEPT']);
foreach ($contentTypes as $contentType) {
$contentType = explode(';', $contentType);
$this->attributes['accepts'][] = trim(strtolower($contentType[0]));
}
}
}
if (!isset($this->attributes['encodings'])) {
$this->attributes['encodings'] = [];
if (isset($this->server['HTTP_ACCEPT_ENCODING'])) {
$acceptEncodings = explode(',', $this->server['HTTP_ACCEPT_ENCODING']);
foreach ($acceptEncodings as $encoding) {
$this->attributes['encodings'][] = trim(strtolower($encoding));
}
}
}
}
示例11: send
/**
* @param ServerRequestInterface $request
*/
public function send(ServerRequestInterface $request)
{
$this->currentUri = $request->getUri();
$this->setBase($this->currentUri);
if (empty($this->currentUri->getHost())) {
$this->currentUri = new Uri($this->getBase() . $this->currentUri);
}
$curl = curl_init();
$options = [CURLOPT_URL => (string) $this->currentUri, CURLOPT_FOLLOWLOCATION => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_CUSTOMREQUEST => $request->getMethod(), CURLOPT_USERAGENT => Loader::USER_AGENT, CURLOPT_HEADER => true, CURLOPT_HTTPHEADER => $this->getConvertedHeaders($request->getHeaders())];
if ($request->getBody()->getSize()) {
$options[CURLOPT_POSTFIELDS] = (string) $request->getBody();
}
curl_setopt_array($curl, $options);
$response = curl_exec($curl);
$this->currentUri = new Uri(curl_getinfo($curl, CURLINFO_EFFECTIVE_URL));
return \GuzzleHttp\Psr7\parse_response($response);
}
示例12: createRequest
/**
* {@inheritdoc}
*/
public function createRequest(ServerRequestInterface $psrRequest)
{
$server = array();
$uri = $psrRequest->getUri();
if ($uri instanceof UriInterface) {
$server['SERVER_NAME'] = $uri->getHost();
$server['SERVER_PORT'] = $uri->getPort();
$server['REQUEST_URI'] = $uri->getPath();
$server['QUERY_STRING'] = $uri->getQuery();
}
$server['REQUEST_METHOD'] = $psrRequest->getMethod();
$server = array_replace($server, $psrRequest->getServerParams());
$parsedBody = $psrRequest->getParsedBody();
$parsedBody = is_array($parsedBody) ? $parsedBody : array();
$request = new Request($psrRequest->getQueryParams(), $parsedBody, $psrRequest->getAttributes(), $psrRequest->getCookieParams(), $this->getFiles($psrRequest->getUploadedFiles()), $server, $psrRequest->getBody()->__toString());
$request->headers->replace($psrRequest->getHeaders());
return $request;
}
示例13: responseRaidsAdd
public function responseRaidsAdd(Request $request, Response $response)
{
$aRequest = $request->getParsedBody();
$aHeader = $request->getHeaders();
// @todo: validation of input params
$sUserName = $aHeader['HTTP_X_AUTH_USER'];
$sToken = $aHeader['HTTP_X_AUTH_TOKEN'];
if (!$this->oUser->checkUserToken($sToken)) {
return $response->withStatus(401);
}
/**
* @var Raid
*/
$oRaid = new Raid();
$bSuccess = $oRaid->generateUuid()->setTitle($aRequest['title'])->setStart($aRequest['raidDate'], $aRequest['startTime'])->setEnd($aRequest['raidDate'], $aRequest['endTime'])->setMaxAttendees($aRequest['maxAttendees'])->save();
$aResponse = [self::RESPONSE_SUCCESS => $bSuccess, 'uuid' => $oRaid->getUuid()];
$response->getBody()->write(json_encode($aResponse));
return $response;
}
示例14: render
/**
* Render an exception into an HTTP or JSON response.
*
* @param Request $request
* @param Response $response
* @param \Exception $exception
* @return mixed
*/
public function render(Request $request, Response $response, \Exception $exception)
{
$statusCode = method_exists($exception, 'getStatusCode') ? $exception->getStatusCode() : 400;
$response->withStatus($statusCode);
$debug = $this->settings['displayErrorDetails'] == 'true' ? true : false;
$title = $debug ? 'The application could not run because of the following error:' : 'A website error has occurred. Sorry for the temporary inconvenience.';
$header = $request->getHeaders();
$message = $exception->getMessage();
$json = isset($header['HTTP_CONTENT_TYPE'][0]) && $header['HTTP_CONTENT_TYPE'][0] == 'application/json';
// Check content-type is application/json
if ($json) {
// Define content-type to json
$response->withHeader('Content-Type', 'application/json');
$error = ['status' => 'error', 'error' => $title, 'statusCode' => $statusCode];
// Check debug
if ($debug) {
$error['details'] = ['message' => $message, 'file' => $exception->getFile(), 'line' => $exception->getLine(), 'code' => $exception->getCode()];
}
$view = $this->json->render($response, $error, $statusCode);
} else {
// Define content-type to html
$response->withHeader('Content-Type', 'text/html');
$message = sprintf('<span>%s</span>', htmlentities($message));
$error = ['type' => get_class($exception), 'message' => $message];
// Check debug
if ($debug) {
$trace = $exception->getTraceAsString();
$trace = sprintf('<pre>%s</pre>', htmlentities($trace));
$error['file'] = $exception->getFile();
$error['line'] = $exception->getLine();
$error['code'] = $exception->getCode();
$error['trace'] = $trace;
}
$error['debug'] = $debug;
$error['title'] = $title;
$view = $this->view->render($response, 'error/error.twig', $error);
}
// Send error to log
$this->log->addError($exception->getMessage());
return $view;
}
示例15: getHeaders
/**
* {@inheritdoc}
*/
public function getHeaders()
{
return $this->wrapped->getHeaders();
}