[ Index ] |
|
Code source de Symfony 1.0.0 |
1 <?php 2 3 /* 4 * This file is part of the symfony package. 5 * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com> 6 * (c) 2004-2006 Sean Kerr. 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12 /** 13 * sfSessionStorage allows you to store persistent symfony data in the user session. 14 * 15 * <b>Optional parameters:</b> 16 * 17 * # <b>auto_start</b> - [Yes] - Should session_start() automatically be called? 18 * # <b>session_name</b> - [symfony] - The name of the session. 19 * 20 * @package symfony 21 * @subpackage storage 22 * @author Fabien Potencier <fabien.potencier@symfony-project.com> 23 * @author Sean Kerr <skerr@mojavi.org> 24 * @version SVN: $Id: sfSessionStorage.class.php 3329 2007-01-23 08:29:34Z fabien $ 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 // initialize parent 41 parent::initialize($context, $parameters); 42 43 // set session name 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 // start our session 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 // don't need a shutdown procedure because read/write do it in real-time 145 } 146 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Fri Mar 16 22:42:14 2007 | par Balluche grâce à PHPXref 0.7 |