diff options
author | xue <> | 2006-06-15 18:18:47 +0000 |
---|---|---|
committer | xue <> | 2006-06-15 18:18:47 +0000 |
commit | 6c0154fb4e292ad22667e618f598a37cc5f9d524 (patch) | |
tree | 925b51622b8f054d203050cd673eb48a24035c3c /framework | |
parent | c8919fa9fc845ab7f3c6701b6de08c8cd042ec30 (diff) |
Merge from 3.0 branch till 1166.
Diffstat (limited to 'framework')
-rw-r--r-- | framework/Web/Services/TPageService.php | 27 | ||||
-rw-r--r-- | framework/Web/UI/TTemplateManager.php | 78 | ||||
-rw-r--r-- | framework/Web/UI/TThemeManager.php | 2 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TBaseValidator.php | 38 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TDataGrid.php | 4 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TDataList.php | 4 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TRepeater.php | 4 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TTable.php | 5 | ||||
-rw-r--r-- | framework/Xml/TXmlDocument.php | 36 |
9 files changed, 149 insertions, 49 deletions
diff --git a/framework/Web/Services/TPageService.php b/framework/Web/Services/TPageService.php index 1df4ffde..5172f59c 100644 --- a/framework/Web/Services/TPageService.php +++ b/framework/Web/Services/TPageService.php @@ -96,6 +96,10 @@ class TPageService extends TService */
private $_basePath=null;
/**
+ * @var string base path class in namespace format
+ */
+ private $_basePageClass='TPage';
+ /**
* @var string default page
*/
private $_defaultPage='Home';
@@ -398,6 +402,25 @@ class TPageService extends TService }
/**
+ * Sets the base page class name (in namespace format).
+ * If a page only has a template file without page class file,
+ * this base page class will be instantiated.
+ * @param string class name
+ */
+ public function setBasePageClass($value)
+ {
+ $this->_basePageClass=$value;
+ }
+
+ /**
+ * @return string base page class name in namespace format. Defaults to 'TPage'.
+ */
+ public function getBasePageClass()
+ {
+ return $this->_basePageClass;
+ }
+
+ /**
* Runs the service.
* This will create the requested page, initializes it with the property values
* specified in the configuration, and executes the page.
@@ -417,9 +440,9 @@ class TPageService extends TService throw new TConfigurationException('pageservice_pageclass_unknown',$className);
}
else
- $className='TPage';
+ $className=$this->getBasePageClass();
- $this->_page=new $className();
+ $this->_page=Prado::createComponent($className);
$this->_page->setPagePath($this->getRequestedPagePath());
// initialize page properties with those set in configurations
diff --git a/framework/Web/UI/TTemplateManager.php b/framework/Web/UI/TTemplateManager.php index cb05fa35..53239bd9 100644 --- a/framework/Web/UI/TTemplateManager.php +++ b/framework/Web/UI/TTemplateManager.php @@ -383,28 +383,6 @@ class TTemplate extends TApplicationComponent implements ITemplate * @param string property name
* @param mixed property initial value
*/
- protected function configureControl2($control,$name,$value)
- {
- if(strncasecmp($name,'on',2)===0) // is an event
- $this->configureEvent($control,$name,$value,$control);
- else if(($pos=strrpos($name,'.'))===false) // is a simple property or custom attribute
- $this->configureProperty($control,$name,$value);
- else // is a subproperty
- {
- $subName=substr($name,$pos+1);
- if(strncasecmp($subName,'on',2)===0) // is an event: XXX.YYY.OnZZZ
- {
- $object=$control->getSubProperty(substr($name,0,$pos));
- if(($object instanceof TControl))
- $this->configureEvent($object,$subName,$value,$control);
- else
- $this->configureSubProperty($control,$name,$value);
- }
- else
- $this->configureSubProperty($control,$name,$value);
- }
- }
-
protected function configureControl($control,$name,$value)
{
if(strncasecmp($name,'on',2)===0) // is an event
@@ -414,6 +392,7 @@ class TTemplate extends TApplicationComponent implements ITemplate else // is a subproperty
$this->configureSubProperty($control,$name,$value);
}
+
/**
* Configures a property of a non-control component.
* @param TComponent component to be configured
@@ -632,7 +611,7 @@ class TTemplate extends TApplicationComponent implements ITemplate if($matchStart>$textStart)
$tpl[$c++]=array($container,substr($input,$textStart,$matchStart-$textStart));
$textStart=$matchEnd+1;
- $literal=trim(THttpUtility::htmlDecode($match[5][0]));
+ $literal=trim($match[5][0]);
if($str[2]==='=') // expression
$tpl[$c++]=array($container,array(TCompositeLiteral::TYPE_EXPRESSION,$literal));
else if($str[2]==='%') // statements
@@ -851,21 +830,44 @@ class TTemplate extends TApplicationComponent implements ITemplate */
protected function parseAttribute($value)
{
- $matches=array();
- if(!preg_match('/\\s*(<%#.*?%>|<%=.*?%>|<%~.*?%>|<%\\$.*?%>|<%\\[.*?\\]%>)\\s*/msS',$value,$matches) || $matches[0]!==$value)
- return THttpUtility::htmlDecode($value);
- $value=THttpUtility::htmlDecode($matches[1]);
- if($value[2]==='#') // databind
- return array(self::CONFIG_DATABIND,substr($value,3,strlen($value)-5));
- else if($value[2]==='=') // a dynamic initialization
- return array(self::CONFIG_EXPRESSION,substr($value,3,strlen($value)-5));
- else if($value[2]==='~') // a URL
- return array(self::CONFIG_ASSET,trim(substr($value,3,strlen($value)-5)));
- else if($value[2]==='[')
- return array(self::CONFIG_LOCALIZATION,trim(substr($value,3,strlen($value)-6)));
- else if($value[2]==='$')
- return array(self::CONFIG_PARAMETER,trim(substr($value,3,strlen($value)-5)));
- return '';
+ if(($n=preg_match_all('/<%[#=].*?%>/msS',$value,$matches,PREG_OFFSET_CAPTURE))>0)
+ {
+ $isDataBind=false;
+ $textStart=0;
+ $expr='';
+ for($i=0;$i<$n;++$i)
+ {
+ $match=$matches[0][$i];
+ $token=$match[0];
+ $offset=$match[1];
+ $length=strlen($token);
+ if($token[2]==='#')
+ $isDataBind=true;
+ if($offset>$textStart)
+ $expr.=".'".strtr(substr($value,$textStart,$offset-$textStart),array("'"=>"\\'","\\"=>"\\\\"))."'";
+ $expr.='.('.substr($token,3,$length-5).')';
+ $textStart=$offset+$length;
+ }
+ $length=strlen($value);
+ if($length>$textStart)
+ $expr.=".'".substr($value,$textStart,$length-$textStart)."'";
+ if($isDataBind)
+ return array(self::CONFIG_DATABIND,ltrim($expr,'.'));
+ else
+ return array(self::CONFIG_EXPRESSION,ltrim($expr,'.'));
+ }
+ else if(preg_match('/\\s*(<%~.*?%>|<%\\$.*?%>|<%\\[.*?\\]%>)\\s*/msS',$value,$matches) && $matches[0]===$value)
+ {
+ $value=$matches[1];
+ if($value[2]==='~') // a URL
+ return array(self::CONFIG_ASSET,trim(substr($value,3,strlen($value)-5)));
+ else if($value[2]==='[')
+ return array(self::CONFIG_LOCALIZATION,trim(substr($value,3,strlen($value)-6)));
+ else if($value[2]==='$')
+ return array(self::CONFIG_PARAMETER,trim(substr($value,3,strlen($value)-5)));
+ }
+ else
+ return $value;
}
protected function validateAttributes($type,$attributes)
diff --git a/framework/Web/UI/TThemeManager.php b/framework/Web/UI/TThemeManager.php index fcb20a81..66bfa8be 100644 --- a/framework/Web/UI/TThemeManager.php +++ b/framework/Web/UI/TThemeManager.php @@ -305,6 +305,8 @@ class TTheme extends TApplicationComponent implements ITheme }
}
closedir($dir);
+ sort($this->_cssFiles);
+ sort($this->_jsFiles);
if($cache!==null)
$cache->set(self::THEME_CACHE_PREFIX.$themePath,array($this->_skins,$this->_cssFiles,$this->_jsFiles,time()));
}
diff --git a/framework/Web/UI/WebControls/TBaseValidator.php b/framework/Web/UI/WebControls/TBaseValidator.php index 3fe9ee03..1194089e 100644 --- a/framework/Web/UI/WebControls/TBaseValidator.php +++ b/framework/Web/UI/WebControls/TBaseValidator.php @@ -473,10 +473,22 @@ abstract class TBaseValidator extends TLabel implements IValidator */ public function validate() { + $this->onValidate(); $this->setIsValid(true); $control=$this->getValidationTarget(); if($control && $this->getVisible(true) && $this->getEnabled()) - $this->setIsValid($this->evaluateIsValid()); + { + if($this->evaluateIsValid()) + { + $this->setIsValid(true); + $this->onSuccess(); + } + else + { + $this->setIsValid(false); + $this->onError(); + } + } return $this->getIsValid(); } @@ -504,6 +516,30 @@ abstract class TBaseValidator extends TLabel implements IValidator abstract protected function evaluateIsValid(); /** + * This event is raised when the validator succeeds in validation. + */ + public function onSuccess() + { + $this->raiseEvent('OnSuccess',$this,null); + } + + /** + * This event is raised when the validator fails in validation. + */ + public function onError() + { + $this->raiseEvent('OnError',$this,null); + } + + /** + * This event is raised right before the validator starts to perform validation. + */ + public function onValidate() + { + $this->raiseEvent('OnValidate',$this,null); + } + + /** * Renders the validator control. * @param THtmlWriter writer for the rendering purpose */ diff --git a/framework/Web/UI/WebControls/TDataGrid.php b/framework/Web/UI/WebControls/TDataGrid.php index d2625c0d..69798c1a 100644 --- a/framework/Web/UI/WebControls/TDataGrid.php +++ b/framework/Web/UI/WebControls/TDataGrid.php @@ -1047,10 +1047,12 @@ class TDataGrid extends TBaseDataList implements INamingContainer $editIndex=$this->getEditItemIndex();
$index=0;
$dsIndex=$ds->getAllowPaging()?$ds->getFirstIndexInPage():0;
- foreach($ds as $data)
+ foreach($ds as $key=>$data)
{
if($keyField!=='')
$keys->add($this->getDataFieldValue($data,$keyField));
+ else
+ $keys->add($key);
if($index===$editIndex)
$itemType=self::IT_EDITITEM;
else if($index===$selectedIndex)
diff --git a/framework/Web/UI/WebControls/TDataList.php b/framework/Web/UI/WebControls/TDataList.php index 0bec8921..b2bd9229 100644 --- a/framework/Web/UI/WebControls/TDataList.php +++ b/framework/Web/UI/WebControls/TDataList.php @@ -1129,10 +1129,12 @@ class TDataList extends TBaseDataList implements INamingContainer, IRepeatInfoUs $hasSeparator=$this->_separatorTemplate!==null;
$selectedIndex=$this->getSelectedItemIndex();
$editIndex=$this->getEditItemIndex();
- foreach($data as $dataItem)
+ foreach($data as $key=>$dataItem)
{
if($keyField!=='')
$keys->add($this->getDataFieldValue($dataItem,$keyField));
+ else
+ $keys->add($key);
if($itemIndex===0 && $this->_headerTemplate!==null)
$this->_header=$this->createItemInternal(-1,'Header',true,null);
if($hasSeparator && $itemIndex>0)
diff --git a/framework/Web/UI/WebControls/TRepeater.php b/framework/Web/UI/WebControls/TRepeater.php index 2070cb1a..9c1cc4ac 100644 --- a/framework/Web/UI/WebControls/TRepeater.php +++ b/framework/Web/UI/WebControls/TRepeater.php @@ -443,10 +443,12 @@ class TRepeater extends TDataBoundControl implements INamingContainer $items=$this->getItems();
$itemIndex=0;
$hasSeparator=$this->_separatorTemplate!==null;
- foreach($data as $dataItem)
+ foreach($data as $key=>$dataItem)
{
if($keyField!=='')
$keys->add($this->getDataFieldValue($dataItem,$keyField));
+ else
+ $keys->add($key);
if($itemIndex===0 && $this->_headerTemplate!==null)
$this->_header=$this->createItemInternal(-1,self::IT_HEADER,true,null);
if($hasSeparator && $itemIndex>0)
diff --git a/framework/Web/UI/WebControls/TTable.php b/framework/Web/UI/WebControls/TTable.php index aaed37df..1c58c62e 100644 --- a/framework/Web/UI/WebControls/TTable.php +++ b/framework/Web/UI/WebControls/TTable.php @@ -68,11 +68,6 @@ Prado::using('System.Web.UI.WebControls.TTableRow'); class TTable extends TWebControl
{
/**
- * @var TTableRowCollection row collection
- */
- private $_rows=null;
-
- /**
* @return string tag name for the table
*/
protected function getTagName()
diff --git a/framework/Xml/TXmlDocument.php b/framework/Xml/TXmlDocument.php index ab4b0b7a..0d766c68 100644 --- a/framework/Xml/TXmlDocument.php +++ b/framework/Xml/TXmlDocument.php @@ -229,6 +229,42 @@ class TXmlElement extends TComponent * You can also get the version and encoding of the XML document by * the Version and Encoding properties. * + * To construct an XML string, you may do the following: + * <code> + * $doc=new TXmlDocument('1.0','utf-8'); + * $doc->TagName='Root'; + * + * $proc=new TXmlElement('Proc'); + * $proc->setAttribute('Name','xxxx'); + * $doc->Elements[]=$proc; + * + * $query=new TXmlElement('Query'); + * $query->setAttribute('ID','xxxx'); + * $proc->Elements[]=$query; + * + * $attr=new TXmlElement('Attr'); + * $attr->setAttribute('Name','aaa'); + * $attr->Value='1'; + * $query->Elements[]=$attr; + * + * $attr=new TXmlElement('Attr'); + * $attr->setAttribute('Name','bbb'); + * $attr->Value='1'; + * $query->Elements[]=$attr; + * </code> + * The above code represents the following XML string: + * <code> + * <?xml version="1.0" encoding="utf-8"?> + * <Root> + * <Proc Name="xxxx"> + * <Query ID="xxxx"> + * <Attr Name="aaa">1</Attr> + * <Attr Name="bbb">1</Attr> + * </Query> + * </Proc> + * </Root> + * </code> + * * @author Qiang Xue <qiang.xue@gmail.com> * @version $Revision: $ $Date: $ * @package System.Xml |