summaryrefslogtreecommitdiff
path: root/framework/Web/UI/WebControls
diff options
context:
space:
mode:
authorxue <>2006-04-08 17:00:05 +0000
committerxue <>2006-04-08 17:00:05 +0000
commitccf0cd0f8d6480238db531f46ae1c70554d0e90d (patch)
tree42dad36e6d3c3ee2e9affa71615257f848cff552 /framework/Web/UI/WebControls
parent325b2ab61e3cf03e9ae7fb03ee1030cae6b08b3e (diff)
Added TOutputCache.
Diffstat (limited to 'framework/Web/UI/WebControls')
-rw-r--r--framework/Web/UI/WebControls/TOutputCache.php160
-rw-r--r--framework/Web/UI/WebControls/TPanel.php2
-rw-r--r--framework/Web/UI/WebControls/TWizard.php1
3 files changed, 161 insertions, 2 deletions
diff --git a/framework/Web/UI/WebControls/TOutputCache.php b/framework/Web/UI/WebControls/TOutputCache.php
new file mode 100644
index 00000000..9708c033
--- /dev/null
+++ b/framework/Web/UI/WebControls/TOutputCache.php
@@ -0,0 +1,160 @@
+<?php
+
+class TOutputCache extends TControl implements INamingContainer
+{
+ const CACHE_ID_PREFIX='prado:outputcache';
+ private $_useCache=false;
+ private $_cacheReady=false;
+ private $_cacheChecked=false;
+ private $_expiry=60;
+ private $_cache=null;
+ private $_contents;
+ private $_state;
+ private $_enableCaching=true;
+ private $_actions=array();
+
+ protected function initRecursive($namingContainer=null)
+ {
+ if($this->_cacheReady && !$this->_useCache)
+ {
+ $stack=$this->getPage()->getCachingStack();
+ $stack->push($this);
+ parent::initRecursive($namingContainer);
+ $stack->pop();
+ }
+ else
+ parent::initRecursive($namingContainer);
+ }
+
+ protected function loadRecursive()
+ {
+ if($this->_cacheReady && !$this->_useCache)
+ {
+ $stack=$this->getPage()->getCachingStack();
+ $stack->push($this);
+ parent::loadRecursive();
+ $stack->pop();
+ }
+ else
+ {
+ if($this->_useCache)
+ {
+ $cs=$this->getPage()->getClientScript();
+ foreach($this->_actions as $action)
+ {
+ if($action[0]==='registerRequiresPostData')
+ $this->getPage()->registerRequiresPostData($action[1]);
+ else
+ call_user_func_array(array($cs,$action[0]),$action[1]);
+ }
+ }
+ parent::loadRecursive();
+ }
+ }
+
+ protected function preRenderRecursive()
+ {
+ if($this->_cacheReady && !$this->_useCache)
+ {
+ $stack=$this->getPage()->getCachingStack();
+ $stack->push($this);
+ parent::preRenderRecursive();
+ $stack->pop();
+ }
+ else
+ parent::preRenderRecursive();
+ }
+
+ public function registerAction($funcName,$funcParams)
+ {
+ $this->_actions[]=array($funcName,$funcParams);
+ }
+
+ public function getAllowChildControls()
+ {
+ if(!$this->_cacheChecked)
+ {
+ $this->_cacheChecked=true;
+ if(!$this->getPage()->getIsPostBack() && ($this->_cache=$this->getApplication()->getCache())!==null && $this->getEnableCaching())
+ {
+ $this->_cacheReady=true;
+ $data=$this->_cache->get($this->getCacheKey());
+ if(($this->_useCache=($data!==false)))
+ list($this->_contents,$this->_state,$this->_actions)=$data;
+ }
+ }
+ return !$this->_useCache;
+ }
+
+ public function getEnableCaching()
+ {
+ return $this->_enableCaching;
+ }
+
+ public function setEnableCaching($value)
+ {
+ $this->_enableCaching=TPropertyValue::ensureBoolean($value);
+ }
+
+ protected function loadStateRecursive(&$state,$needViewState=true)
+ {
+ if($this->_useCache)
+ parent::loadStateRecursive($this->_state,$needViewState);
+ else
+ parent::loadStateRecursive($state,$needViewState);
+ }
+
+ protected function &saveStateRecursive($needViewState=true)
+ {
+ if($this->_useCache)
+ return $this->_state;
+ else if($this->_cacheReady)
+ {
+ $this->_state=parent::saveStateRecursive($needViewState);
+ return $this->_state;
+ }
+ else
+ return parent::saveStateRecursive($needViewState);
+ }
+
+ protected function getCacheKey()
+ {
+ return self::CACHE_ID_PREFIX.$this->getUniqueID();
+ }
+
+ public function getExpiry()
+ {
+ return $this->_expiry;
+ }
+
+ public function setExpiry($value)
+ {
+ if(($value=TPropertyValue::ensureInteger($value))<0)
+ throw new TInvalidDataValueException('outputcache_expiry_invalid');
+ $this->_expiry=$value;
+ }
+
+ public function render($writer)
+ {
+ if($this->_useCache)
+ $writer->write($this->_contents);
+ else if($this->_cacheReady)
+ {
+ $textWriter=new TTextWriter;
+
+ $stack=$this->getPage()->getCachingStack();
+ $stack->push($this);
+ parent::render(new THtmlWriter($textWriter));
+ $stack->pop();
+
+ $content=$textWriter->flush();
+ $data=array($content,$this->_state,$this->_actions);
+ $this->_cache->set($this->getCacheKey(),$data,$this->getExpiry());
+ $writer->write($content);
+ }
+ else
+ parent::render($writer);
+ }
+}
+
+?> \ No newline at end of file
diff --git a/framework/Web/UI/WebControls/TPanel.php b/framework/Web/UI/WebControls/TPanel.php
index 5f99edf5..03f0a3a3 100644
--- a/framework/Web/UI/WebControls/TPanel.php
+++ b/framework/Web/UI/WebControls/TPanel.php
@@ -73,7 +73,7 @@ class TPanel extends TWebControl
else
{
$writer->addAttribute('id',$this->getClientID());
- $this->getPage()->getClientScript()->registerDefaultButton($this, $button);
+ $this->getPage()->getClientScript()->registerDefaultButton($this->getClientID(), $button->getClientID());
}
}
}
diff --git a/framework/Web/UI/WebControls/TWizard.php b/framework/Web/UI/WebControls/TWizard.php
index ef4691bd..0b44872b 100644
--- a/framework/Web/UI/WebControls/TWizard.php
+++ b/framework/Web/UI/WebControls/TWizard.php
@@ -16,7 +16,6 @@ Prado::using('System.Web.UI.WebControls.TButton');
Prado::using('System.Web.UI.WebControls.TLinkButton');
Prado::using('System.Web.UI.WebControls.TImageButton');
Prado::using('System.Web.UI.WebControls.TDataList');
-Prado::using('System.Collections.TStack');
/**
* Class TWizard.