diff options
author | xue <> | 2007-12-24 16:06:39 +0000 |
---|---|---|
committer | xue <> | 2007-12-24 16:06:39 +0000 |
commit | a636ca22642c43b9df588714811da5679775fb38 (patch) | |
tree | a4d8038f15b7d6c30ba6dfda64e5a4dd7165d224 /framework/Util | |
parent | d253ed938b33aa5bf45351a81e1a4d596e69b5f7 (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/Util')
-rw-r--r-- | framework/Util/TDataFieldAccessor.php | 44 |
1 files changed, 5 insertions, 39 deletions
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);
}
}
|