| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
class sfSessionStorage extends sfStorage |
|---|
| 27 |
{ |
|---|
| 28 |
|
|---|
| 29 |
* Initializes this Storage instance. |
|---|
| 30 |
* |
|---|
| 31 |
* @param sfContext A sfContext instance |
|---|
| 32 |
* @param array An associative array of initialization parameters |
|---|
| 33 |
* |
|---|
| 34 |
* @return boolean true, if initialization completes successfully, otherwise false |
|---|
| 35 |
* |
|---|
| 36 |
* @throws <b>sfInitializationException</b> If an error occurs while initializing this Storage |
|---|
| 37 |
*/ |
|---|
| 38 |
public function initialize($context, $parameters = null) |
|---|
| 39 |
{ |
|---|
| 40 |
|
|---|
| 41 |
parent::initialize($context, $parameters); |
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
$sessionName = $this->getParameterHolder()->get('session_name', 'symfony'); |
|---|
| 45 |
|
|---|
| 46 |
session_name($sessionName); |
|---|
| 47 |
|
|---|
| 48 |
$use_cookies = (boolean) ini_get('session.use_cookies'); |
|---|
| 49 |
if (!$use_cookies) |
|---|
| 50 |
{ |
|---|
| 51 |
$sessionId = $context->getRequest()->getParameter($sessionName, ''); |
|---|
| 52 |
|
|---|
| 53 |
if ($sessionId != '') |
|---|
| 54 |
{ |
|---|
| 55 |
session_id($sessionId); |
|---|
| 56 |
} |
|---|
| 57 |
} |
|---|
| 58 |
|
|---|
| 59 |
$cookieDefaults = session_get_cookie_params(); |
|---|
| 60 |
$lifetime = $this->getParameter('session_cookie_lifetime', $cookieDefaults['lifetime']); |
|---|
| 61 |
$path = $this->getParameter('session_cookie_path', $cookieDefaults['path']); |
|---|
| 62 |
$domain = $this->getParameter('session_cookie_domain', $cookieDefaults['domain']); |
|---|
| 63 |
$secure = $this->getParameter('session_cookie_secure', $cookieDefaults['secure']); |
|---|
| 64 |
$httpOnly = $this->getParameter('session_cookie_httponly', isset($cookieDefaults['httponly']) ? $cookieDefaults['httponly'] : false); |
|---|
| 65 |
if (version_compare(phpversion(), '5.2', '>=')) |
|---|
| 66 |
{ |
|---|
| 67 |
session_set_cookie_params($lifetime, $path, $domain, $secure, $httpOnly); |
|---|
| 68 |
} |
|---|
| 69 |
else |
|---|
| 70 |
{ |
|---|
| 71 |
session_set_cookie_params($lifetime, $path, $domain, $secure); |
|---|
| 72 |
} |
|---|
| 73 |
|
|---|
| 74 |
if ($this->getParameter('auto_start', true)) |
|---|
| 75 |
{ |
|---|
| 76 |
|
|---|
| 77 |
session_start(); |
|---|
| 78 |
} |
|---|
| 79 |
} |
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
* Reads data from this storage. |
|---|
| 83 |
* |
|---|
| 84 |
* The preferred format for a key is directory style so naming conflicts can be avoided. |
|---|
| 85 |
* |
|---|
| 86 |
* @param string A unique key identifying your data |
|---|
| 87 |
* |
|---|
| 88 |
* @return mixed Data associated with the key |
|---|
| 89 |
*/ |
|---|
| 90 |
public function & read($key) |
|---|
| 91 |
{ |
|---|
| 92 |
$retval = null; |
|---|
| 93 |
|
|---|
| 94 |
if (isset($_SESSION[$key])) |
|---|
| 95 |
{ |
|---|
| 96 |
$retval =& $_SESSION[$key]; |
|---|
| 97 |
} |
|---|
| 98 |
|
|---|
| 99 |
return $retval; |
|---|
| 100 |
} |
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
* Removes data from this storage. |
|---|
| 104 |
* |
|---|
| 105 |
* The preferred format for a key is directory style so naming conflicts can be avoided. |
|---|
| 106 |
* |
|---|
| 107 |
* @param string A unique key identifying your data |
|---|
| 108 |
* |
|---|
| 109 |
* @return mixed Data associated with the key |
|---|
| 110 |
*/ |
|---|
| 111 |
public function & remove($key) |
|---|
| 112 |
{ |
|---|
| 113 |
$retval = null; |
|---|
| 114 |
|
|---|
| 115 |
if (isset($_SESSION[$key])) |
|---|
| 116 |
{ |
|---|
| 117 |
$retval =& $_SESSION[$key]; |
|---|
| 118 |
unset($_SESSION[$key]); |
|---|
| 119 |
} |
|---|
| 120 |
|
|---|
| 121 |
return $retval; |
|---|
| 122 |
} |
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 |
* Writes data to this storage. |
|---|
| 126 |
* |
|---|
| 127 |
* The preferred format for a key is directory style so naming conflicts can be avoided. |
|---|
| 128 |
* |
|---|
| 129 |
* @param string A unique key identifying your data |
|---|
| 130 |
* @param mixed Data associated with your key |
|---|
| 131 |
* |
|---|
| 132 |
*/ |
|---|
| 133 |
public function write($key, &$data) |
|---|
| 134 |
{ |
|---|
| 135 |
$_SESSION[$key] =& $data; |
|---|
| 136 |
} |
|---|
| 137 |
|
|---|
| 138 |
|
|---|
| 139 |
* Executes the shutdown procedure. |
|---|
| 140 |
* |
|---|
| 141 |
*/ |
|---|
| 142 |
public function shutdown() |
|---|
| 143 |
{ |
|---|
| 144 |
|
|---|
| 145 |
} |
|---|
| 146 |
} |
|---|
| 147 |
|
|---|