summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxue <>2007-12-24 16:06:39 +0000
committerxue <>2007-12-24 16:06:39 +0000
commita636ca22642c43b9df588714811da5679775fb38 (patch)
treea4d8038f15b7d6c30ba6dfda64e5a4dd7165d224
parentd253ed938b33aa5bf45351a81e1a4d596e69b5f7 (diff)
TDataFieldAccessor now supports chained property access without getters.
TJavaScript::encode() will encode data as a list if integer indices are detected.
-rw-r--r--HISTORY2
-rw-r--r--framework/Exceptions/messages/messages.txt2
-rw-r--r--framework/Util/TDataFieldAccessor.php44
-rw-r--r--framework/Web/Javascripts/TJavaScript.php24
4 files changed, 23 insertions, 49 deletions
diff --git a/HISTORY b/HISTORY
index aa993e7a..76880785 100644
--- a/HISTORY
+++ b/HISTORY
@@ -6,11 +6,13 @@ BUG: Fixed a bug in TPropertyValue::ensureArray() (Qiang)
CHG: Changed TConditional so that the controls in its template behave like they are in its parent (Qiang)
CHG: Active Record many-to-many relationship change from self::HAS_MANY to self::MANY_TO_MANY (Wei)
CHG: Active Record no longer automatically performs adding/removing/updating related objects (Qiang)
+CHG: TJavaScript::encode() will encode data as a list if integer indices are detected (Qiang)
ENH: Ticket#722 - Add Read Only capabilities to TInPlaceTextBox (Christophe)
ENH: Active Record supports multiple foreign references of the same table (Wei)
ENH: Added TDbCommand.queryColumn() (Qiang)
ENH: Active Record now supports implicitly declared related properties (Qiang)
ENH: Active Record now supports query criteria for implicitly declared related properties (Qiang)
+ENH: TDataFieldAccessor now supports chained property access without getters. (Qiang)
NEW: Added TDbLogRoute (Qiang)
NEW: Added TDataRenderer and TItemDataRenderer (Qiang)
NEW: Ticket#544 - Added TXCache (Wei)
diff --git a/framework/Exceptions/messages/messages.txt b/framework/Exceptions/messages/messages.txt
index 918a70cd..377baf51 100644
--- a/framework/Exceptions/messages/messages.txt
+++ b/framework/Exceptions/messages/messages.txt
@@ -283,7 +283,7 @@ datagridcolumncollection_datagridcolumn_required = TDataGridColumnCollection can
datagridpagerstyle_pagebuttoncount_invalid = TDataGridPagerStyle.PageButtonCount must be greater than 0.
datafieldaccessor_data_invalid = TDataFieldAccessor is trying to evaluate a field value of an invalid data. Make sure the data is an array, TMap, TList, or object that contains the specified field '{0}'.
-datafieldaccessor_datafield_invalid = TDataFieldAccessor is trying to evaluate data value of an unknown field '{0}'.
+datafieldaccessor_datafield_invalid = TDataFieldAccessor is trying to evaluate data value of an unknown field '{0}': {1}.
tablerowcollection_tablerow_required = TTableRowCollection can only accept TTableRow objects.
diff --git a/framework/Util/TDataFieldAccessor.php b/framework/Util/TDataFieldAccessor.php
index b5c65044..4acd9cd4 100644
--- a/framework/Util/TDataFieldAccessor.php
+++ b/framework/Util/TDataFieldAccessor.php
@@ -50,7 +50,7 @@ class TDataFieldAccessor
*/
public static function getDataFieldValue($data,$field)
{
- if(Prado::getApplication()->getMode()===TApplicationMode::Performance)
+ try
{
if(is_array($data) || ($data instanceof ArrayAccess))
return $data[$field];
@@ -67,50 +67,16 @@ class TDataFieldAccessor
{
$object=$data;
foreach(explode('.',$field) as $f)
- $object=call_user_func(array($object,'get'.$f));
+ $object=$object->$f;
return $object;
}
}
- else
- throw new TInvalidDataValueException('datafieldaccessor_data_invalid',$field);
}
- else
+ catch(Exception $e)
{
- if(is_array($data) || ($data instanceof ArrayAccess))
- {
- if(isset($data[$field]) || $data[$field]===null)
- return $data[$field];
- else
- throw new TInvalidDataValueException('datafieldaccessor_datafield_invalid',$field);
- }
- else if(is_object($data))
- {
- if(strpos($field,'.')===false) // simple field
- {
- if(property_exists($data,$field))
- return $data->{$field};
- else if(is_callable(array($data,'get'.$field)))
- return call_user_func(array($data,'get'.$field));
- else
- throw new TInvalidDataValueException('datafieldaccessor_datafield_invalid',$field);
- }
- else // field in the format of xxx.yyy.zzz
- {
- $object=$data;
- foreach(explode('.',$field) as $f)
- {
- $getter='get'.$f;
- if(is_callable(array($object,$getter)))
- $object=call_user_func(array($object,$getter));
- else
- throw new TInvalidDataValueException('datafieldaccessor_datafield_invalid',$field);
- }
- return $object;
- }
- }
- else
- throw new TInvalidDataValueException('datafieldaccessor_data_invalid',$field);
+ throw new TInvalidDataValueException('datafieldaccessor_datafield_invalid',$field,$e->getMessage());
}
+ throw new TInvalidDataValueException('datafieldaccessor_data_invalid',$field);
}
}
diff --git a/framework/Web/Javascripts/TJavaScript.php b/framework/Web/Javascripts/TJavaScript.php
index 228dc88f..4dce8e2e 100644
--- a/framework/Web/Javascripts/TJavaScript.php
+++ b/framework/Web/Javascripts/TJavaScript.php
@@ -153,20 +153,26 @@ class TJavaScript
return $value?'true':'false';
else if(is_array($value))
{
- $results=array();
- if($toMap)
+ $results='';
+ if(($n=count($value))>0 && array_keys($value)!==range(0,$n-1))
{
foreach($value as $k=>$v)
- if($v!=='')
- $results[]="'{$k}':".self::encode($v,$toMap);
- return '{'.implode(',',$results).'}';
+ {
+ if($results!=='')
+ $results.=',';
+ $results.="'$k':".self::encode($v,$toMap);
+ }
+ return '{'.$results.'}';
}
else
{
- foreach($value as $k=>$v)
- if($v!=='')
- $results[]=self::encode($v,$toMap);
- return '['.implode(',',$results).']';
+ foreach($value as $v)
+ {
+ if($results!=='')
+ $results.=',';
+ $results.=self::encode($v,$toMap);
+ }
+ return '['.$results.']';
}
}
else if(is_integer($value))