From 0398196913b7c9920e6163ef8bdef53e5bf92fce Mon Sep 17 00:00:00 2001 From: xue <> Date: Thu, 16 Mar 2006 03:06:29 +0000 Subject: Changed THttpSession.Storage to UseCustomStorage. Fixed some doc errors. --- framework/Security/TAuthManager.php | 4 +- framework/Security/TUserManager.php | 2 +- framework/Web/THttpSession.php | 79 ++++++++++++++++--------------------- framework/Web/UI/TThemeManager.php | 2 +- 4 files changed, 38 insertions(+), 49 deletions(-) (limited to 'framework') diff --git a/framework/Security/TAuthManager.php b/framework/Security/TAuthManager.php index 819b7b36..b4856ee5 100644 --- a/framework/Security/TAuthManager.php +++ b/framework/Security/TAuthManager.php @@ -26,8 +26,8 @@ Prado::using('System.Security.TUserManager'); * To login or logout a user, call {@link login} or {@link logout}, respectively. * * To load TAuthManager, configure it in application configuration as follows, - * - * + * + * * * @author Qiang Xue * @version $Revision: $ $Date: $ diff --git a/framework/Security/TUserManager.php b/framework/Security/TUserManager.php index c799c446..5ad582e1 100644 --- a/framework/Security/TUserManager.php +++ b/framework/Security/TUserManager.php @@ -168,7 +168,7 @@ class TUser extends TComponent implements IUser * * TUserManager manages a static list of users {@link TUser}. * The user information is specified via module configuration using the following XML syntax, - * + * * * * diff --git a/framework/Web/THttpSession.php b/framework/Web/THttpSession.php index 97ab6b08..fa53022d 100644 --- a/framework/Web/THttpSession.php +++ b/framework/Web/THttpSession.php @@ -29,23 +29,27 @@ * * * The following configurations are available for session: - * AutoStart, Cookie, CacheLimiter, SavePath, Storage, GCProbability, CookieUsage, Timeout. + * {@link setAutoStart AutoStart}, {@link setCookie Cookie}, + * {@link setCacheLimiter, {@link setSavePath SavePath}, + * {@link setUseCustomStorage UseCustomStorage}, {@link setGCProbability GCProbability}, + * {@link setCookieUsage CookieUsage}, {@link setTimeout Timeout}. * See the corresponding setter and getter documentation for more information. * Note, these properties must be set before the session is started. * * THttpSession can be inherited with customized session storage method. * Override {@link _open}, {@link _close}, {@link _read}, {@link _write}, {@link _destroy} and {@link _gc} - * and set Storage as 'Custom' to store session using methods other than files and shared memory. + * and set {@link setUseCustomStorage UseCustomStorage} to true. + * Then, the session data will be stored using the above methods. * * By default, THttpSession is registered with {@link TApplication} as the * request module. It can be accessed via {@link TApplication::getSession()}. * * THttpSession may be configured in application configuration file as follows, - * * where {@link getSessionName SessionName}, {@link getSavePath SavePath}, - * {@link getCookieMode CookieMode}, {@link getStorage Storage}, + * {@link getCookieMode CookieMode}, {@link getUseCustomStorage UseCustomStorage}, * {@link getAutoStart AutoStart}, {@link getGCProbability GCProbability}, * {@link getUseTransparentSessionID UseTransparentSessionID} and * {@link getTimeOut TimeOut} are configurable properties of THttpSession. @@ -77,6 +81,20 @@ class THttpSession extends TApplicationComponent implements IteratorAggregate,Ar * @var string module id */ private $_id; + /** + * @var boolean + */ + private $_customStorage=false; + + /** + * Destructor. + * Closes session. + */ + public function __destruct() + { + if($this->_started) + $this->close(); + } /** * @return string id of this module @@ -115,6 +133,8 @@ class THttpSession extends TApplicationComponent implements IteratorAggregate,Ar { if(!$this->_started) { + if($this->_customStorage) + session_set_save_handler(array($this,'_open'),array($this,'_close'),array($this,'_read'),array($this,'_write'),array($this,'_destroy'),array($this,'_gc')); if($this->_cookie!==null) session_set_cookie_params($this->_cookie->getExpire(),$this->_cookie->getPath(),$this->_cookie->getDomain(),$this->_cookie->getSecure()); session_start(); @@ -219,53 +239,22 @@ class THttpSession extends TApplicationComponent implements IteratorAggregate,Ar } /** - * @return string (File|SharedMemory|Custom) storage medium of session, defaults to 'File'. - * @see setStorage + * @return boolean whether to use user-specified handlers to store session data. Defaults to false. */ - public function getStorage() + public function getUseCustomStorage() { - switch(session_module_name()) - { - case 'files': return 'File'; - case 'mm': return 'SharedMemory'; - case 'user': return 'Custom'; - default: return 'Unknown'; - } + return $this->_customStorage; } /** - * Sets the storage medium of session data. - * By default, the session data is stored in files (File). - * You may change to use shared memory (SharedMemory) for better performance - * if shared memory is available on the server. - * Or you may choose to use your own storage (Custom). If you do so, - * make sure you override {@link _open}, {@link _close}, {@link _read}, - * {@link _write}, {@link _destroy}, and {@link _gc}. - * @param string (File|SharedMemory|Custom) storage medium of session. - * @throws TInvalidOperationException if session is started already + * @param boolean whether to use user-specified handlers to store session data. + * If true, make sure the methods {@link _open}, {@link _close}, {@link _read}, + * {@link _write}, {@link _destroy}, and {@link _gc} are overridden in child + * class, because they will be used as the callback handlers. */ - public function setStorage($value) + public function setUseCustomStorage($value) { - if($this->_started) - throw new TInvalidOperationException('httpsession_storage_unchangeable'); - else - { - $value=TPropertyValue::ensureEnum($value,array('File','SharedMemory','Custom')); - if($value==='Custom') - session_set_save_handler(array($this,'_open'),array($this,'_close'),array($this,'_read'),array($this,'_write'),array($this,'_destroy'),array($this,'_gc')); - switch($value) - { - case 'Custom': - session_module_name('user'); - break; - case 'SharedMemory': - session_module_name('mm'); - break; - default: - session_module_name('files'); - break; - } - } + $this->_customStorage=TPropertyValue::ensureBoolean($value); } /** diff --git a/framework/Web/UI/TThemeManager.php b/framework/Web/UI/TThemeManager.php index 00b3f60f..29b48d90 100644 --- a/framework/Web/UI/TThemeManager.php +++ b/framework/Web/UI/TThemeManager.php @@ -26,7 +26,7 @@ * * TThemeManager may be configured within page service tag in application * configuration file as follows, - * * where {@link getCacheExpire CacheExpire}, {@link getCacheControl CacheControl} * and {@link getBufferOutput BufferOutput} are configurable properties of THttpResponse. -- cgit v1.2.3