Example #1
0
 function testGetAllElements()
 {
     Session::set('Test', 'Test');
     Session::set('Test-2', 'Test-2');
     $session = Session::get_all();
     $this->assertEquals($session, array('Test' => 'Test', 'Test-2' => 'Test-2'));
 }
 function testGetAllElements()
 {
     Session::clear_all();
     // Remove all session that might've been set by the test harness
     Session::set('Test', 'Test');
     Session::set('Test-2', 'Test-2');
     $session = Session::get_all();
     $this->assertEquals($session, array('Test' => 'Test', 'Test-2' => 'Test-2'));
 }
 public function masquerade()
 {
     // don't use $member->logIn() because it triggers tracking and breaks remember me tokens, etc.
     $sessionData = Session::get_all();
     Session::clear_all();
     Session::set("loggedInAs", $this->getOwner()->ID);
     Session::set('Masquerade.Old', $sessionData);
     return $this->getOwner();
 }
 public function postRequest(SS_HTTPRequest $request, SS_HTTPResponse $response, DataModel $model)
 {
     if (!$this->testSessionEnvironment->isRunningTests()) {
         return;
     }
     // Store PHP session
     $state = $this->testSessionEnvironment->getState();
     $state->session = Session::get_all();
     $this->testSessionEnvironment->applyState($state);
 }
 public static function getSessionData()
 {
     $data = Session::get_all();
     $filtered = array();
     // Filter not useful data
     foreach ($data as $k => $v) {
         if (strpos($k, 'gf_') === 0) {
             continue;
         }
         if ($k === 'PHPDEBUGBAR_STACK_DATA') {
             continue;
         }
         $filtered[$k] = $v;
     }
     return $filtered;
 }
 /**
  * Determine if the cache should be enabled for the current request
  *
  * @param string $url
  * @return boolean
  */
 protected function enabled($url)
 {
     // Master override
     if (!self::config()->enabled) {
         return false;
     }
     // No GET params other than cache relevant config is passed (e.g. "?stage=Stage"),
     // which would mean that we have to bypass the cache
     if (count(array_diff(array_keys($_GET), array('url')))) {
         return false;
     }
     // Request is not POST (which would have to be handled dynamically)
     if ($_POST) {
         return false;
     }
     // Check url doesn't hit opt out filter
     $optOutURL = self::config()->optOutURL;
     if (!empty($optOutURL) && preg_match($optOutURL, $url)) {
         return false;
     }
     // Check url hits the opt in filter
     $optInURL = self::config()->optInURL;
     if (!empty($optInURL) && !preg_match($optInURL, $url)) {
         return false;
     }
     // Check ajax filter
     if (!self::config()->enableAjax && Director::is_ajax()) {
         return false;
     }
     // If displaying form errors then don't display cached result
     foreach (Session::get_all() as $field => $data) {
         // Check for session details in the form FormInfo.{$FormName}.errors/FormInfo.{$FormName}.formError
         if ($field === 'FormInfo') {
             foreach ($data as $formData) {
                 if (isset($formData['errors']) || isset($formData['formError'])) {
                     return false;
                 }
             }
         }
     }
     // OK!
     return true;
 }
 public function init()
 {
     parent::init();
     if ($message = Session::get('Status')) {
         $this->owner->StatusMessage = DBField::create_field('HTMLText', $message['message']);
         $this->owner->StatusType = isset($message['type']) ? $message['type'] : 'success';
         Session::clear('Status');
     } else {
         $messages = Session::get_all();
         if ($messages && isset($messages['FormInfo'])) {
             foreach ($messages['FormInfo'] as $name => $message) {
                 if (isset($message['formError'])) {
                     $this->owner->StatusMessage = DBField::create_field('HTMLText', $message['formError']['message']);
                     $this->owner->StatusType = isset($message['formError']['type']) ? $message['formError']['type'] : 'success';
                 }
             }
             Session::clear('FormInfo');
         }
     }
     if ($this->owner->StatusMessage) {
         $this->owner->StatusMessage = html_entity_decode($this->owner->StatusMessage);
     }
 }
 /**
  * The entry-point. called by Clockwork itself.
  * @param Request $request
  * @return \Clockwork\Request\Request
  */
 function resolve(Request $request)
 {
     // Retrieve the timeline
     $timeline = Injector::inst()->get('ClockworkTimeline');
     $timeline->finalize();
     $request->timelineData = $timeline->toArray();
     // Retrieve the query log
     $db = DB::getConn();
     if ($db instanceof DatabaseProxy) {
         $request->databaseQueries = $db->getQueries();
     }
     // Retrieve the log
     $log = Injector::inst()->get('ClockworkLog');
     $request->log = $log->toArray();
     // Fill in the rest of the request - these may not be finalized yet when the PhpDataSource sees them
     $request->cookies = \Cookie::get_all();
     $request->sessionData = \Session::get_all();
     // Give some knowledge about the controller if we have it
     if (isset(self::$controller)) {
         $request->controller = self::$controller;
     }
     // TODO: routing
     return $request;
 }
 /**
  * @deprecated 2.5 Use Session::get_all()
  */
 public static function getAll()
 {
     user_error('Session::getAll() is deprecated. Please use Session::get_all() instead.', E_USER_NOTICE);
     return Session::get_all();
 }
Example #10
0
function loadDbVars(&$db)
{
    $vars = Session::get_all('vars');
    foreach ($vars as $variable => $value) {
        $query = 'SET @' . $variable . ' = ' . $value;
        $db->query($query);
    }
}
 /**
  * Clear all session variables that start with the gridlist session key prefix (self.KeyPrefix).
  */
 protected function clearSession()
 {
     $len = strlen(self::SessionKeyPrefix);
     foreach (\Session::get_all() as $name => $value) {
         if (substr($name, 0, $len) == self::SessionKeyPrefix) {
             \Session::clear($name);
         }
     }
     \Session::save();
 }
 function beforeMemberLoggedOut()
 {
     if (SiteConfig::current_site_config()->IsRunningTests()) {
         $this->_cache_session = Session::get_all();
     }
 }
 /**
  * @param  SS_HTTPRequest  $request
  * @param  SS_HTTPResponse $response
  * @return bool
  */
 protected function allowSave(SS_HTTPRequest $request, SS_HTTPResponse $response)
 {
     $vars = array('request' => $request, 'response' => $response, 'member' => \Member::currentUser(), 'session' => \Session::get_all()) + $this->extraExpressionVars;
     if (count($this->saveExcludeRules)) {
         foreach ($this->saveExcludeRules as $rule) {
             if ($this->expressionLanguage->evaluate($rule, $vars)) {
                 return false;
             }
         }
     }
     if (count($this->saveIncludeRules)) {
         foreach ($this->saveIncludeRules as $rule) {
             if (!$this->expressionLanguage->evaluate($rule, $vars)) {
                 return false;
             }
         }
     }
     return true;
 }
 /**
  * Return the contents of the session in array form.
  */
 public function contents()
 {
     return Session::get_all();
 }