public static function getCsrfToken() { if (Session::has('csrftoken')) { return Session::get('csrftoken'); } $token = self::generateCsrfToken(); Session::set('csrftoken', $token); return $token; }
function showSuccess(array $notices = array()) { if (Session::has('messages') || $notices) { $sessionMessages = Arrays::filterNotBlank(Arrays::toArray(Session::get('messages'))); $notices = array_merge($sessionMessages, $notices); $noticeView = new View('success_alert'); $noticeView->notices = $notices; return $noticeView->render(); } return null; }
/** * @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 _removeMessages() { if (!$this->_keepMessage && Session::has('messages')) { $messages = Arrays::filter(Session::get('messages'), function (Notice $notice) { return !$notice->requestUrlMatches(); }); $this->saveMessagesWithEmptyCheck($messages); } }
private function _getConfigFromSession() { return Session::get('config') ?: array(); }
/** * @test */ public function shouldSaveStatsIfDebugIsOn() { //given Config::overrideProperty('debug')->with(true); Session::remove('stats_queries'); Route::get('/sample/save', 'sample#save'); //when $this->get('/sample/save'); //then $this->assertNotEmpty(Session::get('stats_queries')); }
/** * @test */ public function shouldRemoveNoticeIfUrlIsWithQueryPath() { //given Route::allowAll('/simple_test', 'simple_test'); $this->get('/simple_test/notice_with_query?data=some-data'); //when $this->get('/simple_test/other_action'); //then $this->assertEmpty(Session::get('messages')); }
/** * @test */ public function shouldPushNestedSessionValueWhenArrayIsNotEmpty() { // given Session::push('key1', 'key2', 'value1'); Session::push('key1', 'key2', 'value2'); //when Session::push('key1', 'key2', 'value3'); //then Assert::thatSession()->hasSize(1); $value = Session::get('key1', 'key2'); Assert::thatArray($value)->containsExactly('value1', 'value2', 'value3'); }
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); } }