diff options
author | xue <> | 2006-04-11 00:58:46 +0000 |
---|---|---|
committer | xue <> | 2006-04-11 00:58:46 +0000 |
commit | 37f4d81a1ce6bdea84b00a38b0c8fc32f82f9e5d (patch) | |
tree | 21fefb880ab617aa2f5440494143d23f9fb68520 /framework/Web/UI/TPage.php | |
parent | 00d32ec019a329a84190b7938cbf48f9e9494874 (diff) |
Refactored page state persister.
Diffstat (limited to 'framework/Web/UI/TPage.php')
-rw-r--r-- | framework/Web/UI/TPage.php | 104 |
1 files changed, 103 insertions, 1 deletions
diff --git a/framework/Web/UI/TPage.php b/framework/Web/UI/TPage.php index 6a4083b0..e34101d9 100644 --- a/framework/Web/UI/TPage.php +++ b/framework/Web/UI/TPage.php @@ -145,6 +145,10 @@ class TPage extends TTemplateControl * @var TStack stack used to store currently active caching controls
*/
private $_cachingStack=null;
+ /**
+ * @var string state string to be stored on the client side
+ */
+ private $_clientState='';
/**
* Constructor.
@@ -740,6 +744,7 @@ class TPage extends TTemplateControl $this->_formRendered=true;
$this->_inFormRender=true;
$cs=$this->getClientScript();
+ $cs->registerHiddenField(self::FIELD_PAGESTATE,$this->getClientState());
$cs->renderHiddenFields($writer);
$cs->renderScriptFiles($writer);
$cs->renderBeginScripts($writer);
@@ -842,6 +847,34 @@ class TPage extends TTemplateControl }
/**
+ * Returns the state to be stored on the client side.
+ * This method should only be used by framework and control developers.
+ * @return string the state to be stored on the client side
+ */
+ public function getClientState()
+ {
+ return $this->_clientState;
+ }
+
+ /**
+ * Sets the state to be stored on the client side.
+ * This method should only be used by framework and control developers.
+ * @param string the state to be stored on the client side
+ */
+ public function setClientState($state)
+ {
+ $this->_clientState=$state;
+ }
+
+ /**
+ * @return string the state postback from client side
+ */
+ public function getRequestClientState()
+ {
+ return $this->getRequest()->itemAt(self::FIELD_PAGESTATE);
+ }
+
+ /**
* @return string class name of the page state persister. Defaults to TPageStatePersister.
*/
public function getStatePersisterClass()
@@ -937,7 +970,7 @@ class TPage extends TTemplateControl * @author Qiang Xue <qiang.xue@gmail.com>
* @version $Revision: $ $Date: $
* @package System.Web.UI
- * @since 3.0
+ * @since 3.1
*/
interface IPageStatePersister
{
@@ -961,4 +994,73 @@ interface IPageStatePersister public function load();
}
+
+/**
+ * TPageStateFormatter class.
+ *
+ * TPageStateFormatter is a utility class to transform the page state
+ * into and from a string that can be properly saved in persistent storage.
+ *
+ * Depending on the {@link TPage::getEnableStateValidation() EnableStateValidation}
+ * and {@link TPage::getEnableStateEncryption() EnableStateEncryption},
+ * TPageStateFormatter may do HMAC validation and encryption to prevent
+ * the state data from being tampered or viewed.
+ * The private keys and hashing/encryption methods are determined by
+ * {@link TApplication::getSecurityManager() SecurityManager}.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI
+ * @since 3.1
+ */
+class TPageStateFormatter
+{
+ /**
+ * @param TPage
+ * @param mixed state data
+ * @return string serialized data
+ */
+ public static function serialize($page,$data)
+ {
+ $sm=$page->getApplication()->getSecurityManager();
+ if($page->getEnableStateValidation())
+ $str=$sm->hashData(Prado::serialize($data));
+ else
+ $str=Prado::serialize($data);
+ if($page->getEnableStateEncryption())
+ $str=$sm->encrypt($str);
+ if(extension_loaded('zlib'))
+ $str=gzcompress($str);
+ return base64_encode($str);
+ }
+
+ /**
+ * @param TPage
+ * @param string serialized data
+ * @return mixed unserialized state data, null if data is corrupted
+ */
+ public static function unserialize($page,$data)
+ {
+ $str=base64_decode($data);
+ if($str==='')
+ return null;
+ if(extension_loaded('zlib'))
+ $str=gzuncompress($str);
+ if($str!==false)
+ {
+ $sm=$page->getApplication()->getSecurityManager();
+ if($page->getEnableStateEncryption())
+ $str=$sm->decrypt($str);
+ if($page->getEnableStateValidation())
+ {
+ if(($str=$sm->validateData($str))!==false)
+ return Prado::unserialize($str);
+ }
+ else
+ return $str;
+ }
+ return null;
+ }
+}
+
?>
\ No newline at end of file |