From a90da4361d02a53204f198f19072e2d420b394f0 Mon Sep 17 00:00:00 2001 From: xue <> Date: Sun, 3 Sep 2006 21:33:04 +0000 Subject: Added TEnumerable and updated places where enumerable type should be used. --- framework/Exceptions/TErrorHandler.php | 4 +- framework/PradoBase.php | 4 +- framework/Security/TSecurityManager.php | 31 +++++-- framework/Security/TUserManager.php | 38 ++++++-- framework/TApplication.php | 35 +++++-- framework/TComponent.php | 52 +++++++++++ framework/Util/TDataFieldAccessor.php | 2 +- framework/Web/Javascripts/js/debug/validator.js | 4 +- framework/Web/Javascripts/prado/validation3.js | 4 +- framework/Web/Services/TPageService.php | 2 +- framework/Web/TAssetManager.php | 8 +- framework/Web/THttpRequest.php | 40 ++++++-- framework/Web/THttpSession.php | 42 +++++++-- framework/Web/UI/TClientScriptManager.php | 4 +- framework/Web/UI/TThemeManager.php | 2 +- framework/Web/UI/WebControls/TBaseValidator.php | 33 +++++-- framework/Web/UI/WebControls/TTextBox.php | 101 ++++++++++++++++----- .../Web/UI/WebControls/TValidationSummary.php | 72 ++++++++++++--- framework/Web/UI/WebControls/TWizard.php | 98 +++++++++++++++----- 19 files changed, 453 insertions(+), 123 deletions(-) (limited to 'framework') diff --git a/framework/Exceptions/TErrorHandler.php b/framework/Exceptions/TErrorHandler.php index e18de7ab..eabe20dc 100644 --- a/framework/Exceptions/TErrorHandler.php +++ b/framework/Exceptions/TErrorHandler.php @@ -130,7 +130,7 @@ class TErrorHandler extends TModule header('Content-Type: text/html; charset=UTF-8'); if($param instanceof THttpException) $this->handleExternalError($param->getStatusCode(),$param); - else if($this->getApplication()->getMode()===TApplication::STATE_DEBUG) + else if($this->getApplication()->getMode()===TApplicationMode::Debug) $this->displayException($param); else $this->handleExternalError(500,$param); @@ -183,7 +183,7 @@ class TErrorHandler extends TModule */ protected function handleRecursiveError($exception) { - if($this->getApplication()->getMode()===TApplication::STATE_DEBUG) + if($this->getApplication()->getMode()===TApplicationMode::Debug) { echo "Recursive Error\n"; echo "

Recursive Error

\n"; diff --git a/framework/PradoBase.php b/framework/PradoBase.php index cf1d67fb..cda172a3 100644 --- a/framework/PradoBase.php +++ b/framework/PradoBase.php @@ -489,9 +489,9 @@ class PradoBase */ public static function trace($msg,$category='Uncategorized') { - if(self::$_application && self::$_application->getMode()===TApplication::STATE_PERFORMANCE) + if(self::$_application && self::$_application->getMode()===TApplicationMode::Performance) return; - if(!self::$_application || self::$_application->getMode()===TApplication::STATE_DEBUG) + if(!self::$_application || self::$_application->getMode()===TApplicationMode::Debug) { $trace=debug_backtrace(); if(isset($trace[0]['file']) && isset($trace[0]['line'])) diff --git a/framework/Security/TSecurityManager.php b/framework/Security/TSecurityManager.php index b0ea4e95..6c227c8e 100644 --- a/framework/Security/TSecurityManager.php +++ b/framework/Security/TSecurityManager.php @@ -43,11 +43,9 @@ class TSecurityManager extends TModule { const STATE_VALIDATION_KEY='prado:securitymanager:validationkey'; const STATE_ENCRYPTION_KEY='prado:securitymanager:encryptionkey'; - const STATE_INIT_VECTOR='prado:securitymanager:initvector'; private $_validationKey=null; private $_encryptionKey=null; - private $_initVector=null; - private $_validation='SHA1'; + private $_validation=TSecurityManagerValidationMode::SHA1; private $_encryption='3DES'; /** @@ -127,7 +125,7 @@ class TSecurityManager extends TModule } /** - * @return string hashing algorithm used to generate HMAC. Defaults to 'SHA1'. + * @return TSecurityManagerValidationMode hashing algorithm used to generate HMAC. Defaults to TSecurityManagerValidationMode::SHA1. */ public function getValidation() { @@ -135,11 +133,11 @@ class TSecurityManager extends TModule } /** - * @param string hashing algorithm used to generate HMAC. Valid values include 'SHA1' and 'MD5'. + * @param TSecurityManagerValidationMode hashing algorithm used to generate HMAC. */ public function setValidation($value) { - $this->_validation=TPropertyValue::ensureEnum($value,'SHA1','MD5'); + $this->_validation=TPropertyValue::ensureEnumerable($value,'TSecurityManagerValidationMode'); } /** @@ -260,4 +258,25 @@ class TSecurityManager extends TModule } } + +/** + * TSecurityManagerValidationMode class. + * TSecurityManagerValidationMode defines the enumerable type for the possible validation modes + * that can be used by {@link TSecurityManager}. + * + * The following enumerable values are defined: + * - MD5: an MD5 hash is generated from the data and used for validation. + * - SHA1: an SHA1 hash is generated from the data and used for validation. + * + * @author Qiang Xue + * @version $Revision: $ $Date: $ + * @package System.Security + * @since 3.0.4 + */ +class TSecurityManagerValidationMode extends TEnumerable +{ + const MD5='MD5'; + const SHA1='SHA1'; +} + ?> \ No newline at end of file diff --git a/framework/Security/TUserManager.php b/framework/Security/TUserManager.php index 6b10fa8b..8d91c92a 100644 --- a/framework/Security/TUserManager.php +++ b/framework/Security/TUserManager.php @@ -35,7 +35,7 @@ Prado::using('System.Security.TUser'); * similar to the above sample. * * The user passwords may be specified as clear text, SH1 or MD5 hashed by setting - * {@link setPasswordMode PasswordMode} as Clear, SH1 or MD5. + * {@link setPasswordMode PasswordMode} as Clear, SHA1 or MD5. * The default name for a guest user is Guest. It may be changed * by setting {@link setGuestName GuestName} property. * @@ -67,9 +67,9 @@ class TUserManager extends TModule implements IUserManager */ private $_guestName='Guest'; /** - * @var string password mode, Clear|MD5|SH1 + * @var TUserManagerPasswordMode password mode */ - private $_passwordMode='MD5'; + private $_passwordMode=TUserManagerPasswordMode::MD5; /** * @var boolean whether the module has been initialized */ @@ -186,7 +186,7 @@ class TUserManager extends TModule implements IUserManager } /** - * @return string (Clear|MD5|SH1) how password is stored, clear text, or MD5 or SH1 hashed. Default to MD5. + * @return TUserManagerPasswordMode how password is stored, clear text, or MD5 or SHA1 hashed. Default to TUserManagerPasswordMode::MD5. */ public function getPasswordMode() { @@ -194,11 +194,11 @@ class TUserManager extends TModule implements IUserManager } /** - * @param string (Clear|MD5|SH1) how password is stored, clear text, or MD5 or SH1 hashed. + * @param TUserManagerPasswordMode how password is stored, clear text, or MD5 or SHA1 hashed. */ public function setPasswordMode($value) { - $this->_passwordMode=TPropertyValue::ensureEnum($value,array('Clear','MD5','SHA1')); + $this->_passwordMode=TPropertyValue::ensureEnumerable($value,'TUserManagerPasswordMode'); } /** @@ -209,9 +209,9 @@ class TUserManager extends TModule implements IUserManager */ public function validateUser($username,$password) { - if($this->_passwordMode==='MD5') + if($this->_passwordMode===TUserManagerPasswordMode::MD5) $password=md5($password); - else if($this->_passwordMode==='SHA1') + else if($this->_passwordMode===TUserManagerPasswordMode::SHA1) $password=sha1($password); $username=strtolower($username); return (isset($this->_users[$username]) && $this->_users[$username]===$password); @@ -258,4 +258,26 @@ class TUserManager extends TModule implements IUserManager } } +/** + * TUserManagerPasswordMode class. + * TUserManagerPasswordMode defines the enumerable type for the possible modes + * that user passwords can be specified for a {@link TUserManager}. + * + * The following enumerable values are defined: + * - Clear: the password is in plain text + * - MD5: the password is recorded as the MD5 hash value of the original password + * - SHA1: the password is recorded as the SHA1 hash value of the original password + * + * @author Qiang Xue + * @version $Revision: $ $Date: $ + * @package System.Security + * @since 3.0.4 + */ +class TUserManagerPasswordMode extends TEnumerable +{ + const Clear='Clear'; + const MD5='MD5'; + const SHA1='SHA1'; +} + ?> \ No newline at end of file diff --git a/framework/TApplication.php b/framework/TApplication.php index 375df885..0cce1a1a 100644 --- a/framework/TApplication.php +++ b/framework/TApplication.php @@ -112,7 +112,8 @@ require_once(PRADO_DIR.'/I18N/TGlobalization.php'); class TApplication extends TComponent { /** - * application state + * possible application mode. + * @deprecated deprecated since version 3.0.4 (use TApplicationMode constants instead) */ const STATE_OFF='Off'; const STATE_DEBUG='Debug'; @@ -260,9 +261,9 @@ class TApplication extends TComponent */ private $_authRules=null; /** - * @var string application mode + * @var TApplicationMode application mode */ - private $_mode='Debug'; + private $_mode=TApplicationMode::Debug; /** * Constructor. @@ -465,7 +466,7 @@ class TApplication extends TComponent } /** - * @return string application mode (Off|Debug|Normal|Peformance), defaults to Debug. + * @return TApplicationMode application mode. Defaults to TApplicationMode::Debug. */ public function getMode() { @@ -473,11 +474,11 @@ class TApplication extends TComponent } /** - * @param string application mode. Valid values include Off, Debug, Normal, or Peformance + * @param TApplicationMode application mode */ public function setMode($value) { - $this->_mode=TPropertyValue::ensureEnum($value,array(self::STATE_OFF,self::STATE_DEBUG,self::STATE_NORMAL,self::STATE_PERFORMANCE)); + $this->_mode=TPropertyValue::ensureEnumerable($value,'TApplicationMode'); } /** @@ -1037,6 +1038,28 @@ class TApplication extends TComponent } } +/** + * TApplicationMode class. + * TApplicationMode defines the possible mode that an application can be set at by + * setting {@link TApplication::setMode Mode}. + * In particular, the following modes are defined + * - Off: the application is not running. Any request to the application will obtain an error. + * - Debug: the application is running in debug mode. + * - Debug: the application is running in normal production mode. + * - Performance: the application is running in performance mode. + * @author Qiang Xue + * @version $Revision: $ $Date: $ + * @package System + * @since 3.0.4 + */ +class TApplicationMode extends TEnumerable +{ + const Off='Off'; + const Debug='Debug'; + const Normal='Normal'; + const Performance='Performance'; +} + /** * TApplicationConfiguration class. diff --git a/framework/TComponent.php b/framework/TComponent.php index 21a62abd..b9dbd3d5 100644 --- a/framework/TComponent.php +++ b/framework/TComponent.php @@ -443,6 +443,32 @@ class TComponent } } +/** + * TEnumerable class. + * TEnumerable is the base class for all enumerable types. + * To define an enumerable type, extend TEnumberable and define string constants. + * Each constant represents an enumerable value. + * The constant name must be the same as the constant value. + * For example, + * + * class TTextAlign extends TEnumerable + * { + * const Left='Left'; + * const Right='Right'; + * } + * + * Then, one can use the enumerable values such as TTextAlign::Left and + * TTextAlign::Right. + * + * @author Qiang Xue + * @version $Revision: $ $Date: $ + * @package System + * @since 3.0 + */ +class TEnumerable +{ +} + /** * TPropertyValue class * @@ -568,6 +594,7 @@ class TPropertyValue /** * Converts a value to enum type. + * This method is deprecated. Try to use {@link ensureEnumerable}, instead. * This method mainly performs sanity check of a value to make sure * it is a valid enumeration value. Each enumeration value is a string * which is case-sensistive. @@ -577,6 +604,7 @@ class TPropertyValue * till the last parameters are enumeration values. * @return string the valid enumeration value * @throws TInvalidDataValueException if the original value is not in the string array. + * @deprecated deprecated since version 3.0.4 */ public static function ensureEnum($value,$enums) { @@ -590,6 +618,30 @@ class TPropertyValue else throw new TInvalidDataValueException('propertyvalue_enumvalue_invalid',$value,implode(' | ',$enums)); } + + /** + * Converts a value to enum type. + * This method checks if the value is of the specified enumerable type. + * A value is a valid enumerable value if it is equal to the name of a constant + * in the specified enumerable type (class). + * For more details about enumerable, see {@link TEnumerable}. + * @param string enumerable value + * @param string enumerable class name + * @return string valid enumerable value + * @throws TInvalidDataValueException if the original value is not a valid enumerable value. + * @see ensureEnum + * @sine 3.0.4 + */ + public static function ensureEnumerable($value,$enumType) + { + static $types=array(); + if(!isset($types[$enumType])) + $types[$enumType]=new ReflectionClass($enumType); + if($types[$enumType]->hasConstant($value)) + return $value; + else + throw new TInvalidDataValueException('propertyvalue_enumvalue_invalid',$value,$enumType); + } } /** diff --git a/framework/Util/TDataFieldAccessor.php b/framework/Util/TDataFieldAccessor.php index 6af972e9..a3dcbb00 100644 --- a/framework/Util/TDataFieldAccessor.php +++ b/framework/Util/TDataFieldAccessor.php @@ -50,7 +50,7 @@ class TDataFieldAccessor */ public static function getDataFieldValue($data,$field) { - if(Prado::getApplication()->getMode()===TApplication::STATE_PERFORMANCE) + if(Prado::getApplication()->getMode()===TApplicationMode::Performance) { if(is_array($data) || ($data instanceof ArrayAccess)) return $data[$field]; diff --git a/framework/Web/Javascripts/js/debug/validator.js b/framework/Web/Javascripts/js/debug/validator.js index d0293cbd..170d7ff1 100644 --- a/framework/Web/Javascripts/js/debug/validator.js +++ b/framework/Web/Javascripts/js/debug/validator.js @@ -348,7 +348,7 @@ Prado.WebUI.TValidationSummary.prototype = * options['DisplayMode'] Summary display style, 'BulletList', 'List', 'SingleParagraph' * options['Refresh'] True to update the summary upon validator state change. * options['ValidationGroup'] Validation summary group - * options['Display'] Display mode, 'None', 'Static', 'Dynamic'. + * options['Display'] Display mode, 'None', 'Fixed', 'Dynamic'. * options['ScrollToSummary'] True to scroll to the validation summary upon refresh. * */ @@ -554,7 +554,7 @@ Prado.WebUI.TBaseValidator.prototype = * options['ID']* Validator ID, e.g. span with message * options['FormID']* HTML form that the validator belongs * options['ControlToValidate']*HTML form input to validate - * options['Display'] Display mode, 'None', 'Static', 'Dynamic' + * options['Display'] Display mode, 'None', 'Fixed', 'Dynamic' * options['ErrorMessage'] Validation error message * options['FocusOnError'] True to focus on validation error * options['FocusElementID'] Element to focus on error diff --git a/framework/Web/Javascripts/prado/validation3.js b/framework/Web/Javascripts/prado/validation3.js index 67d490e3..714aa93f 100644 --- a/framework/Web/Javascripts/prado/validation3.js +++ b/framework/Web/Javascripts/prado/validation3.js @@ -348,7 +348,7 @@ Prado.WebUI.TValidationSummary.prototype = * options['DisplayMode'] Summary display style, 'BulletList', 'List', 'SingleParagraph' * options['Refresh'] True to update the summary upon validator state change. * options['ValidationGroup'] Validation summary group - * options['Display'] Display mode, 'None', 'Static', 'Dynamic'. + * options['Display'] Display mode, 'None', 'Fixed', 'Dynamic'. * options['ScrollToSummary'] True to scroll to the validation summary upon refresh. * */ @@ -554,7 +554,7 @@ Prado.WebUI.TBaseValidator.prototype = * options['ID']* Validator ID, e.g. span with message * options['FormID']* HTML form that the validator belongs * options['ControlToValidate']*HTML form input to validate - * options['Display'] Display mode, 'None', 'Static', 'Dynamic' + * options['Display'] Display mode, 'None', 'Fixed', 'Dynamic' * options['ErrorMessage'] Validation error message * options['FocusOnError'] True to focus on validation error * options['FocusElementID'] Element to focus on error diff --git a/framework/Web/Services/TPageService.php b/framework/Web/Services/TPageService.php index 5172f59c..6d3a69c7 100644 --- a/framework/Web/Services/TPageService.php +++ b/framework/Web/Services/TPageService.php @@ -244,7 +244,7 @@ class TPageService extends TService if(is_array($arr)) { list($pageConfig,$timestamps)=$arr; - if($application->getMode()!==TApplication::STATE_PERFORMANCE) + if($application->getMode()!==TApplicationMode::Performance) { foreach($timestamps as $fileName=>$timestamp) { diff --git a/framework/Web/TAssetManager.php b/framework/Web/TAssetManager.php index 707324d3..ac1ebee1 100644 --- a/framework/Web/TAssetManager.php +++ b/framework/Web/TAssetManager.php @@ -162,14 +162,14 @@ class TAssetManager extends TModule $dir=$this->hash(dirname($fullpath)); $fileName=basename($fullpath); $dst=$this->_basePath.'/'.$dir; - if(!is_file($dst.'/'.$fileName) || $checkTimestamp || $this->getApplication()->getMode()!==TApplication::STATE_PERFORMANCE) + if(!is_file($dst.'/'.$fileName) || $checkTimestamp || $this->getApplication()->getMode()!==TApplicationMode::Performance) $this->copyFile($fullpath,$dst); return $this->_published[$path]=$this->_baseUrl.'/'.$dir.'/'.$fileName; } else { $dir=$this->hash($fullpath); - if(!is_dir($this->_basePath.'/'.$dir) || $checkTimestamp || $this->getApplication()->getMode()!==TApplication::STATE_PERFORMANCE) + if(!is_dir($this->_basePath.'/'.$dir) || $checkTimestamp || $this->getApplication()->getMode()!==TApplicationMode::Performance) { Prado::trace("Publishing directory $fullpath",'System.Web.UI.TAssetManager'); $this->copyDirectory($fullpath,$this->_basePath.'/'.$dir); @@ -202,7 +202,7 @@ class TAssetManager extends TModule { @mkdir($dst); @chmod($dst, 0777); - } + } $dstFile=$dst.'/'.basename($src); if(@filemtime($dstFile)<@filemtime($src)) { @@ -263,7 +263,7 @@ class TAssetManager extends TModule $dir=$this->hash(dirname($fullpath)); $fileName=basename($fullpath); $dst=$this->_basePath.'/'.$dir; - if(!is_file($dst.'/'.$fileName) || $checkTimestamp || $this->getApplication()->getMode()!==TApplication::STATE_PERFORMANCE) + if(!is_file($dst.'/'.$fileName) || $checkTimestamp || $this->getApplication()->getMode()!==TApplicationMode::Performance) { if(@filemtime($dst.'/'.$fileName)<@filemtime($fullpath)) { diff --git a/framework/Web/THttpRequest.php b/framework/Web/THttpRequest.php index 130dc3cf..fcf1c8f9 100644 --- a/framework/Web/THttpRequest.php +++ b/framework/Web/THttpRequest.php @@ -88,7 +88,7 @@ class THttpRequest extends TApplicationComponent implements IteratorAggregate,Ar */ private $_pathInfo; - private $_urlFormat='Get'; + private $_urlFormat=THttpRequestUrlFormat::Get; private $_services; private $_requestResolved=false; private $_enableCookieValidation=false; @@ -160,7 +160,7 @@ class THttpRequest extends TApplicationComponent implements IteratorAggregate,Ar $_COOKIE=$this->stripSlashes($_COOKIE); } - if($this->getUrlFormat()==='Path' && ($pathInfo=trim($this->_pathInfo,'/'))!=='') + if($this->getUrlFormat()===THttpRequestUrlFormat::Path && ($pathInfo=trim($this->_pathInfo,'/'))!=='') $this->_items=array_merge($this->parseUrl(),$_POST); else $this->_items=array_merge($_GET,$_POST); @@ -205,7 +205,7 @@ class THttpRequest extends TApplicationComponent implements IteratorAggregate,Ar } /** - * @return string the format of URLs. Defaults to 'Get'. + * @return THttpRequestUrlFormat the format of URLs. Defaults to THttpRequestUrlFormat::Get. */ public function getUrlFormat() { @@ -214,15 +214,15 @@ class THttpRequest extends TApplicationComponent implements IteratorAggregate,Ar /** * Sets the format of URLs constructed and interpretted by the request module. - * A 'Get' URL format is like index.php?name1=value1&name2=value2 - * while a 'Path' URL format is like index.php/name1,value1/name2,value. + * A Get URL format is like index.php?name1=value1&name2=value2 + * while a Path URL format is like index.php/name1,value1/name2,value. * Changing the UrlFormat will affect {@link constructUrl} and how GET variables * are parsed. - * @param string the format of URLs. Valid values include 'Path' and 'Get'. + * @param THttpRequestUrlFormat the format of URLs. */ public function setUrlFormat($value) { - $this->_urlFormat=TPropertyValue::ensureEnum($value,'Path','Get'); + $this->_urlFormat=TPropertyValue::ensureEnumerable($value,'THttpRequestUrlFormat'); } /** @@ -467,7 +467,7 @@ class THttpRequest extends TApplicationComponent implements IteratorAggregate,Ar * If you do so, you may also need to override {@link parseUrl} so that the URL can be properly parsed. * The URL is constructed as the following format: * /entryscript.php?serviceID=serviceParameter&get1=value1&... - * If {@link setUrlFormat UrlFormat} is 'Path', the following format is used instead: + * If {@link setUrlFormat UrlFormat} is Path, the following format is used instead: * /entryscript.php/serviceID/serviceParameter/get1,value1/get2,value2... * @param string service ID * @param string service parameter @@ -511,7 +511,7 @@ class THttpRequest extends TApplicationComponent implements IteratorAggregate,Ar } } } - if($this->getUrlFormat()==='Path') + if($this->getUrlFormat()===THttpRequestUrlFormat::Path) { $url=strtr($url,array($amp=>'/','?'=>'/','='=>$this->_separator)); if(defined('SID') && SID != '' && !((int)ini_get('session.use_cookies')===1 && ((int)ini_get('session.use_only_cookies')===1))) @@ -528,7 +528,7 @@ class THttpRequest extends TApplicationComponent implements IteratorAggregate,Ar /** * Parses the request URL and returns an array of input parameters (including GET variables). - * This method is invoked when the URL format is 'Path'. + * This method is invoked when the URL format is Path. * You may override this method to support customized URL format. * @return array list of input parameters, indexed by parameter names * @see constructUrl @@ -1199,4 +1199,24 @@ class TUri extends TComponent } } +/** + * THttpRequestUrlFormat class. + * THttpRequestUrlFormat defines the enumerable type for the possible URL formats + * that can be recognized by {@link THttpRequest}. + * + * The following enumerable values are defined: + * - Get: the URL format is like /path/to/index.php?name1=value1&name2=value2... + * - Path: the URL format is like /path/to/index.php/name1,value1/name2,value2... + * + * @author Qiang Xue + * @version $Revision: $ $Date: $ + * @package System.Web + * @since 3.0.4 + */ +class THttpRequestUrlFormat extends TEnumerable +{ + const Get='Get'; + const Path='Path'; +} + ?> \ No newline at end of file diff --git a/framework/Web/THttpSession.php b/framework/Web/THttpSession.php index 19473cda..810d8e60 100644 --- a/framework/Web/THttpSession.php +++ b/framework/Web/THttpSession.php @@ -271,22 +271,20 @@ class THttpSession extends TApplicationComponent implements IteratorAggregate,Ar } /** - * @return string (None|Allow|Only) how to use cookie to store session ID - * 'None' means not using cookie, 'Allow' means using cookie, and 'Only' means using cookie only, defaults to 'Allow'. + * @return THttpSessionCookieMode how to use cookie to store session ID. Defaults to THttpSessionCookieMode::Allow. */ public function getCookieMode() { if(ini_get('session.use_cookies')==='0') - return 'None'; + return THttpSessionCookieMode::None; else if(ini_get('session.use_only_cookies')==='0') - return 'Allow'; + return THttpSessionCookieMode::Allow; else - return 'Only'; + return THttpSessionCookieMode::Only; } /** - * @param string (None|Allow|Only) how to use cookie to store session ID - * 'None' means not using cookie, 'Allow' means using cookie, and 'Only' means using cookie only. + * @param THttpSessionCookieMode how to use cookie to store session ID * @throws TInvalidOperationException if session is started already */ public function setCookieMode($value) @@ -295,10 +293,10 @@ class THttpSession extends TApplicationComponent implements IteratorAggregate,Ar throw new TInvalidOperationException('httpsession_cookiemode_unchangeable'); else { - $value=TPropertyValue::ensureEnum($value,array('None','Allow','Only')); - if($value==='None') + $value=TPropertyValue::ensureEnumerable($value,'THttpSessionCookieMode'); + if($value===THttpSessionCookieMode::None) ini_set('session.use_cookies','0'); - else if($value==='Allow') + else if($value===THttpSessionCookieMode::Allow) { ini_set('session.use_cookies','1'); ini_set('session.use_only_cookies','0'); @@ -695,4 +693,28 @@ class TSessionIterator implements Iterator return $this->_key!==false; } } + + +/** + * THttpSessionCookieMode class. + * THttpSessionCookieMode defines the enumerable type for the possible methods of + * using cookies to store session ID. + * + * The following enumerable values are defined: + * - None: not using cookie. + * - Allow: using cookie. + * - Only: using cookie only. + * + * @author Qiang Xue + * @version $Revision: $ $Date: $ + * @package System.Web + * @since 3.0.4 + */ +class THttpSessionCookieMode extends TEnumerable +{ + const None='None'; + const Allow='Allow'; + const Only='Only'; +} + ?> \ No newline at end of file diff --git a/framework/Web/UI/TClientScriptManager.php b/framework/Web/UI/TClientScriptManager.php index 49a34a02..dfd78ba6 100644 --- a/framework/Web/UI/TClientScriptManager.php +++ b/framework/Web/UI/TClientScriptManager.php @@ -139,7 +139,7 @@ class TClientScriptManager extends TApplicationComponent protected function getPradoScriptBasePath() { $basePath = Prado::getFrameworkPath().'/'.self::SCRIPT_PATH; - if($this->getApplication()->getMode()===TApplication::STATE_DEBUG) + if($this->getApplication()->getMode()===TApplicationMode::Debug) return $basePath.'/debug'; else return $basePath.'/compressed'; @@ -165,7 +165,7 @@ class TClientScriptManager extends TApplicationComponent $basePath=$this->getPradoScriptBasePath(); $scriptLoader=$basePath.'/'.self::SCRIPT_LOADER; $url=$this->publishFilePath($scriptLoader).'?js='.trim($files,','); - if($this->getApplication()->getMode()===TApplication::STATE_DEBUG) + if($this->getApplication()->getMode()===TApplicationMode::Debug) $url.='&mode=debug'; $writer->write(TJavaScript::renderScriptFile($url)); } diff --git a/framework/Web/UI/TThemeManager.php b/framework/Web/UI/TThemeManager.php index 1d80d0c5..ce96a6b4 100644 --- a/framework/Web/UI/TThemeManager.php +++ b/framework/Web/UI/TThemeManager.php @@ -240,7 +240,7 @@ class TTheme extends TApplicationComponent implements ITheme if(is_array($array)) { list($skins,$cssFiles,$jsFiles,$timestamp)=$array; - if($this->getApplication()->getMode()!==TApplication::STATE_PERFORMANCE) + if($this->getApplication()->getMode()!==TApplicationMode::Performance) { if(($dir=opendir($themePath))===false) throw new TIOException('theme_path_inexistent',$themePath); diff --git a/framework/Web/UI/WebControls/TBaseValidator.php b/framework/Web/UI/WebControls/TBaseValidator.php index 5c75273e..711dd2c4 100644 --- a/framework/Web/UI/WebControls/TBaseValidator.php +++ b/framework/Web/UI/WebControls/TBaseValidator.php @@ -136,7 +136,7 @@ abstract class TBaseValidator extends TLabel implements IValidator { $display=$this->getDisplay(); $visible=$this->getEnabled(true) && !$this->getIsValid(); - if($display==='None' || (!$visible && $display==='Dynamic')) + if($display===TValidatorDisplayStyle::None || (!$visible && $display===TValidatorDisplayStyle::Dynamic)) $writer->addStyleAttribute('display','none'); else if(!$visible) $writer->addStyleAttribute('visibility','hidden'); @@ -311,20 +311,19 @@ abstract class TBaseValidator extends TLabel implements IValidator } /** - * @return string the display behavior (None, Static, Dynamic) of the error message in a validation control. Defaults to Static. + * @return TValidatorDisplayStyle the style of displaying the error message. Defaults to TValidatorDisplayStyle::Fixed. */ public function getDisplay() { - return $this->getViewState('Display','Static'); + return $this->getViewState('Display',TValidatorDisplayStyle::Fixed); } /** - * Sets the display behavior (None, Static, Dynamic) of the error message in a validation control. - * @param string the display behavior (None, Static, Dynamic) + * @param TValidatorDisplayStyle the style of displaying the error message */ public function setDisplay($value) { - $this->setViewState('Display',TPropertyValue::ensureEnum($value,array('None','Static','Dynamic')),'Static'); + $this->setViewState('Display',TPropertyValue::ensureEnumerable($value,'TValidatorDisplayStyle'),TValidatorDisplayStyle::Fixed); } /** @@ -664,4 +663,26 @@ class TValidatorClientSide extends TClientSideOptions } } + +/** + * TValidatorDisplayStyle class. + * TValidatorDisplayStyle defines the enumerable type for the possible styles + * that a validator control can display the error message. + * + * The following enumerable values are defined: + * - None: the error message is not displayed + * - Dynamic: the error message dynamically appears when the validator fails validation + * - Fixed: Similar to Dynamic except that the error message physically occupies the page layout (even though it may not be visible) + * + * @author Qiang Xue + * @version $Revision: $ $Date: $ + * @package System.Web.UI.WebControls + * @since 3.0.4 + */ +class TValidatorDisplayStyle extends TEnumerable +{ + const None='None'; + const Dynamic='Dynamic'; + const Fixed='Fixed'; +} ?> \ No newline at end of file diff --git a/framework/Web/UI/WebControls/TTextBox.php b/framework/Web/UI/WebControls/TTextBox.php index feea6227..96c43092 100644 --- a/framework/Web/UI/WebControls/TTextBox.php +++ b/framework/Web/UI/WebControls/TTextBox.php @@ -58,10 +58,6 @@ class TTextBox extends TWebControl implements IPostBackDataHandler, IValidatable * Default number of columns (for MultiLine text box) */ const DEFAULT_COLUMNS=20; - /** - * @var array list of auto complete types - */ - private static $_autoCompleteTypes=array('BusinessCity','BusinessCountryRegion','BusinessFax','BusinessPhone','BusinessState','BusinessStreetAddress','BusinessUrl','BusinessZipCode','Cellular','Company','Department','Disabled','DisplayName','Email','FirstName','Gender','HomeCity','HomeCountryRegion','HomeFax','Homepage','HomePhone','HomeState','HomeStreetAddress','HomeZipCode','JobTitle','LastName','MiddleName','None','Notes','Office','Pager','Search'); /** * @var mixed safe text parser */ @@ -90,7 +86,7 @@ class TTextBox extends TWebControl implements IPostBackDataHandler, IValidatable $page->ensureRenderInForm($this); if(($uid=$this->getUniqueID())!=='') $writer->addAttribute('name',$uid); - if(($textMode=$this->getTextMode())==='MultiLine') + if(($textMode=$this->getTextMode())===TTextBoxMode::MultiLine) { if(($rows=$this->getRows())<=0) $rows=self::DEFAULT_ROWS; @@ -103,7 +99,7 @@ class TTextBox extends TWebControl implements IPostBackDataHandler, IValidatable } else { - if($textMode==='SingleLine') + if($textMode===TTextBoxMode::SingleLine) { $writer->addAttribute('type','text'); if(($text=$this->getText())!=='') @@ -233,27 +229,20 @@ class TTextBox extends TWebControl implements IPostBackDataHandler, IValidatable } /** - * @return string the AutoComplete type of the textbox + * @return TTextBoxAutoCompleteType the AutoComplete type of the textbox */ public function getAutoCompleteType() { - return $this->getViewState('AutoCompleteType','None'); + return $this->getViewState('AutoCompleteType',TTextBoxAutoCompleteType::None); } /** - * @param string the AutoComplete type of the textbox, default value is 'None'. - * Valid values include: - * 'BusinessCity','BusinessCountryRegion','BusinessFax','BusinessPhone', - * 'BusinessState','BusinessStreetAddress','BusinessUrl','BusinessZipCode', - * 'Cellular','Company','Department','Disabled','DisplayName','Email', - * 'FirstName','Gender','HomeCity','HomeCountryRegion','HomeFax','Homepage', - * 'HomePhone','HomeState','HomeStreetAddress','HomeZipCode','JobTitle', - * 'LastName','MiddleName','None','Notes','Office','Pager','Search' + * @param TTextBoxAutoCompleteType the AutoComplete type of the textbox, default value is TTextBoxAutoCompleteType::None. * @throws TInvalidDataValueException if the input parameter is not a valid AutoComplete type */ public function setAutoCompleteType($value) { - $this->setViewState('AutoCompleteType',TPropertyValue::ensureEnum($value,self::$_autoCompleteTypes),'None'); + $this->setViewState('AutoCompleteType',TPropertyValue::ensureEnumerable($value,'TTextBoxAutoCompleteType'),TTextBoxAutoCompleteType::None); } /** @@ -416,21 +405,21 @@ class TTextBox extends TWebControl implements IPostBackDataHandler, IValidatable } /** - * @return string the behavior mode (SingleLine, MultiLine, or Password) of the TTextBox component. Defaults to SingleLine. + * @return TTextBoxMode the behavior mode of the TTextBox component. Defaults to TTextBoxMode::SingleLine. */ public function getTextMode() { - return $this->getViewState('TextMode','SingleLine'); + return $this->getViewState('TextMode',TTextBoxMode::SingleLine); } /** - * Sets the behavior mode (SingleLine, MultiLine, or Password) of the TTextBox component. - * @param string the text mode + * Sets the behavior mode of the TTextBox component. + * @param TTextBoxMode the text mode * @throws TInvalidDataValueException if the input value is not a valid text mode. */ public function setTextMode($value) { - $this->setViewState('TextMode',TPropertyValue::ensureEnum($value,array('SingleLine','MultiLine','Password')),'SingleLine'); + $this->setViewState('TextMode',TPropertyValue::ensureEnumerable($value,'TTextBoxMode'),TTextBoxMode::SingleLine); } /** @@ -467,4 +456,72 @@ class TTextBox extends TWebControl implements IPostBackDataHandler, IValidatable } } +/** + * TTextBoxMode class. + * TTextBoxMode defines the enumerable type for the possible mode + * that a {@link TTextBox} control could be at. + * + * The following enumerable values are defined: + * - SingleLine: the textbox will be a regular single line input + * - MultiLine: the textbox will be a textarea allowing multiple line input + * - Password: the textbox will hide user input like a password input box + * + * @author Qiang Xue + * @version $Revision: $ $Date: $ + * @package System.Web.UI.WebControls + * @since 3.0.4 + */ +class TTextBoxMode extends TEnumerable +{ + const SingleLine='SingleLine'; + const MultiLine='MultiLine'; + const Password='Password'; +} + +/** + * TTextBoxAutoCompleteType class. + * TTextBoxAutoCompleteType defines the possible AutoComplete type that is supported + * by a {@link TTextBox} control. + * + * @author Qiang Xue + * @version $Revision: $ $Date: $ + * @package System.Web.UI.WebControls + * @since 3.0.4 + */ +class TTextBoxAutoCompleteType extends TEnumerable +{ + const BusinessCity='BusinessCity'; + const BusinessCountryRegion='BusinessCountryRegion'; + const BusinessFax='BusinessFax'; + const BusinessPhone='BusinessPhone'; + const BusinessState='BusinessState'; + const BusinessStreetAddress='BusinessStreetAddress'; + const BusinessUrl='BusinessUrl'; + const BusinessZipCode='BusinessZipCode'; + const Cellular='Cellular'; + const Company='Company'; + const Department='Department'; + const Disabled='Disabled'; + const DisplayName='DisplayName'; + const Email='Email'; + const FirstName='FirstName'; + const Gender='Gender'; + const HomeCity='HomeCity'; + const HomeCountryRegion='HomeCountryRegion'; + const HomeFax='HomeFax'; + const Homepage='Homepage'; + const HomePhone='HomePhone'; + const HomeState='HomeState'; + const HomeStreetAddress='HomeStreetAddress'; + const HomeZipCode='HomeZipCode'; + const JobTitle='JobTitle'; + const LastName='LastName'; + const MiddleName='MiddleName'; + const None='None'; + const Notes='Notes'; + const Office='Office'; + const Pager='Pager'; + const Search='Search'; +} + ?> \ No newline at end of file diff --git a/framework/Web/UI/WebControls/TValidationSummary.php b/framework/Web/UI/WebControls/TValidationSummary.php index c7330f94..539c6dc3 100644 --- a/framework/Web/UI/WebControls/TValidationSummary.php +++ b/framework/Web/UI/WebControls/TValidationSummary.php @@ -52,20 +52,19 @@ class TValidationSummary extends TWebControl } /** - * @return string the display behavior (None, Static, Dynamic) of the error message in a validation summary component. + * @return TValidationSummaryDisplayStyle the style of displaying the error messages. Defaults to TValidationSummaryDisplayStyle::Fixed. */ public function getDisplay() { - return $this->getViewState('Display','Static'); + return $this->getViewState('Display',TValidationSummaryDisplayStyle::Fixed); } /** - * Sets the display behavior (None, Static, Dynamic) of the error message in a validation summary component. - * @param string the display behavior (None, Static, Dynamic) + * @param TValidationSummaryDisplayStyle the style of displaying the error messages */ public function setDisplay($value) { - $this->setViewState('Display',TPropertyValue::ensureEnum($value,'None','Dynamic','Static'),'Static'); + $this->setViewState('Display',TPropertyValue::ensureEnumerable($value,'TValidationSummaryDisplayStyle'),TValidationSummaryDisplayStyle::Fixed); } /** @@ -86,20 +85,19 @@ class TValidationSummary extends TWebControl } /** - * @return string the display mode (BulletList, List, SingleParagraph) of the validation summary. Defaults to BulletList. + * @return TValidationSummaryDisplayMode the mode of displaying error messages. Defaults to TValidationSummaryDisplayMode::BulletList. */ public function getDisplayMode() { - return $this->getViewState('DisplayMode','BulletList'); + return $this->getViewState('DisplayMode',TValidationSummaryDisplayMode::BulletList); } /** - * Sets the display mode (BulletList, List, SingleParagraph) of the validation summary. - * @param string the display mode (BulletList, List, SingleParagraph) + * @param TValidationSummaryDisplayMode the mode of displaying error messages */ public function setDisplayMode($value) { - $this->setViewState('DisplayMode',TPropertyValue::ensureEnum($value,'List','SingleParagraph','BulletList'),'BulletList'); + $this->setViewState('DisplayMode',TPropertyValue::ensureEnumerable($value,'TValidationSummaryDisplayMode'),TValidationSummaryDisplayMode::BulletList); } /** @@ -206,7 +204,7 @@ class TValidationSummary extends TWebControl $visible=$this->getEnabled(true) && count($this->getErrorMessages()) > 0; if(!$visible) { - if($display==='None' || $display==='Dynamic') + if($display===TValidationSummaryDisplayStyle::None || $display===TValidationSummaryDisplayStyle::Dynamic) $writer->addStyleAttribute('display','none'); else $writer->addStyleAttribute('visibility','hidden'); @@ -318,13 +316,13 @@ class TValidationSummary extends TWebControl // $this->setStyle('display:block'); switch($this->getDisplayMode()) { - case 'List': + case TValidationSummaryDisplayMode::SimpleList: $this->renderList($writer); break; - case 'SingleParagraph': + case TValidationSummaryDisplayMode::SingleParagraph: $this->renderSingleParagraph($writer); break; - case 'BulletList': + case TValidationSummaryDisplayMode::BulletList: $this->renderBulletList($writer); break; } @@ -449,4 +447,50 @@ class TValidationSummaryClientScript extends TClientSideOptions } } + +/** + * TValidationSummaryDisplayMode class. + * TValidationSummaryDisplayMode defines the enumerable type for the possible modes + * that a {@link TValidationSummary} can organize and display the collected error messages. + * + * The following enumerable values are defined: + * - SimpleList: the error messages are displayed as a list without any decorations. + * - SingleParagraph: the error messages are concatenated together into a paragraph. + * - BulletList: the error messages are displayed as a bulleted list. + * + * @author Qiang Xue + * @version $Revision: $ $Date: $ + * @package System.Web.UI.WebControls + * @since 3.0.4 + */ +class TValidationSummaryDisplayMode extends TEnumerable +{ + const SimpleList='SimpleList'; + const SingleParagraph='SingleParagraph'; + const BulletList='BulletList'; +} + + +/** + * TValidationSummaryDisplay class. + * TValidationSummaryDisplay defines the enumerable type for the possible styles + * that a {@link TValidationSummary} can display the collected error messages. + * + * The following enumerable values are defined: + * - None: the error messages are not displayed + * - Dynamic: the error messages are dynamically added to display as the corresponding validators fail + * - Fixed: Similar to Dynamic except that the error messages physically occupy the page layout (even though they may not be visible) + * + * @author Qiang Xue + * @version $Revision: $ $Date: $ + * @package System.Web.UI.WebControls + * @since 3.0.4 + */ +class TValidationSummaryDisplayStyle extends TEnumerable +{ + const None='None'; + const Dynamic='Dynamic'; + const Fixed='Fixed'; +} + ?> \ No newline at end of file diff --git a/framework/Web/UI/WebControls/TWizard.php b/framework/Web/UI/WebControls/TWizard.php index 2d54afbe..0a9bb58c 100644 --- a/framework/Web/UI/WebControls/TWizard.php +++ b/framework/Web/UI/WebControls/TWizard.php @@ -85,6 +85,7 @@ class TWizard extends TWebControl implements INamingContainer { /** * Wizard step types. + * @deprecated deprecated since version 3.0.4 (use TWizardStepType constants instead) */ const ST_AUTO='Auto'; const ST_START='Start'; @@ -918,7 +919,7 @@ class TWizard extends TWebControl implements INamingContainer } } $activeStepType=$this->getStepType($activeStep); - if($activeStepType===self::ST_COMPLETE) + if($activeStepType===TWizardStepType::Complete) { $this->_sideBar->setVisible(false); $this->_header->setVisible(false); @@ -1014,24 +1015,24 @@ class TWizard extends TWebControl implements INamingContainer /** * Determines the type of the specified wizard step. * @param TWizardStep - * @return string type of the step, 'Finish', 'Start', 'Step'. + * @return TWizardStepType type of the step */ protected function getStepType($wizardStep) { - if(($type=$wizardStep->getStepType())===self::ST_AUTO) + if(($type=$wizardStep->getStepType())===TWizardStepType::Auto) { $steps=$this->getWizardSteps(); if(($index=$steps->indexOf($wizardStep))>=0) { $stepCount=$steps->getCount(); - if($stepCount===1 || ($index<$stepCount-1 && $steps->itemAt($index+1)->getStepType()==='Complete')) - return self::ST_FINISH; + if($stepCount===1 || ($index<$stepCount-1 && $steps->itemAt($index+1)->getStepType()===TWizardStepType::Complete)) + return TWizardStepType::Finish; else if($index===0) - return self::ST_START; + return TWizardStepType::Start; else if($index===$stepCount-1) - return self::ST_FINISH; + return TWizardStepType::Finish; else - return self::ST_STEP; + return TWizardStepType::Step; } else return $type; @@ -1162,7 +1163,7 @@ class TWizard extends TWebControl implements INamingContainer if(($button=$item->findControl(self::ID_SIDEBAR_BUTTON))!==null) { $step=$item->getDataItem(); - if(($this->getStepType($step)==='Complete')) + if(($this->getStepType($step)===TWizardStepType::Complete)) $button->setEnabled(false); if(($title=$step->getTitle())!=='') $button->setText($title); @@ -1515,19 +1516,19 @@ class TWizardNavigationButtonStyle extends TStyle } /** - * @return string button type. Default to 'Button'. + * @return TWizardNavigationButtonType button type. Default to TWizardNavigationButtonType::Button. */ public function getButtonType() { - return $this->_buttonType===null?'Button':$this->_buttonType; + return $this->_buttonType===null? TWizardNavigationButtonType::Button :$this->_buttonType; } /** - * @param string button type. Valid values include 'Button', 'Image', 'Link'. + * @param TWizardNavigationButtonType button type. */ public function setButtonType($value) { - $this->_buttonType=TPropertyValue::ensureEnum($value,'Button','Image','Link'); + $this->_buttonType=TPropertyValue::ensureEnumerable($value,'TWizardNavigationButtonType'); } /** @@ -1618,22 +1619,22 @@ class TWizardStep extends TView } /** - * @return string the wizard step type. Defaults to 'Auto'. + * @return TWizardStepType the wizard step type. Defaults to TWizardStepType::Auto. */ public function getStepType() { - return $this->getViewState('StepType',TWizard::ST_AUTO); + return $this->getViewState('StepType',TWizardStepType::Auto); } /** - * @param string the wizard step type. Valid values include 'Auto', 'Complete', 'Start', 'Step', 'Finish'. + * @param TWizardStepType the wizard step type. */ public function setStepType($type) { - $type=TPropertyValue::ensureEnum($type,TWizard::ST_AUTO,TWizard::ST_COMPLETE,TWizard::ST_STEP,TWizard::ST_START,TWizard::ST_FINISH); + $type=TPropertyValue::ensureEnumerable($type,'TWizardStepType'); if($type!==$this->getStepType()) { - $this->setViewState('StepType',$type,TWizard::ST_AUTO); + $this->setViewState('StepType',$type,TWizardStepType::Auto); if($this->_wizard) $this->_wizard->wizardStepsChanged(); } @@ -1644,7 +1645,7 @@ class TWizardStep extends TView /** * TCompleteWizardStep class. * - * TCompleteWizardStep represents a wizard step of type 'Complete'. + * TCompleteWizardStep represents a wizard step of type TWizardStepType::Complete. * * @author Qiang Xue * @version $Revision: $ $Date: $ @@ -1654,11 +1655,11 @@ class TWizardStep extends TView class TCompleteWizardStep extends TWizardStep { /** - * @return string the wizard step type. Always 'Complete'. + * @return TWizardStepType the wizard step type. Always TWizardStepType::Complete. */ public function getStepType() { - return 'Complete'; + return TWizardStepType::Complete; } /** @@ -2100,13 +2101,13 @@ class TWizardNavigationTemplate extends TComponent implements ITemplate { switch($buttonStyle->getButtonType()) { - case 'Button': + case TWizardNavigationButtonType::Button: $button=new TButton; break; - case 'Link' : + case TWizardNavigationButtonType::Link: $button=new TLinkButton; break; - case 'Image' : + case TWizardNavigationButtonType::Image: $button=new TImageButton; $button->setImageUrl($buttonStyle->getImageUrl()); break; @@ -2218,4 +2219,53 @@ class TWizardStepNavigationTemplate extends TWizardNavigationTemplate } } + +/** + * TWizardNavigationButtonType class. + * TWizardNavigationButtonType defines the enumerable type for the possible types of buttons + * that can be used in the navigation part of a {@link TWizard}. + * + * The following enumerable values are defined: + * - Button: a regular click button + * - Image: an image button + * - Link: a hyperlink button + * + * @author Qiang Xue + * @version $Revision: $ $Date: $ + * @package System.Web.UI.WebControls + * @since 3.0.4 + */ +class TWizardNavigationButtonType extends TEnumerable +{ + const Button='Button'; + const Image='Image'; + const Link='Link'; +} + + +/** + * TWizardStepType class. + * TWizardStepType defines the enumerable type for the possible types of {@link TWizard wizard} steps. + * + * The following enumerable values are defined: + * - Auto: the type is automatically determined based on the location of the wizard step in the whole step collection. + * - Complete: the step is the last summary step. + * - Start: the step is the first step + * - Step: the step is between the begin and the end steps. + * - Finish: the last step before the Complete step. + * + * @author Qiang Xue + * @version $Revision: $ $Date: $ + * @package System.Web.UI.WebControls + * @since 3.0.4 + */ +class TWizardStepType extends TEnumerable +{ + const Auto='Auto'; + const Complete='Complete'; + const Start='Start'; + const Step='Step'; + const Finish='Finish'; +} + ?> \ No newline at end of file -- cgit v1.2.3