From 1c32172efb18e8d08ea483e2460813670ebfe1a5 Mon Sep 17 00:00:00 2001 From: xue <> Date: Sat, 30 Sep 2006 18:40:40 +0000 Subject: merge from 3.0 branch till 1451. --- framework/Web/THttpRequest.php | 9 ++- framework/Web/TUrlMapping.php | 81 ++++++++++++++++++---- .../Web/UI/WebControls/TDropDownListColumn.php | 72 ++++++++++++++----- 3 files changed, 128 insertions(+), 34 deletions(-) (limited to 'framework') diff --git a/framework/Web/THttpRequest.php b/framework/Web/THttpRequest.php index aa690540..90007fa2 100644 --- a/framework/Web/THttpRequest.php +++ b/framework/Web/THttpRequest.php @@ -596,7 +596,10 @@ class THttpRequest extends TApplicationComponent implements IteratorAggregate,Ar } } - protected function getRequestResolved() + /** + * @return boolean true if request is already resolved, false otherwise. + */ + public function getRequestResolved() { return $this->_requestResolved; } @@ -631,7 +634,7 @@ class THttpRequest extends TApplicationComponent implements IteratorAggregate,Ar * Sets the requested service ID. * @param string requested service ID */ - protected function setServiceID($value) + public function setServiceID($value) { $this->_serviceID=$value; } @@ -650,7 +653,7 @@ class THttpRequest extends TApplicationComponent implements IteratorAggregate,Ar * Sets the requested service parameter. * @param string requested service parameter */ - protected function setServiceParameter($value) + public function setServiceParameter($value) { $this->_serviceParam=$value; } diff --git a/framework/Web/TUrlMapping.php b/framework/Web/TUrlMapping.php index a5d6abf8..a4c662a9 100644 --- a/framework/Web/TUrlMapping.php +++ b/framework/Web/TUrlMapping.php @@ -43,7 +43,7 @@ * @package System.Web * @since 3.0.5 */ -class TUrlMapping extends THttpRequest +class TUrlMapping extends TModule { /** * @var string default pattern class. @@ -201,9 +201,9 @@ class TUrlMapping extends THttpRequest * * Describes an URL mapping pattern, if a given URL matches the pattern, the * TUrlMapping class will alter the THttpRequest parameters. The - * url matching is done using regular expressions. + * url matching is done using patterns and regular expressions. * - * The {@link setPattern Pattern} property takes a regular expression with + * The {@link setPattern Pattern} property takes an string expression with * parameter names enclosed between a left brace '{' and a right brace '}'. * The pattens for each parameter can be set using {@link getParameters Parameters} * attribute collection. For example @@ -215,6 +215,17 @@ class TUrlMapping extends THttpRequest * In the above example, the pattern contains 3 parameters named "year", * "month" and "day". The pattern for these parameters are, respectively, * "\d{4}" (4 digits), "\d{2}" (2 digits) and "\d+" (1 or more digits). + * Essentially, the Parameters attribute name and values are used + * as substrings in replacing the placeholders in the Pattern string + * to form a complete regular expression string. A full regular expression + * may be expressed using the RegularExpression attribute or + * as the body content of the <module> tag. The above pattern is equivalent + * to the following regular expression pattern. + * + * /articles\/(?P\d{4})\/(?P\d{2})\/(?P\d+)/u + * + * The above regular expression used the "named group" feature available in PHP. + * Notice that you need to escape the slash in regular expressions. * * In the TUrlMappingPattern class, the pattern is matched against the * path property of the url only. @@ -262,6 +273,10 @@ class TUrlMappingPattern extends TComponent * @var string regular expression pattern. */ private $_regexp; + /** + * @var boolean case sensitive matching, default is true + */ + private $_caseSensitive=true; public function __construct() { @@ -277,20 +292,20 @@ class TUrlMappingPattern extends TComponent { $body = trim($config->getValue()); if(strlen($body)>0) - $this->setPattern($body); + $this->setRegularExpression($body); if(is_null($this->_serviceParameter)) { throw new TConfigurationException( 'dispatcher_url_service_parameter_missing', $this->getPattern()); } - $this->initializePattern(); } /** * Subsitutue the parameter key value pairs as named groupings * in the regular expression matching pattern. + * @return string regular expression pattern with parameter subsitution */ - protected function initializePattern() + protected function getParameterizedPattern() { $params= array(); $values = array(); @@ -299,17 +314,29 @@ class TUrlMappingPattern extends TComponent $params[] = '{'.$key.'}'; $values[] = '(?P<'.$key.'>'.$value.')'; } - $this->_regexp = str_replace($params,$values,$this->getPattern()); + $params[] = '/'; + $values[] = '\\/'; + $regexp = str_replace($params,$values,$this->getPattern()); + $modifiers = $this->getModifiers(); + return '/'.$regexp.'/'.$modifiers; } /** - * @return string mapping pattern + * @return string full regular expression mapping pattern */ - protected function getRegExpPattern() + public function getRegularExpression() { return $this->_regexp; } + /** + * @param string full regular expression mapping patern. + */ + public function setRegularExpression($value) + { + $this->_regexp; + } + /** * @param string service parameter, such as page class name. */ @@ -358,6 +385,22 @@ class TUrlMappingPattern extends TComponent $this->_pattern = $value; } + /** + * @param boolean case sensitive pattern matching, default is true. + */ + public function setCaseSensitive($value) + { + $this->_caseSensitive=TPropertyValue::ensureBoolean($value); + } + + /** + * @return boolean case sensitive pattern matching, default is true. + */ + public function getCaseSensitive() + { + return $this->_caseSensitive; + } + /** * @return TAttributeCollection parameter key value pairs. */ @@ -375,7 +418,8 @@ class TUrlMappingPattern extends TComponent } /** - * Use regular expression to match the given url path. + * Uses URL pattern (or full regular expression if available) to + * match the given url path. * @param TUri url to match against * @return array matched parameters, empty if no matches. */ @@ -383,10 +427,23 @@ class TUrlMappingPattern extends TComponent { $path = $url->getPath(); $matches=array(); - $pattern = str_replace('/', '\\/', $this->getRegExpPattern()); - preg_match('/'.$pattern.'/', $path, $matches); + $pattern = $this->getRegularExpression(); + if($pattern === null) + $pattern = $this->getParameterizedPattern(); + preg_match($pattern, $path, $matches); return $matches; } + + /** + * @return string regular expression matching modifiers. + */ + protected function getModifiers() + { + $modifiers = 'u'; + if(!$this->getCaseSensitive()) + $modifiers .= 'i'; + return $modifiers; + } } ?> \ No newline at end of file diff --git a/framework/Web/UI/WebControls/TDropDownListColumn.php b/framework/Web/UI/WebControls/TDropDownListColumn.php index dbc20f7a..384a3701 100644 --- a/framework/Web/UI/WebControls/TDropDownListColumn.php +++ b/framework/Web/UI/WebControls/TDropDownListColumn.php @@ -18,11 +18,13 @@ Prado::using('System.Web.UI.WebControls.TDropDownList'); * * TDropDownListColumn represents a column that is bound to a field in a data source. * The cells in the column will be displayed using the data indexed by - * {@link setDataField DataField}. You can customize the display by - * setting {@link setDataFormatString DataFormatString}. + * {@link setDataTextField DataTextField}. You can customize the display by + * setting {@link setDataTextFormatString DataTextFormatString}. * * If {@link setReadOnly ReadOnly} is false, TDropDownListColumn will display cells in edit mode * with dropdown lists. Otherwise, a static text is displayed. + * The currently selected dropndown list item is specified by the data indexed with + * {@link setDataValueField DataValueField}. * * There are two approaches to specify the list items available for selection. * The first approach uses template syntax as follows, @@ -107,35 +109,57 @@ class TDropDownListColumn extends TDataGridColumn } /** - * @return string the field name from the data source to bind to the column + * @return string the field of the data source that provides the text content of the column. */ - public function getDataField() + public function getDataTextField() { - return $this->getViewState('DataField',''); + return $this->getViewState('DataTextField',''); } /** - * @param string the field name from the data source to bind to the column + * Sets the field of the data source that provides the text content of the column. + * If this is not set, the data specified via {@link getDataValueField DataValueField} + * will be displayed in the column. + * @param string the field of the data source that provides the text content of the column. */ - public function setDataField($value) + public function setDataTextField($value) { - $this->setViewState('DataField',$value,''); + $this->setViewState('DataTextField',$value,''); } /** * @return string the formatting string used to control how the bound data will be displayed. */ - public function getDataFormatString() + public function getDataTextFormatString() { - return $this->getViewState('DataFormatString',''); + return $this->getViewState('DataTextFormatString',''); } /** * @param string the formatting string used to control how the bound data will be displayed. */ - public function setDataFormatString($value) + public function setDataTextFormatString($value) { - $this->setViewState('DataFormatString',$value,''); + $this->setViewState('DataTextFormatString',$value,''); + } + + /** + * @return string the field of the data source that provides the key selecting an item in dropdown list. + */ + public function getDataValueField() + { + return $this->getViewState('DataValueField',''); + } + + /** + * Sets the field of the data source that provides the key selecting an item in dropdown list. + * If this is not present, the data specified via {@link getDataTextField DataTextField} (without + * applying the formatting string) will be used for selection, instead. + * @param string the field of the data source that provides the key selecting an item in dropdown list. + */ + public function setDataValueField($value) + { + $this->setViewState('DataValueField',$value,''); } /** @@ -257,7 +281,7 @@ class TDropDownListColumn extends TDataGridColumn case TListItemType::Item: case TListItemType::AlternatingItem: case TListItemType::SelectedItem: - if($this->getDataField()!=='') + if($this->getDataTextField()!=='' || $this->getDataValueField()!=='') $cell->attachEventHandler('OnDataBinding',array($this,'dataBindColumn')); break; } @@ -272,14 +296,24 @@ class TDropDownListColumn extends TDataGridColumn { $item=$sender->getNamingContainer(); $data=$item->getDataItem(); - if(($field=$this->getDataField())!=='') - $data=$this->getDataFieldValue($data,$field); - $formatString=$this->getDataFormatString(); - $value=$this->formatDataValue($formatString,$data); + if(($valueField=$this->getDataValueField())!=='') + $value=$this->getDataFieldValue($data,$valueField); + else + $value=''; + if(($textField=$this->getDataTextField())!=='') + { + $text=$this->getDataFieldValue($data,$textField); + if($valueField==='') + $value=$text; + $formatString=$this->getDataTextFormatString(); + $text=$this->formatDataValue($formatString,$text); + } + else + $text=$value; if($sender instanceof TTableCell) - $sender->setText($value); + $sender->setText($text); else if($sender instanceof TDropDownList) - $sender->setSelectedValue($data); + $sender->setSelectedValue($value); } } -- cgit v1.2.3