本文整理汇总了PHP中Zend\Http\PhpEnvironment\Request::getHeaders方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::getHeaders方法的具体用法?PHP Request::getHeaders怎么用?PHP Request::getHeaders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Http\PhpEnvironment\Request
的用法示例。
在下文中一共展示了Request::getHeaders方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: headers
/**
* @param string $name
* @param mixed $default
* @return mixed
*/
public function headers($name, $default = null)
{
//The RequestInterface expects this method to also return PHP_AUTH variables
if (strpos($name, 'PHP_AUTH_') === 0) {
return $this->server($name, $default);
}
$header = $this->httpRequest->getHeaders($name);
if (!$header) {
return $default;
}
return $header->getFieldValue();
}
示例2: testHeadersWithMinus
/**
* @dataProvider serverHeaderProvider
* @param array $server
* @param string $name
* @param string $value
*/
public function testHeadersWithMinus(array $server, $name, $value)
{
$_SERVER = $server;
$request = new Request();
$header = $request->getHeaders()->get($name);
$this->assertNotEquals($header, false);
$this->assertEquals($name, $header->getFieldName($value));
$this->assertEquals($value, $header->getFieldValue($value));
}
示例3: checkHeader
private function checkHeader()
{
foreach (parent::getHeaders() as $header) {
$name = $header->getFieldName();
$value = $header->getFieldValue();
$name = $this->headerToParam($name);
$this->headerParameters[$name] = $value;
}
}
示例4: getBrowserLocale
/**
* Detect language by browser headers
*
* @return string
*/
private function getBrowserLocale()
{
$locales = $this->request->getHeaders('Accept-Language')->getPrioritized();
foreach ($locales as $lng) {
if (in_array($lng->type, $this->getAvailableLocales())) {
return $lng->type;
}
}
return Config::$lng;
}
示例5: createFromRequest
public static function createFromRequest(BaseRequest $request)
{
$new = static::fromString($request->toString());
$new->setQuery($request->getQuery());
$new->setPost($request->getPost());
$new->setCookies($request->getCookie());
$new->setFiles($request->getFiles());
$new->setServer($request->getServer());
$new->setContent($request->getContent());
$new->setEnv($request->getEnv());
$headers = $request->getHeaders();
$new->setHeaders($headers);
return $new;
}
示例6: _getBasicAuthData
/**
* fetch basic auth credentials
*
* @param \Zend\Http\PhpEnvironment\Request $request
* @return array
*/
protected function _getBasicAuthData(\Zend\Http\PhpEnvironment\Request $request)
{
if ($header = $request->getHeaders('Authorization')) {
return explode(":", base64_decode(substr($header->getFieldValue(), 6)), 2);
} elseif ($header = $request->getServer('HTTP_AUTHORIZATION')) {
return explode(":", base64_decode(substr($header, 6)), 2);
} else {
// check if (REDIRECT_)*REMOTE_USER is found in SERVER vars
$name = 'REMOTE_USER';
for ($i = 0; $i < 5; $i++) {
if ($header = $request->getServer($name)) {
return explode(":", base64_decode(substr($header, 6)), 2);
}
$name = 'REDIRECT_' . $name;
}
}
}
示例7: write
/**
* Запись логов
* @param Request $request
* @param Response $response
*/
public function write($request, $response)
{
$serverOptions = $request->getServer()->toArray();
$requestUri = isset($serverOptions['REQUEST_URI']) ? $serverOptions['REQUEST_URI'] : null;
// Проверка на запись от правильного запроса
if (is_null($requestUri) || !preg_match($this->_patternRequestWriteLog, $requestUri)) {
return;
}
$remoteAddr = isset($serverOptions['REMOTE_ADDR']) ? $serverOptions['REMOTE_ADDR'] : '';
$requestTime = isset($serverOptions['REQUEST_TIME']) ? $serverOptions['REQUEST_TIME'] : 0;
$requestTimeFloat = isset($serverOptions['REQUEST_TIME_FLOAT']) ? $serverOptions['REQUEST_TIME_FLOAT'] : 0;
/** @var DocumentManager $dm */
$dm = $this->getServiceLocator()->get('doctrine-document');
$logsClient = new LogsClient();
$logsClient->setDatetime((new \DateTime())->setTimestamp($requestTime))->setHeaders($request->getHeaders()->toString())->setRequest($request->getContent())->setResponse($response->getContent())->setIpAddress($remoteAddr)->setDuration(round(microtime(true), 4) - $requestTimeFloat);
$dm->persist($logsClient);
$dm->flush();
}
示例8: 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'));
}
示例9: testRecognize_WhenShouldRedirectToRecognizedLanguageIsEnabled
/**
* @dataProvider dataProviderForTestRecognize_WhenShouldRedirectToRecognizedLanguageIsEnabled
*
* @param string $browserLangLocale
* @param string $routeMatchLang
* @param array $expectedResult
*/
public function testRecognize_WhenShouldRedirectToRecognizedLanguageIsEnabled($browserLangLocale, $routeMatchLang, $expectedResult)
{
$this->prepareTestedObject($this->prepareConfig(true));
$request = new Request();
$request->getHeaders()->addHeaderLine('Accept-Language', $browserLangLocale);
$paramsBefore = ['__NAMESPACE__' => 'Module\\Some', 'controller' => 'TestController', 'action' => 'index', 'lang' => $routeMatchLang, '__CONTROLLER__' => 'test'];
$routeMatch = new RouteMatch($paramsBefore);
$matchedRouteName = 'some\\test';
$routeMatch->setMatchedRouteName($matchedRouteName);
$event = new MvcEvent();
$event->setRequest($request);
$event->setResponse(new Response());
$event->setRouteMatch($routeMatch);
$result = $this->testedObject->recognize($event);
$this->assertSame($expectedResult, $result);
}