Esempio n. 1
0
File: Http.php Progetto: gmo/common
 /**
  * Get the most suitable IP address from the given request. This function
  * checks the headers defined in {@see Http::HEADERS_TO_CHECK}.
  *
  * @return string|null The found IP address or null if no IP found.
  */
 public static function getIp()
 {
     foreach (static::$HEADERS_TO_CHECK as $headerName) {
         if (isset($_SERVER[$headerName])) {
             $ip = static::extractIp($headerName, $_SERVER[$headerName]);
             if ($ip) {
                 return $ip;
             }
         }
     }
     return Arr::get($_SERVER, 'REMOTE_ADDR');
 }
Esempio n. 2
0
 /**
  * @param $cookieName
  * @param $cookies
  * @return array
  */
 protected function parseCookieData($cookieName, $cookies)
 {
     if ($cookies instanceof ParameterBag) {
         $cookieData = $cookies->get($cookieName, '');
     } else {
         $cookies = is_array($cookies) ? $cookies : $_COOKIE;
         $cookieData = Arr::get($cookies, $cookieName, '');
     }
     try {
         return Arr::objectToArray(JWT::decode($cookieData, $this->secret));
     } catch (\Exception $e) {
         return array();
     }
 }
Esempio n. 3
0
 public function test_get_default_value()
 {
     $this->assertNull(Arr::get($this->sut, "color3"));
     $this->assertFalse(Arr::get($this->sut, "color3", false));
     $this->assertSame("black", Arr::get($this->sut, "color3", "black"));
 }