public static function getCsrfToken() { if (Session::has('csrftoken')) { return Session::get('csrftoken'); } $token = self::generateCsrfToken(); Session::set('csrftoken', $token); return $token; }
/** * @return Event[] */ public static function loadNew() { $lastEventId = Session::get('last_event_id'); if (!$lastEventId) { //do not load events that we triggered before this session was started /** @var Event $lastEvent */ $lastEvent = Event::queryBuilder()->limit(1)->order('id desc')->fetch(); Session::set('last_event_id', $lastEvent ? $lastEvent->id : 0); } $events = Event::where(['id' => Restrictions::greaterThan($lastEventId)])->order('id asc')->fetchAll(); if ($events) { Session::set('last_event_id', Arrays::last($events)->id); } return $events; }
private function saveMessagesWithEmptyCheck($messages) { if ($messages) { Session::set('messages', $messages); } else { Session::remove('messages'); } }
/** * @test */ public function shouldGetAllValuesFromSession() { //given Session::set('key', 'value'); //when $all = Session::all(); //then Assert::thatArray($all)->hasSize(1)->containsKeyAndValue(array('key' => 'value')); }
private static function removeExcessiveRequests() { $all = Session::get('stats_queries'); if (sizeof($all) > self::NUMBER_OF_REQUESTS_TO_KEEP) { while (sizeof($all) > self::NUMBER_OF_REQUESTS_TO_KEEP) { array_shift($all); } Session::set('stats_queries', $all); } }