From c9cbb1a2891543bff1c459af18c2c62f47a17d28 Mon Sep 17 00:00:00 2001 From: xue <> Date: Fri, 18 Nov 2005 00:46:02 +0000 Subject: --- framework/Exceptions/messages.en | 18 ++++++++++ framework/TApplication.php | 6 ++++ framework/Web/TAssetManager.php | 2 +- framework/Web/THttpRequest.php | 52 +++++++++++++-------------- framework/Web/THttpResponse.php | 16 +++++++-- framework/Web/THttpSession.php | 72 +++++++++++++++++++++++++------------- framework/Web/UI/TThemeManager.php | 4 +-- 7 files changed, 112 insertions(+), 58 deletions(-) (limited to 'framework') diff --git a/framework/Exceptions/messages.en b/framework/Exceptions/messages.en index 136fe3df..c573db82 100644 --- a/framework/Exceptions/messages.en +++ b/framework/Exceptions/messages.en @@ -7,6 +7,8 @@ component_statements_invalid = Component '%s' is evaluating invalid PHP statem propertyvalue_enumvalue_invalid = Value '%s' is a not valid enumeration value (%s). +uri_format_invalid = '%s' is not a valid URI. + application_configfile_inexistent = Application configuration file "%s" does not exist. application_module_existing = Application module "%s" cannot be registered twice. application_service_invalid = Service "%s" must implement IService interface. @@ -21,6 +23,22 @@ appconfig_serviceid_required = Application configuration element mus appconfig_servicetype_required = Application configuration must have a "type" attribute. appconfig_parameterid_required = Application configuration element must have an "id" attribute. +httpresponse_bufferoutput_unchangeable = Property THttpResponse.BufferOutput cannot be modified after THttpResponse is initialized. +httpresponse_file_inexistent = THttpResponse cannot send file '%s'. The file does not exist. + +httpsession_sessionid_unchangeable = Session ID cannot be modified after the session is started. +httpsession_sessionname_unchangeable = Session name cannot be modified after the session is started. +httpsession_sessionname_invalid = Session name must contain alphanumeric characters only. +httpsession_savepath_unchangeable = Session SavePath cannot be modified after the session is started. +httpsession_savepath_invalid = Session SavePath '%s' is invalid. +httpsession_storage_unchangeable = Session storage cannot be modified after the session is started. +httpsession_cookiemode_unchangeable = Session CookieMode cannot be modified after the session is started. +httpsession_autostart_unchangeable = Session AutoStart cannot be modified after the session module is initialized. +httpsession_gcprobability_unchangeable = Session GCProbability cannot be modified after the session is started. +httpsession_gcprobability_invalid = Session GCProbability must be an integer between 0 and 100. +httpsession_transid_unchangeable = Session UseTransparentSessionID cannot be modified after the session is started. +httpsession_maxlifetime_unchangeable = Session Timeout cannot be modified after the session is started. + body_contents_not_allowed = %s: body contents are not allowed. control_id_not_unique = Control ID '%s' is not unique for control type '%s'. control_not_found = Unable to find a control with ID '%s'. diff --git a/framework/TApplication.php b/framework/TApplication.php index 9ac9a8a0..7c9de44a 100644 --- a/framework/TApplication.php +++ b/framework/TApplication.php @@ -58,10 +58,16 @@ require_once(PRADO_DIR.'/Web/Services/TPageService.php'); * the application, the modules, the services, the parameters, and so on. * * Examples: + * - Create and run a Prado application: * * $application=new TApplication($configFile); * $application->run(); * + * - The parsed application configuration file is cached. + * + * $application=new TApplication($configFile,$cacheFile); + * $application->run(); + * * * @author Qiang Xue * @version $Revision: $ $Date: $ diff --git a/framework/Web/TAssetManager.php b/framework/Web/TAssetManager.php index f36714aa..4147ce2d 100644 --- a/framework/Web/TAssetManager.php +++ b/framework/Web/TAssetManager.php @@ -127,7 +127,7 @@ class TAssetManager extends TComponent implements IModule public function setBaseUrl($value) { if($this->_initialized) - throw new TInvalidOperationException('pageservice_baseurl_unchangeable'); + throw new TInvalidOperationException('assetmanager_baseurl_unchangeable'); else $this->_baseUrl=$value; } diff --git a/framework/Web/THttpRequest.php b/framework/Web/THttpRequest.php index 02bf557f..dd1bd662 100644 --- a/framework/Web/THttpRequest.php +++ b/framework/Web/THttpRequest.php @@ -1,6 +1,6 @@ * @link http://www.pradosoft.com/ @@ -16,7 +16,13 @@ * THttpRequest provides storage and access scheme for user request sent via HTTP. * It also encapsulates a uniform way to parse and construct URLs. * - * THttpRequest is the default "request" module for prado application. + * To retrieve user POST and GET variables, use {@link getItems()} method. + * To construct a URL that can be recognized by Prado, use {@link constructUrl()}. + * THttpRequest also provides the cookies sent by the user, user information such + * as his browser capabilities, accepted languages, etc. + * + * By default, THttpRequest is registered with {@link TApplication} as the + * request module. It can be accessed via {@link TApplication::getRequest()}. * * @author Qiang Xue * @version $Revision: $ $Date: $ @@ -62,26 +68,6 @@ class THttpRequest extends TComponent implements IModule */ private $_items; - /** - * Constructor. - * Analyzes and resolves user request. - */ - public function __construct() - { - } - - /** - * Strips slashes from input data. - * This method is applied when magic quotes is enabled. - * Do not call this method. - * @param mixed input data to be processed - * @param mixed processed data - */ - public function stripSlashes(&$data) - { - return is_array($data)?array_map(array($this,'stripSlashes'),$data):stripslashes($data); - } - /** * Initializes the module. * This method is required by IModule and is invoked by application. @@ -95,7 +81,6 @@ class THttpRequest extends TComponent implements IModule // SCRIPT_NAME is the real URI for the requested script (w/o path info and query string) // REQUEST_URI contains the URI part entered in the browser address bar // SCRIPT_FILENAME is the file path to the executing script - parent::__construct(); if(isset($_SERVER['REQUEST_URI'])) $this->_requestUri=$_SERVER['REQUEST_URI']; else // TBD: in this case, SCRIPT_NAME need to be escaped @@ -111,13 +96,13 @@ class THttpRequest extends TComponent implements IModule if(get_magic_quotes_gpc()) { if(isset($_GET)) - $_GET=array_map(array($this,'stripSlashes'),$_GET); + $_GET=$this->stripSlashes($_GET); if(isset($_POST)) - $_POST=array_map(array($this,'stripSlashes'),$_POST); + $_POST=$this->stripSlashes($_POST); if(isset($_REQUEST)) - $_REQUEST=array_map(array($this,'stripSlashes'),$_REQUEST); + $_REQUEST=$this->stripSlashes($_REQUEST); if(isset($_COOKIE)) - $_COOKIE=array_map(array($this,'stripSlashes'),$_COOKIE); + $_COOKIE=$this->stripSlashes($_COOKIE); } $this->_items=new TMap(array_merge($_POST,$_GET)); @@ -127,6 +112,17 @@ class THttpRequest extends TComponent implements IModule $application->setRequest($this); } + /** + * Strips slashes from input data. + * This method is applied when magic quotes is enabled. + * @param mixed input data to be processed + * @param mixed processed data + */ + public function stripSlashes(&$data) + { + return is_array($data)?array_map(array($this,'stripSlashes'),$data):stripslashes($data); + } + /** * @return string id of this module */ @@ -220,7 +216,7 @@ class THttpRequest extends TComponent implements IModule */ public function getPhysicalApplicationPath() { - return strtr($_SERVER['SCRIPT_FILENAME'],'\\','/'); + return realpath($_SERVER['SCRIPT_FILENAME']); } /** diff --git a/framework/Web/THttpResponse.php b/framework/Web/THttpResponse.php index 6146b4f0..7f70de63 100644 --- a/framework/Web/THttpResponse.php +++ b/framework/Web/THttpResponse.php @@ -13,9 +13,19 @@ /** * THttpResponse class * - * THttpResponse implements a scheme to output response to user requests. + * THttpResponse implements the mechanism for sending output to client users. * - * THttpResponse is the default "response" module for prado application. + * To output a string to client, use {@link write()}. By default, the output is + * buffered until {@link flush()} is called or the application ends. The output in + * the buffer can also be cleaned by {@link clear()}. To disable output buffering, + * set BufferOutput property to false. + * + * To send cookies to client, use {@link getCookies()}. + * To redirect client browser to a new URL, use {@link redirect()}. + * To send a file to client, use {@link writeFile()}. + * + * By default, THttpResponse is registered with {@link TApplication} as the + * response module. It can be accessed via {@link TApplication::getResponse()}. * * @author Qiang Xue * @version $Revision: $ $Date: $ @@ -41,7 +51,7 @@ class THttpResponse extends TComponent implements IModule, ITextWriter */ private $_cookies=null; /** - * @var integer status code + * @var integer response status code */ private $_status=200; diff --git a/framework/Web/THttpSession.php b/framework/Web/THttpSession.php index fcecde1f..f9aed384 100644 --- a/framework/Web/THttpSession.php +++ b/framework/Web/THttpSession.php @@ -28,13 +28,16 @@ * * * The following configurations are available for session: - * AutoStart, Cookie, CacheExpire, CacheLimiter, SavePath, Storage, GCProbability, CookieUsage, Timeout. + * AutoStart, Cookie, CacheLimiter, SavePath, Storage, GCProbability, CookieUsage, 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 'user' to store session using methods other than files and shared memory. + * and set Storage as 'Custom' to store session using methods other than files and shared memory. + * + * By default, THttpSession is registered with {@link TApplication} as the + * request module. It can be accessed via {@link TApplication::getSession()}. * * @author Qiang Xue * @version $Revision: $ $Date: $ @@ -211,7 +214,7 @@ class THttpSession extends TComponent implements IModule public function setSavePath($value) { if($this->_started) - throw new TInvalidOperationException('httpsession_cachelimiter_unchangeable'); + throw new TInvalidOperationException('httpsession_savepath_unchangeable'); else if(is_dir($value)) session_save_path($value); else @@ -219,19 +222,29 @@ class THttpSession extends TComponent implements IModule } /** - * @return string (files|mm|user) storage mode of session, defaults to 'files'. + * @return string (File|SharedMemory|Custom) storage medium of session, defaults to 'File'. + * @see setStorage */ public function getStorage() { - return session_module_name(); + switch(session_module_name()) + { + case 'files': return 'File'; + case 'mm': return 'SharedMemory'; + case 'user': return 'Custom'; + default: return 'Unknown'; + } } /** - * @param string (files|mm|user) storage mode of session. By default, the session - * data is stored in files. You may change to shared memory (mm) for better performance. - * Or you may choose your own storage (user). If you do so, make sure you - * override {@link _open}, {@link _close}, {@link _read}, {@link _write}, - * {@link _destroy}, and {@link _gc}. + * 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 */ public function setStorage($value) @@ -240,10 +253,21 @@ class THttpSession extends TComponent implements IModule throw new TInvalidOperationException('httpsession_storage_unchangeable'); else { - $value=TPropertyValue::ensureEnum($value,array('files','mm','user')); - if($value==='user') + $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')); - session_module_name($value); + switch($value) + { + case 'Custom': + session_module_name('user'); + break; + case 'SharedMemory': + session_module_name('mm'); + break; + default: + session_module_name('files'); + break; + } } } @@ -258,22 +282,22 @@ class THttpSession extends TComponent implements IModule } /** - * @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 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'. */ public function getCookieMode() { if(ini_get('session.use_cookies')==='0') - return 'none'; + return 'None'; else if(ini_get('session.use_only_cookies')==='0') - return 'allow'; + return 'Allow'; else - return 'only'; + return '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 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. * @throws TInvalidOperationException if session is started already */ public function setCookieMode($value) @@ -282,10 +306,10 @@ class THttpSession extends TComponent implements IModule throw new TInvalidOperationException('httpsession_cookiemode_unchangeable'); else { - $value=TPropertyValue::ensureEnum($value,array('none','allow','only')); - if($value==='none') + $value=TPropertyValue::ensureEnum($value,array('None','Allow','Only')); + if($value==='None') ini_set('session.use_cookies','0'); - else if($value==='allow') + else if($value==='Allow') { ini_set('session.use_cookies','1'); ini_set('session.use_only_cookies','0'); @@ -353,7 +377,7 @@ class THttpSession extends TComponent implements IModule */ public function getUseTransparentSessionID() { - return ini_get('session.use_trans_sid')==='1'?true:false; + return ini_get('session.use_trans_sid')==='1'; } /** diff --git a/framework/Web/UI/TThemeManager.php b/framework/Web/UI/TThemeManager.php index 9b7dc6a6..f98563e0 100644 --- a/framework/Web/UI/TThemeManager.php +++ b/framework/Web/UI/TThemeManager.php @@ -121,9 +121,9 @@ class TTheme extends TTemplate public function __construct($content,$themePath) { - $this->_themePath=strtr($themePath,'\\','/'); + $this->_themePath=realpath($themePath); $basePath=dirname(Prado::getApplication()->getRequest()->getPhysicalApplicationPath()); - if(($pos=strpos($this->_themePath,$basePath))===false) + if($this->_themePath===false || ($pos=strpos($this->_themePath,$basePath))===false) throw new TConfigurationException('theme_themepath_invalid',$themePath); else { -- cgit v1.2.3