/**
  * @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
0
 /**
  * @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
0
 private function checkHeader()
 {
     foreach (parent::getHeaders() as $header) {
         $name = $header->getFieldName();
         $value = $header->getFieldValue();
         $name = $this->headerToParam($name);
         $this->headerParameters[$name] = $value;
     }
 }
Пример #4
0
 /**
  * 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;
 }
 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;
 }
 /**
  * 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
0
 /**
  * Запись логов
  * @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
0
 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
0
 /**
  * @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);
 }