本文整理汇总了PHP中Psr\Http\Message\ServerRequestInterface::getHeaderLine方法的典型用法代码示例。如果您正苦于以下问题:PHP ServerRequestInterface::getHeaderLine方法的具体用法?PHP ServerRequestInterface::getHeaderLine怎么用?PHP ServerRequestInterface::getHeaderLine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Psr\Http\Message\ServerRequestInterface
的用法示例。
在下文中一共展示了ServerRequestInterface::getHeaderLine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: dispatch
/**
* Run Controller
*
* @param ServerRequestInterface $request PSR7 Request object
* @param ResponseInterface $response PSR7 Response object
* @param array $args Request arguments
* @return ResponseInterface
*/
public function dispatch(Request $request, Response $response, $args)
{
$netid = $request->getHeaderLine('AUTH_PRINCIPAL');
$eppa = $request->getHeaderLine('AUTH_ATTR_EDUPERSONPRIMARYAFFILIATION');
$albumID = $args['album_id'] ?? $request->getQueryParams()['album'] ?? 1;
$view_attr = ['page_title' => 'SlimSkeleton | Example', 'username' => $netid, 'eppa' => $eppa, 'data' => $this->service->getPhotos($albumID)];
return $this->view->render($response, 'example.html', $view_attr);
}
示例2: it_can_parse_a_HttpRequest
public function it_can_parse_a_HttpRequest(ServerRequestInterface $httpRequest)
{
$token = Uuid::uuid4()->toString();
$passCode = bin2hex(random_bytes(20));
$httpRequest->getHeaderLine('Accept')->shouldBeCalled();
$httpRequest->getHeaderLine('Authentication-Token')->willReturn($token);
$httpRequest->getHeaderLine('Authentication-Pass-Code')->willReturn($passCode);
$request = $this->parseHttpRequest($httpRequest, []);
$request->shouldHaveType(RequestInterface::class);
$request->getRequestName()->shouldReturn(RefreshTokenHandler::MESSAGE);
$request['token']->shouldBe($token);
$request['pass_code']->shouldBe($passCode);
}
示例3: isExcluded
/**
* {@inheritdoc}
*
* @throws \RuntimeException
*/
public function isExcluded(ServerRequestInterface $request)
{
if (!count($this->headers)) {
throw new \RuntimeException('No headers defined in header excluder');
}
foreach ($this->headers as $header => $value) {
if ($value === null && $request->hasHeader($header)) {
return true;
} elseif ($value !== null && (trim($value) === $request->getHeaderLine($header) || @preg_match(trim($value), $request->getHeaderLine($header)))) {
return true;
}
}
return false;
}
示例4: fromPsrRequest
/**
* attempt to build up a request from a PSR-7 compatible request
*
* @param ServerRequestInterface $request
* @return Request
*/
public static function fromPsrRequest(ServerRequestInterface $request)
{
$url = (string) $request->getUri();
$httpMethod = $request->getMethod();
// Let's find the parameters relevant to this request
$parameters = (array) $request->getParsedBody() + $request->getQueryParams();
// We have a Authorization-header with OAuth data. Parse the header
// and add those overriding any duplicates from GET or POST
if (substr($request->getHeaderLine('Authorization'), 0, 6) == 'OAuth ') {
$header_parameters = Util::splitHeader($request->getHeaderLine('Authorization'));
$parameters = array_merge($parameters, $header_parameters);
}
return new Request($httpMethod, $url, $parameters);
}
示例5: __invoke
public function __invoke(Request $req, Response $res, $args = [])
{
$vaultName = $args['vaultName'];
if (!($vault = Vault::get($vaultName))) {
return $res->withStatus(404);
}
if (!($partSize = $req->getHeaderLine('x-amz-part-size'))) {
return $res->withStatus(400)->write('Part size missing.');
}
if (!($desc = $req->getHeaderLine('x-amz-archive-description'))) {
$desc = '';
}
$m = $vault->createMultipart($partSize, $desc);
return $res->withStatus(201)->withHeader('x-amz-multipart-upload-id', $m->getId());
}
示例6: __invoke
/**
* Invoking the middleware
*
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @param callable $next
* @return ResponseInterface $response
* @throws InternalServerError
* @throws UnsupportedMediaType
*/
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null)
{
// Make sure we have deserializers
if (!isset($this->container['contentTypes'])) {
throw new InternalServerError('No serializers seems to be configured');
}
// Make sure we have a content type header to work with
if ($request->hasHeader('Content-Type')) {
// Get the content of the header
$header = $request->getHeaderLine('Content-Type');
// Make sure the header value isn't empty
if (!empty($header)) {
// Get priorities
$supported = $this->container['contentTypes'];
// Remove included parts that aren't part of the RFC
$header = preg_replace('/(;[a-z]*=[a-z0-9\\-]*)/i', '', $header);
// Replace the original header value
$request = $request->withHeader('Content-Type', $header);
// Check if the content type is supported
if (!in_array($header, $supported)) {
// The content type isn't supported
throw new UnsupportedMediaType('Can not handle the supplied content type. Supported types are ' . implode(', ', $supported));
}
}
}
// Call next middleware
return $next($request, $response, $next);
}
示例7: logIn
/**
* @param Request $request
* @return Request
*/
protected function logIn(Request $request)
{
$header = $request->getHeaderLine('authorization');
$parts = explode(';', $header);
$actor = new Guest();
if (isset($parts[0]) && starts_with($parts[0], $this->prefix)) {
$token = substr($parts[0], strlen($this->prefix));
if (($accessToken = AccessToken::find($token)) && $accessToken->isValid()) {
$actor = $accessToken->user;
$actor->updateLastSeen()->save();
} elseif (isset($parts[1]) && ($apiKey = ApiKey::valid($token))) {
$userParts = explode('=', trim($parts[1]));
if (isset($userParts[0]) && $userParts[0] === 'userId') {
$actor = User::find($userParts[1]);
}
}
}
if ($actor->exists) {
$locale = $actor->getPreference('locale');
} else {
$locale = array_get($request->getCookieParams(), 'locale');
}
if ($locale && $this->locales->hasLocale($locale)) {
$this->locales->setLocale($locale);
}
return $request->withAttribute('actor', $actor ?: new Guest());
}
示例8: __invoke
/**
* {@inheritdoc}
*/
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, \Closure $next)
{
if ($request->getHeaderLine('Content-Type') == 'application/json') {
$request = $request->withParsedBody(json_decode($request->getBody()->__toString(), true));
}
return $next($request);
}
示例9: __invoke
/**
* {@inheritdoc}
*/
public function __invoke(Request $request, Response $response, callable $out = null)
{
if (str_contains($request->getHeaderLine('content-type'), 'json')) {
$input = json_decode($request->getBody(), true);
$request = $request->withParsedBody($input ?: []);
}
return $out ? $out($request, $response) : $response;
}
示例10: modify
public function modify(ServerRequestInterface $request) : ServerRequestInterface
{
if (false === strpos($request->getHeaderLine('Content-Type'), 'application/json')) {
return $request;
}
// TODO: Implement broken json handling
return $request->withParsedBody(json_decode($request->getBody()->getContents(), $this->asAssociativeArray));
}
示例11: __invoke
/**
* {@inheritdoc}
*/
public function __invoke(Request $request, Response $response, callable $out = null)
{
if ($request->getMethod() === 'POST' && $request->hasHeader(self::HEADER_NAME)) {
$fakeMethod = $request->getHeaderLine(self::HEADER_NAME);
$request = $request->withMethod(strtoupper($fakeMethod));
}
return $out ? $out($request, $response) : $response;
}
示例12: __invoke
/**
* Execute the middleware.
*
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @param callable $next
*
* @return ResponseInterface
*/
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
{
$authorization = self::parseAuthorizationHeader($request->getHeaderLine('Authorization'));
if ($authorization && $this->checkUserPassword($authorization['username'], $authorization['password'])) {
return $next(Middleware::setAttribute($request, self::KEY, $authorization['username']), $response);
}
return $response->withStatus(401)->withHeader('WWW-Authenticate', 'Basic realm="' . $this->realm . '"');
}
示例13: isNotModified
/**
* Check the not modified header.
*
* @param \Psr\Http\Message\ServerRequestInterface $request The request to check.
* @param \Cake\Filesystem\File $file The file object to compare.
* @return bool
*/
protected function isNotModified($request, $file)
{
$modifiedSince = $request->getHeaderLine('If-Modified-Since');
if (!$modifiedSince) {
return false;
}
return strtotime($modifiedSince) === $file->lastChange();
}
示例14: getAuth
/**
* Retrieve request authentication information.
*
* @param ServerRequestInterface $request
*
* @return array
*/
protected function getAuth(ServerRequestInterface $request)
{
$authHeader = $request->getHeaderLine('Authorization');
if (preg_match('/^Basic /', $authHeader)) {
$auth = explode(':', base64_decode(substr($authHeader, 6)), 2);
return ['username' => $auth[0], 'password' => isset($auth[1]) ? $auth[1] : null];
}
}
示例15: isValid
/**
* Validate authorization token
* @param Request $request
* @return boolean
*/
private function isValid(Request $request)
{
$token = $request->getHeaderLine('authorization');
if ($token == 'pasando') {
return true;
}
return false;
}