summaryrefslogtreecommitdiff
path: root/framework
diff options
context:
space:
mode:
authorxue <>2007-12-24 16:06:39 +0000
committerxue <>2007-12-24 16:06:39 +0000
commita636ca22642c43b9df588714811da5679775fb38 (patch)
treea4d8038f15b7d6c30ba6dfda64e5a4dd7165d224 /framework
parentd253ed938b33aa5bf45351a81e1a4d596e69b5f7 (diff)
TDataFieldAccessor now supports chained property access without getters.
TJavaScript::encode() will encode data as a list if integer indices are detected.
Diffstat (limited to 'framework')
-rw-r--r--framework/Exceptions/messages/messages.txt2
-rw-r--r--framework/Util/TDataFieldAccessor.php44
-rw-r--r--framework/Web/Javascripts/TJavaScript.php24
3 files changed, 21 insertions, 49 deletions
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))