From b4e9f6795206fab6b952f814ccf812677a34c635 Mon Sep 17 00:00:00 2001 From: xue <> Date: Wed, 7 Dec 2005 00:32:29 +0000 Subject: --- framework/Data/TMemCache.php | 24 +++--------------- framework/Data/TSqliteCache.php | 24 +++--------------- framework/Exceptions/TErrorHandler.php | 24 +++--------------- framework/Security/TAuthManager.php | 24 +++--------------- framework/Security/TUserManager.php | 24 +++--------------- framework/Web/THttpRequest.php | 23 ++--------------- framework/Web/THttpResponse.php | 25 +++---------------- framework/Web/THttpSession.php | 24 +++--------------- framework/Web/UI/TAssetManager.php | 24 +++--------------- framework/Web/UI/TTemplateManager.php | 24 +++--------------- framework/Web/UI/TThemeManager.php | 23 ++--------------- framework/core.php | 45 ++++++++++++++++++++++++++++++++++ 12 files changed, 76 insertions(+), 232 deletions(-) (limited to 'framework') diff --git a/framework/Data/TMemCache.php b/framework/Data/TMemCache.php index b78014fb..d50c5b9d 100644 --- a/framework/Data/TMemCache.php +++ b/framework/Data/TMemCache.php @@ -62,7 +62,7 @@ * @package System.Data * @since 3.0 */ -class TMemCache extends TComponent implements IModule, ICache +class TMemCache extends TModule implements ICache { /** * @var boolean if the module is initialized @@ -84,10 +84,6 @@ class TMemCache extends TComponent implements IModule, ICache * @var integer the port number of the memcache server */ private $_port=11211; - /** - * @var string ID of this module - */ - private $_id=''; /** * Destructor. @@ -111,6 +107,8 @@ class TMemCache extends TComponent implements IModule, ICache */ public function init($application,$config) { + parent::init($application,$config); + if(!extension_loaded('memcache')) throw new TConfigurationException('memcache_extension_required'); $this->_cache=new Memcache; @@ -122,22 +120,6 @@ class TMemCache extends TComponent implements IModule, ICache $application->setCache($this); } - /** - * @return string id of this module - */ - public function getID() - { - return $this->_id; - } - - /** - * @param string id of this module - */ - public function setID($value) - { - $this->_id=$value; - } - /** * @return string host name of the memcache server */ diff --git a/framework/Data/TSqliteCache.php b/framework/Data/TSqliteCache.php index 5eb692d4..13455849 100644 --- a/framework/Data/TSqliteCache.php +++ b/framework/Data/TSqliteCache.php @@ -64,7 +64,7 @@ * @package System.Data * @since 3.0 */ -class TSqliteCache extends TComponent implements IModule, ICache +class TSqliteCache extends TModule implements ICache { /** * name of the table storing cache data @@ -91,10 +91,6 @@ class TSqliteCache extends TComponent implements IModule, ICache * @var string the database file name */ private $_file=null; - /** - * @var string id of this module - */ - private $_id=''; /** * Destructor. @@ -119,6 +115,8 @@ class TSqliteCache extends TComponent implements IModule, ICache */ public function init($application,$config) { + parent::init($application,$config); + if(!function_exists('sqlite_open')) throw new TConfigurationException('sqlitecache_extension_required'); if($this->_file===null) @@ -141,22 +139,6 @@ class TSqliteCache extends TComponent implements IModule, ICache $application->setCache($this); } - /** - * @return string id of this module - */ - public function getID() - { - return $this->_id; - } - - /** - * @param string id of this module - */ - public function setID($value) - { - $this->_id=$value; - } - /** * @return string database file path (in namespace form) */ diff --git a/framework/Exceptions/TErrorHandler.php b/framework/Exceptions/TErrorHandler.php index 913b3ac3..ebdaf41c 100644 --- a/framework/Exceptions/TErrorHandler.php +++ b/framework/Exceptions/TErrorHandler.php @@ -49,7 +49,7 @@ * @package System.Exceptions * @since 3.0 */ -class TErrorHandler extends TComponent implements IModule +class TErrorHandler extends TModule { /** * error template file basename @@ -64,10 +64,6 @@ class TErrorHandler extends TComponent implements IModule */ const SOURCE_LINES=12; - /** - * @var string module ID - */ - private $_id='error'; /** * @var TApplication application instance */ @@ -85,26 +81,12 @@ class TErrorHandler extends TComponent implements IModule */ public function init($application,$config) { + parent::init($application,$config); + $this->_application=$application; $application->setErrorHandler($this); } - /** - * @return string id of this module - */ - public function getID() - { - return $this->_id; - } - - /** - * @param string id of this module - */ - public function setID($value) - { - $this->_id=$value; - } - /** * @return string the directory containing error template files. */ diff --git a/framework/Security/TAuthManager.php b/framework/Security/TAuthManager.php index ae3f713f..3bf6964e 100644 --- a/framework/Security/TAuthManager.php +++ b/framework/Security/TAuthManager.php @@ -34,16 +34,12 @@ Prado::using('System.Security.TUserManager'); * @package System.Security * @since 3.0 */ -class TAuthManager extends TComponent implements IModule +class TAuthManager extends TModule { /** * GET variable name for return url */ const RETURN_URL_VAR='ReturnUrl'; - /** - * @var string module ID - */ - private $_id; /** * @var boolean if the module has been initialized */ @@ -65,22 +61,6 @@ class TAuthManager extends TComponent implements IModule */ private $_skipAuthorization=false; - /** - * @return string id of this module - */ - public function getID() - { - return $this->_id; - } - - /** - * @param string id of this module - */ - public function setID($value) - { - $this->_id=$value; - } - /** * Initializes this module. * This method is required by the IModule interface. @@ -90,6 +70,8 @@ class TAuthManager extends TComponent implements IModule */ public function init($application,$config) { + parent::init($application,$config); + if($this->_userManager===null) throw new TConfigurationException('authmanager_usermanager_required'); if(is_string($this->_userManager)) diff --git a/framework/Security/TUserManager.php b/framework/Security/TUserManager.php index 9da386f0..d9210661 100644 --- a/framework/Security/TUserManager.php +++ b/framework/Security/TUserManager.php @@ -189,12 +189,8 @@ class TUser extends TComponent implements IUser * @package System.Security * @since 3.0 */ -class TUserManager extends TComponent implements IModule +class TUserManager extends TModule { - /** - * @var string id of this module - */ - private $_id; /** * @var array list of users managed by this module */ @@ -221,6 +217,8 @@ class TUserManager extends TComponent implements IModule */ public function init($application,$config) { + parent::init($application,$config); + foreach($config->getElementsByTagName('user') as $node) $this->_users[strtolower($node->getAttribute('name'))]=$node->getAttribute('password'); foreach($config->getElementsByTagName('role') as $node) @@ -233,22 +231,6 @@ class TUserManager extends TComponent implements IModule } } - /** - * @return string id of this module - */ - public function getID() - { - return $this->_id; - } - - /** - * @param string id of this module - */ - public function setID($value) - { - $this->_id=$value; - } - /** * @return string guest name, defaults to 'Guest' */ diff --git a/framework/Web/THttpRequest.php b/framework/Web/THttpRequest.php index 80e87d15..0c21a020 100644 --- a/framework/Web/THttpRequest.php +++ b/framework/Web/THttpRequest.php @@ -29,7 +29,7 @@ * @package System.Web * @since 3.0 */ -class THttpRequest extends TComponent implements IModule +class THttpRequest extends TModule { /** * GET variable name to store service information @@ -39,10 +39,6 @@ class THttpRequest extends TComponent implements IModule * @var boolean whether the module is initialized */ private $_initialized=false; - /** - * @var string module ID - */ - private $_id; /** * @var string requested service ID */ @@ -76,6 +72,7 @@ class THttpRequest extends TComponent implements IModule */ public function init($application,$config) { + parent::init($application,$config); // Info about server variables: // PHP_SELF contains real URI (w/ path info, w/o query string) // SCRIPT_NAME is the real URI for the requested script (w/o path info and query string) @@ -124,22 +121,6 @@ class THttpRequest extends TComponent implements IModule return is_array($data)?array_map(array($this,'stripSlashes'),$data):stripslashes($data); } - /** - * @return string id of this module - */ - public function getID() - { - return $this->_id; - } - - /** - * @param string id of this module - */ - public function setID($value) - { - $this->_id=$value; - } - /** * @return TUri the request URL */ diff --git a/framework/Web/THttpResponse.php b/framework/Web/THttpResponse.php index dfa2d023..ad290fb0 100644 --- a/framework/Web/THttpResponse.php +++ b/framework/Web/THttpResponse.php @@ -37,12 +37,8 @@ * @package System.Web * @since 3.0 */ -class THttpResponse extends TComponent implements IModule, ITextWriter +class THttpResponse extends TModule implements ITextWriter { - /** - * @var string id of this module (response) - */ - private $_id; /** * @var boolean whether to buffer output */ @@ -84,29 +80,14 @@ class THttpResponse extends TComponent implements IModule, ITextWriter */ public function init($application,$config) { + parent::init($application,$config); + if($this->_bufferOutput) ob_start(); $this->_initialized=true; $application->setResponse($this); } - /** - * @return string id of this module - */ - public function getID() - { - return $this->_id; - } - - /** - * @param string id of this module - */ - public function setID($value) - { - $this->_id=$value; - } - - /** * @return integer time-to-live for cached session pages in minutes, this has no effect for nocache limiter. Defaults to 180. */ diff --git a/framework/Web/THttpSession.php b/framework/Web/THttpSession.php index 5afcfb7a..0698d4d8 100644 --- a/framework/Web/THttpSession.php +++ b/framework/Web/THttpSession.php @@ -54,12 +54,8 @@ * @package System.Web * @since 3.0 */ -class THttpSession extends TComponent implements IModule +class THttpSession extends TModule { - /** - * @var string ID of this module - */ - private $_id; /** * @var THttpSessionCollection list of session variables */ @@ -89,6 +85,8 @@ class THttpSession extends TComponent implements IModule */ public function init($application,$config) { + parent::init($application,$config); + if($this->_autoStart) session_start(); $this->_initialized=true; @@ -133,22 +131,6 @@ class THttpSession extends TComponent implements IModule } } - /** - * @return string the ID of this session module (not session ID) - */ - public function getID() - { - return $this->_id; - } - - /** - * @param string the ID of this session module (not session ID) - */ - public function setID($value) - { - $this->_id=$value; - } - /** * @return THttpSessionCollection list of session variables */ diff --git a/framework/Web/UI/TAssetManager.php b/framework/Web/UI/TAssetManager.php index 0f96ae90..df189b58 100644 --- a/framework/Web/UI/TAssetManager.php +++ b/framework/Web/UI/TAssetManager.php @@ -41,7 +41,7 @@ * @package System.Web.UI * @since 3.0 */ -class TAssetManager extends TComponent implements IModule +class TAssetManager extends TModule { /** * Default web accessible base path for storing private files @@ -55,10 +55,6 @@ class TAssetManager extends TComponent implements IModule * @var string base URL for accessing the publishing directory. */ private $_baseUrl=null; - /** - * @var string module ID - */ - private $_id='asset'; /** * @var boolean whether to use timestamp checking to ensure files are published with up-to-date versions. */ @@ -80,6 +76,8 @@ class TAssetManager extends TComponent implements IModule */ public function init($application,$config) { + parent::init($application,$config); + $this->_application=$application; if($this->_basePath===null) $this->_basePath=dirname($application->getRequest()->getPhysicalApplicationPath()).'/'.self::DEFAULT_BASEPATH; @@ -90,22 +88,6 @@ class TAssetManager extends TComponent implements IModule $application->getService()->setAssetManager($this); } - /** - * @return string id of this module - */ - public function getID() - { - return $this->_id; - } - - /** - * @param string id of this module - */ - public function setID($value) - { - $this->_id=$value; - } - /** * @return string the root directory storing published asset files */ diff --git a/framework/Web/UI/TTemplateManager.php b/framework/Web/UI/TTemplateManager.php index 1f3044a2..6864e038 100644 --- a/framework/Web/UI/TTemplateManager.php +++ b/framework/Web/UI/TTemplateManager.php @@ -27,7 +27,7 @@ * @package System.Web.UI * @since 3.0 */ -class TTemplateManager extends TComponent implements IModule +class TTemplateManager extends TModule { /** * Template file extension @@ -41,10 +41,6 @@ class TTemplateManager extends TComponent implements IModule * @var TApplication application instance */ private $_application; - /** - * @var string module ID - */ - private $_id; /** * Initializes the module. @@ -55,26 +51,12 @@ class TTemplateManager extends TComponent implements IModule */ public function init($application,$config) { + parent::init($application,$config); + $this->_application=$application; $application->getService()->setTemplateManager($this); } - /** - * @return string id of this module - */ - public function getID() - { - return $this->_id; - } - - /** - * @param string id of this module - */ - public function setID($value) - { - $this->_id=$value; - } - /** * Loads the template corresponding to the specified class name. * @return ITemplate template for the class name, null if template doesn't exist. diff --git a/framework/Web/UI/TThemeManager.php b/framework/Web/UI/TThemeManager.php index 504e8ecb..746e36cb 100644 --- a/framework/Web/UI/TThemeManager.php +++ b/framework/Web/UI/TThemeManager.php @@ -36,16 +36,12 @@ * @package System.Web.UI * @since 3.0 */ -class TThemeManager extends TComponent implements IModule +class TThemeManager extends TModule { /** * default themes base path */ const DEFAULT_BASEPATH='themes'; - /** - * @var string module ID - */ - private $_id='theme'; /** * @var boolean whether this module has been initialized */ @@ -71,27 +67,12 @@ class TThemeManager extends TComponent implements IModule */ public function init($application,$config) { + parent::init($application,$config); $this->_application=$application; $this->_initialized=true; $application->getService()->setThemeManager($this); } - /** - * @return string id of this module - */ - public function getID() - { - return $this->_id; - } - - /** - * @param string id of this module - */ - public function setID($value) - { - $this->_id=$value; - } - /** * @param string name of the theme to be retrieved * @return TTheme the theme retrieved diff --git a/framework/core.php b/framework/core.php index 794384b4..efd091ad 100644 --- a/framework/core.php +++ b/framework/core.php @@ -310,6 +310,51 @@ interface IPageStatePersister public function save($state); } +/** + * TModule class. + * + * TModule implements the basic methods required by IModule and may be + * used as the basic class for application modules. + * + * @author Qiang Xue + * @version $Revision: $ $Date: $ + * @package System + * @since 3.0 + */ +class TModule extends TComponent implements IModule +{ + /** + * @var string module id + */ + private $_id; + + /** + * Initializes the module. + * This method is required by IModule and is invoked by application. + * @param TApplication application + * @param TXmlElement module configuration + */ + public function init($application,$config) + { + } + + /** + * @return string id of this module + */ + public function getID() + { + return $this->_id; + } + + /** + * @param string id of this module + */ + public function setID($value) + { + $this->_id=$value; + } +} + /** * PradoBase class. * -- cgit v1.2.3