summaryrefslogtreecommitdiff
path: root/framework/Web
diff options
context:
space:
mode:
Diffstat (limited to 'framework/Web')
-rw-r--r--framework/Web/TAssetManager.php2
-rw-r--r--framework/Web/THttpRequest.php52
-rw-r--r--framework/Web/THttpResponse.php16
-rw-r--r--framework/Web/THttpSession.php72
-rw-r--r--framework/Web/UI/TThemeManager.php4
5 files changed, 88 insertions, 58 deletions
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 @@
<?php
/**
- * THttpRequest class
+ * THttpRequest, THttpCookie, THttpCookieCollection, TUri class file
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @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 <qiang.xue@gmail.com>
* @version $Revision: $ $Date: $
@@ -63,26 +69,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.
* @param TApplication 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));
@@ -128,6 +113,17 @@ class THttpRequest extends TComponent implements IModule
}
/**
+ * 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
*/
public function getID()
@@ -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 <qiang.xue@gmail.com>
* @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 @@
* </code>
*
* 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 <qiang.xue@gmail.com>
* @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
{