summaryrefslogtreecommitdiff
path: root/framework/Data/TDataFieldAccessor.php
diff options
context:
space:
mode:
authorxue <>2006-03-31 12:42:22 +0000
committerxue <>2006-03-31 12:42:22 +0000
commit6845c00a3f752abecd9ef763848329bceaf63df4 (patch)
treed573c37ad864edde9a04f1c7b415afe6c2a9c1ef /framework/Data/TDataFieldAccessor.php
parent06fdd252452217716b1062b632fd2fc2195a66e2 (diff)
Reorganized folders under framework. This may break existing applications.
Diffstat (limited to 'framework/Data/TDataFieldAccessor.php')
-rw-r--r--framework/Data/TDataFieldAccessor.php117
1 files changed, 0 insertions, 117 deletions
diff --git a/framework/Data/TDataFieldAccessor.php b/framework/Data/TDataFieldAccessor.php
deleted file mode 100644
index aa6d7be7..00000000
--- a/framework/Data/TDataFieldAccessor.php
+++ /dev/null
@@ -1,117 +0,0 @@
-<?php
-/**
- * TDataFieldAccessor class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Revision: $ $Date: $
- * @package System.Data
- */
-
-/**
- * TDataFieldAccessor class
- *
- * TDataFieldAccessor is a utility class that provides access to a field of some data.
- * The accessor attempts to obtain the field value in the following order:
- * - If the data is an array, then the field is treated as an array index
- * and the corresponding element value is returned;
- * - If the data is a TMap or TList object, then the field is treated as a key
- * into the map or list, and the corresponding value is returned.
- * - If the data is an object, the field is treated as a property or subproperty
- * defined with getter methods. For example, if the object has a method called
- * getMyValue(), then field 'MyValue' will retrive the result of this method call.
- * If getMyValue() returns an object which contains a method getMySubValue(),
- * then field 'MyValue.MySubValue' will return that method call result.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Revision: $ $Date: $
- * @package System.Data
- * @since 3.0
- */
-class TDataFieldAccessor
-{
- /**
- * Evaluates the data value at the specified field.
- * - If the data is an array, then the field is treated as an array index
- * and the corresponding element value is returned;
- * - If the data is a TMap or TList object, then the field is treated as a key
- * into the map or list, and the corresponding value is returned.
- * - If the data is an object, the field is treated as a property or subproperty
- * defined with getter methods. For example, if the object has a method called
- * getMyValue(), then field 'MyValue' will retrive the result of this method call.
- * If getMyValue() returns an object which contains a method getMySubValue(),
- * then field 'MyValue.MySubValue' will return that method call result.
- * @param mixed data containing the field value, can be an array, TMap, TList or object.
- * @param mixed field value
- * @return mixed value at the specified field
- * @throw TInvalidDataValueException if field or data is invalid
- */
- public static function getDataFieldValue($data,$field)
- {
- if(Prado::getApplication()->getMode()===TApplication::STATE_PERFORMANCE)
- {
- if(is_array($data) || ($data instanceof ArrayAccess))
- return $data[$field];
- else if(is_object($data))
- {
- if(strpos($field,'.')===false) // simple field
- {
- if(property_exists($data,$field))
- return $data->{$field};
- else
- return call_user_func(array($data,'get'.$field));
- }
- else // field in the format of xxx.yyy.zzz
- {
- $object=$data;
- foreach(explode('.',$field) as $f)
- $object=call_user_func(array($object,'get'.$f));
- return $object;
- }
- }
- else
- throw new TInvalidDataValueException('datafieldaccessor_data_invalid',$field);
- }
- else
- {
- 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);
- }
- }
-}
-
-?> \ No newline at end of file