| [ Index ] |
|
Code source de PRADO 3.0.6 |
1 <?php 2 /** 3 * TPageStatePersister class file 4 * 5 * @author Qiang Xue <qiang.xue@gmail.com> 6 * @link http://www.pradosoft.com/ 7 * @copyright Copyright © 2005 PradoSoft 8 * @license http://www.pradosoft.com/license/ 9 * @version $Id: TPageStatePersister.php 1397 2006-09-07 07:55:53Z wei $ 10 * @package System.Web.UI 11 */ 12 13 /** 14 * TPageStatePersister class 15 * 16 * TPageStatePersister implements a page state persistent method based on 17 * form hidden fields. 18 * 19 * Depending on the {@link TPage::getEnableStateValidation() EnableStateValidation} 20 * and {@link TPage::getEnableStateEncryption() EnableStateEncryption}, 21 * TPageStatePersister may do HMAC validation and encryption to prevent 22 * the state data from being tampered or viewed. 23 * The private keys and hashing/encryption methods are determined by 24 * {@link TApplication::getSecurityManager() SecurityManager}. 25 * 26 * @author Qiang Xue <qiang.xue@gmail.com> 27 * @version $Id: TPageStatePersister.php 1397 2006-09-07 07:55:53Z wei $ 28 * @package System.Web.UI 29 * @since 3.0 30 */ 31 class TPageStatePersister extends TApplicationComponent implements IPageStatePersister 32 { 33 private $_page; 34 35 /** 36 * @return TPage the page that this persister works for 37 */ 38 public function getPage() 39 { 40 return $this->_page; 41 } 42 43 /** 44 * @param TPage the page that this persister works for 45 */ 46 public function setPage(TPage $page) 47 { 48 $this->_page=$page; 49 } 50 51 /** 52 * Saves state in hidden fields. 53 * @param mixed state to be stored 54 */ 55 public function save($state) 56 { 57 if($this->_page->getEnableStateValidation()) 58 $data=$this->getApplication()->getSecurityManager()->hashData(Prado::serialize($state)); 59 else 60 $data=Prado::serialize($state); 61 if($this->_page->getEnableStateEncryption()) 62 $data=$this->getApplication()->getSecurityManager()->encrypt($data); 63 if(extension_loaded('zlib')) 64 $data=gzcompress($data); 65 $this->_page->getClientScript()->registerHiddenField(TPage::FIELD_PAGESTATE,base64_encode($data)); 66 } 67 68 /** 69 * Loads page state from hidden fields. 70 * @return mixed the restored state 71 * @throws THttpException if page state is corrupted 72 */ 73 public function load() 74 { 75 $str=base64_decode($this->getRequest()->itemAt(TPage::FIELD_PAGESTATE)); 76 if($str==='') 77 return null; 78 if(extension_loaded('zlib')) 79 $data=gzuncompress($str); 80 else 81 $data=$str; 82 if($data!==false) 83 { 84 if($this->_page->getEnableStateEncryption()) 85 $data=$this->getApplication()->getSecurityManager()->decrypt($data); 86 if($this->_page->getEnableStateValidation()) 87 { 88 if(($data=$this->getApplication()->getSecurityManager()->validateData($data))!==false) 89 return Prado::unserialize($data); 90 } 91 else 92 return $data; 93 } 94 throw new THttpException(400,'pagestatepersister_pagestate_corrupted'); 95 } 96 } 97 98 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Sun Feb 25 21:07:04 2007 | par Balluche grâce à PHPXref 0.7 |