/** * 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'); }
/** * @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(); } }
protected function normalizeCollection($data) { if (!Arr::isTraversable($data)) { return $this->normalize($data); } $normalized = array(); $count = 1; foreach ($data as $key => $value) { if ($count++ >= 1000) { $normalized['...'] = 'Over 1000 items, aborting normalization'; break; } $normalized[$key] = $this->normalizeCollection($value); } return $normalized; }
public function test_pop_last() { $actual = Arr::popLast($this->sut); $this->assertSame("blue", $actual); $this->assertSame(array("color1" => "red"), $this->sut); $actual = Arr::popLast($this->list); $this->assertSame("item3", $actual); $this->assertSame(array("item1", "item2"), $this->list); }