ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
ilSessionIStorage Class Reference

Session based immediate storage. More...

+ Collaboration diagram for ilSessionIStorage:

Public Member Functions

 __construct (string $a_component_id, string $a_sess_id='')
 
 set (string $a_key, string $a_val)
 
 get (string $a_key)
 

Static Public Member Functions

static destroySession ($a_session_id)
 Destroy session(s). More...
 

Private Member Functions

 initComponentCacheIfNotExists ()
 

Private Attributes

string $session_id
 
string $component_id
 

Static Private Attributes

static array $values = []
 

Detailed Description

Session based immediate storage.

This class stores session based user data in the database. The difference to ilSession is that data is written immediately when the set() function is called and that this data is written "per key".

Please note that the values are limited to TEXT(1000)!

This class is needed for cases, where ajax calls should write session based data.

Since more concurrent ajax calls can be initiated by a page request, these calls may run into race conditions, if ilSession is used, since it always reads all key/value pairs at the beginning of a request and writes all of them at the end. Similar issues can appear if a page initiates additional requests by (i)frames.

Definition at line 39 of file class.ilSessionIStorage.php.

Constructor & Destructor Documentation

◆ __construct()

ilSessionIStorage::__construct ( string  $a_component_id,
string  $a_sess_id = '' 
)

Definition at line 45 of file class.ilSessionIStorage.php.

46  {
47  $this->component_id = $a_component_id;
48  if ($a_sess_id !== '') {
49  $this->session_id = $a_sess_id;
50  } else {
51  $this->session_id = session_id();
52  }
53  }

Member Function Documentation

◆ destroySession()

static ilSessionIStorage::destroySession (   $a_session_id)
static

Destroy session(s).

This is called by ilSession->destroy

Parameters
string|list<string>$a_session_id Ids of sessions to be deleted

Definition at line 112 of file class.ilSessionIStorage.php.

References $DIC, and $q.

Referenced by ilSession\_destroy().

112  : void
113  {
114  global $DIC;
115 
116  if (is_array($a_session_id)) {
117  $q = 'DELETE FROM usr_sess_istorage WHERE ' .
118  $DIC->database()->in('session_id', $a_session_id, false, 'text');
119  } else {
120  $q = 'DELETE FROM usr_sess_istorage WHERE session_id = ' .
121  $DIC->database()->quote($a_session_id, 'text');
122  }
123 
124  $DIC->database()->manipulate($q);
125  }
global $DIC
Definition: shib_login.php:26
$q
Definition: shib_logout.php:23
+ Here is the caller graph for this function:

◆ get()

ilSessionIStorage::get ( string  $a_key)

Definition at line 82 of file class.ilSessionIStorage.php.

References $component_id, $DIC, $ilDB, and initComponentCacheIfNotExists().

82  : string
83  {
84  global $DIC;
85 
86  $ilDB = $DIC['ilDB'];
87 
88  if (isset(self::$values[$this->component_id][$a_key]) && is_array(self::$values[$this->component_id])) {
89  return self::$values[$this->component_id][$a_key];
90  }
91 
92  $set = $ilDB->query(
93  'SELECT value FROM usr_sess_istorage ' .
94  ' WHERE session_id = ' . $ilDB->quote($this->session_id, 'text') .
95  ' AND component_id = ' . $ilDB->quote($this->component_id, 'text') .
96  ' AND vkey = ' . $ilDB->quote($a_key, 'text')
97  );
98  $rec = $ilDB->fetchAssoc($set);
99  $value = (string) ($rec['value'] ?? '');
100 
102 
103  self::$values[$this->component_id][$a_key] = $value;
104 
105  return $value;
106  }
global $DIC
Definition: shib_login.php:26
+ Here is the call graph for this function:

◆ initComponentCacheIfNotExists()

ilSessionIStorage::initComponentCacheIfNotExists ( )
private

Definition at line 55 of file class.ilSessionIStorage.php.

References $component_id.

Referenced by get(), and set().

55  : void
56  {
57  if (!isset(self::$values[$this->component_id]) || !is_array(self::$values[$this->component_id])) {
58  self::$values[$this->component_id] = [];
59  }
60  }
+ Here is the caller graph for this function:

◆ set()

ilSessionIStorage::set ( string  $a_key,
string  $a_val 
)

Definition at line 62 of file class.ilSessionIStorage.php.

References $component_id, $DIC, $ilDB, and initComponentCacheIfNotExists().

62  : void
63  {
64  global $DIC;
65 
66  $ilDB = $DIC['ilDB'];
67 
69 
70  self::$values[$this->component_id][$a_key] = $a_val;
71  $ilDB->replace(
72  'usr_sess_istorage',
73  [
74  'session_id' => ['text', $this->session_id],
75  'component_id' => ['text', $this->component_id],
76  'vkey' => ['text', $a_key]
77  ],
78  ['value' => ['text', $a_val]]
79  );
80  }
global $DIC
Definition: shib_login.php:26
+ Here is the call graph for this function:

Field Documentation

◆ $component_id

string ilSessionIStorage::$component_id
private

Definition at line 42 of file class.ilSessionIStorage.php.

Referenced by get(), initComponentCacheIfNotExists(), and set().

◆ $session_id

string ilSessionIStorage::$session_id
private

Definition at line 41 of file class.ilSessionIStorage.php.

◆ $values

array ilSessionIStorage::$values = []
staticprivate

Definition at line 43 of file class.ilSessionIStorage.php.


The documentation for this class was generated from the following file: