获取对象属性值
@param object $obj           对象
@param string $propertyName  属性名
@param bool $fieldAccess     getter不存在时,是否允许通过公开的字段访问
@return mixed
765432
public static function getPropertyValue($obj,$propertyName,$fieldAccess=false)
    {
        $getter=self::getGetter($obj, $propertyName);
        if(!empty($getter)){
            return $obj->$getter();
        }else if($fieldAccess && property_exists($obj, $propertyName)){
            return $obj->$propertyName;
        }
    }
609393
public static void setFieldValue(final Object obj, final String fieldName, final Object value) {
		Field field = getAccessibleField(obj, fieldName);

		if (field == null) {
			throw new IllegalArgumentException("Could not find field [" + fieldName + "] on target [" + obj + "]");
		}

		try {
			field.set(obj, value);
		} catch (IllegalAccessException e) {
			logger.error("不可能抛出的异常:{}", e.getMessage());
		}
	}
938418
public static Object getObjectCopy(Object from, Field field)
    {
        if (!field.isAccessible())
        {
            field.setAccessible(true);
        }
        try
        {
            PropertyAccessor<?> accessor = PropertyAccessorFactory.getPropertyAccessor(field);
            return accessor.getCopy(field.get(from));
        }
        catch (IllegalArgumentException iarg)
        {
            throw new PropertyAccessException(iarg);
        }
        catch (IllegalAccessException iacc)
        {
            throw new PropertyAccessException(iacc);
        }
    }
238927
public static Object getFieldVal(Object obj, String fieldName) {
        Field field;
        if (obj == null) {
            return null;
        }
        try {
            field = getField(obj.getClass(), fieldName);
            field.setAccessible(true);//取消安全机制限制
            return field.get(obj);
        } catch (SecurityException e) {
            e.printStackTrace();
            return null;
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
            return null;
        } catch (IllegalAccessException e) {
            e.printStackTrace();
            return null;
        }
    }
456495
public function parser(string $className, $objectAnnotation = null, string $propertyName = "", string $methodName = "", $propertyValue = null)
    {
        $swoftDir      = dirname(__FILE__, 5);
        $componentDirs = scandir($swoftDir);
        foreach ($componentDirs as $component) {
            if ($component == '.' || $component == '..') {
                continue;
            }

            $componentCommandDir = $swoftDir . DS . $component . DS . 'src/Bean/Collector';
            if (!is_dir($componentCommandDir)) {
                continue;
            }

            $componentNs = ComponentHelper::getComponentNs($component);
            $collectNs = "Swoft{$componentNs}\\Bean\\Collector";
            $collectorFiles = scandir($componentCommandDir);
            foreach ($collectorFiles as $collectorFile){
                $pathInfo = pathinfo($collectorFile);
                if(!isset($pathInfo['filename'])){
                    continue;
                }
                $fileName = $pathInfo['filename'];
                $collectClassName = $collectNs.'\\'.$fileName;
                if(!class_exists($collectClassName)){
                    continue;
                }

                /* @var \Swoft\Bean\CollectorInterface $collector */
                $collector = new $collectClassName();
                $collector->collect($className, $objectAnnotation, $propertyName, $methodName, $propertyValue);
            }
        }

        return null;
    }
738298
public function getFieldByPropertyName(string $propertyName): ?FieldMetadataInterface
    {
        foreach ($this->fieldsMetadata as $fieldMetadata) {
            if ($propertyName === $fieldMetadata->getPropertyName()) {
                return $fieldMetadata;
            }
        }

        return null;
    }
1190510
public static Field getAccessibleField(final Object obj, final String fieldName) {
		if(obj == null)
			throw new IllegalArgumentException("object cannot be null.");
		if(fieldName == null || fieldName.trim().length() == 0)
			throw new IllegalArgumentException("fieldName cannot be null.");
		for (Class<?> superClass = obj.getClass(); superClass != Object.class; superClass = superClass.getSuperclass()) {
			try {
				Field field = superClass.getDeclaredField(fieldName);
				field.setAccessible(true);
				return field;
			} catch (NoSuchFieldException e) {//NOSONAR
				// Field不在当前类定义,继续向上转型
			}
		}
		return null;
	}
814230
public static Object getFieldValue(Object instance, String fieldName) {
		try {
			return PropertyUtils.getProperty(instance, fieldName);
		} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
			JK.throww(e);
			return null;
		}
	}
838387
public static Object getFieldValue(Object obj, Field field) throws UtilException {
		if (null == obj || null == field) {
			return null;
		}
		field.setAccessible(true);
		Object result = null;
		try {
			result = field.get(obj);
		} catch (IllegalAccessException e) {
			throw new UtilException(e, "IllegalAccess for {}.{}", obj.getClass(), field.getName());
		}
		return result;
	}
1273340
public Object executeGetValue(Object pvObject) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
		Object lvReturnValue = null;
		AccessController.doPrivileged(new AccessiblePrivilegedAction(accessibleObject));
		if (propertyType == PROPERTY_TYPE_METHOD) {
			lvReturnValue = ((Method) accessibleObject).invoke(pvObject);	
		} else {
			lvReturnValue = ((Field) accessibleObject).get(pvObject);
		}
		return lvReturnValue;
	}
882839
private Object[] getDataType(EntityMetadata entityMetadata, Object... arg1) throws PropertyAccessException
    {
        Field idField = (Field) entityMetadata.getIdAttribute().getJavaMember();
        PropertyAccessor<?> accessor = PropertyAccessorFactory.getPropertyAccessor(idField);

        Object[] pKeys = new Object[arg1.length];
        int cnt = 0;
        for (Object r : arg1)
        {
            pKeys[cnt++] = accessor.fromString(idField.getClass(), r.toString());
        }
        return pKeys;
    }
129978
private function set($object, $propertyName, $propertyValue)
    {
        $reflectionUser = new \ReflectionClass($object);

        $reflectionProperty = $reflectionUser->getProperty($propertyName);
        $reflectionProperty->setAccessible(true);
        $reflectionProperty->setValue($object, $propertyValue);

        return $object;
    }
1152267
public function getProperty(&$object, string $propertyName)
    {
        $reflection = new ReflectionClass(get_class($object));

        /** @var ReflectionProperty $property */
        $property = $reflection->getProperty($propertyName);
        $property->setAccessible(true);

        return $property->getValue($object);
    }
964922
public function parser(string $className, $objectAnnotation = null, string $propertyName = "", string $methodName = "", $propertyValue = null)
    {
        $injectValue = $objectAnnotation->getName();
        $envValue    = $objectAnnotation->getEnv();
        if (empty($injectValue) && empty($envValue)) {
            throw new \InvalidArgumentException("the name and env of @Value can't be empty! class={$className} property={$propertyName}");
        }

        $isRef          = false;
        $injectProperty = null;
        if (!empty($injectValue)) {
            list($injectProperty, $isRef) = $this->annotationResource->getTransferProperty($injectValue);
        }

        if (!empty($envValue)) {
            $value          = $this->getEnvValue($envValue);
            $isArray        = $this->isEnvArrayValue($className, $propertyName);
            $value          = $this->getTransferEnvValue($value, $isArray);
            $injectProperty = ($value !== null) ? $value : $injectProperty;
            $isRef          = ($value !== null) ? false : $isRef;
        }

        return [$injectProperty, $isRef];
    }
475869
protected final Object getProperty(final Object obj, final String property) {
        if ((obj == null) || (property == null) || (property.trim().length() == 0)) {
            return null;
        }
        final String[] getterNames = createGetterNames(property);
        for (int i = 0; i < getterNames.length; i++) {
            final String getter = getterNames[i];
            try {
                final Class cl = obj.getClass();
                final Method m = cl.getMethod(getter, new Class[] {});
                return m.invoke(obj, new Object[] {});
            } catch (final IllegalAccessException e) {
                throw new RuntimeException("Accessing " + getter + " method of property '" + property + "' failed (private? protected?)! ["
                        + obj.getClass() + "]", e);
            } catch (final InvocationTargetException e) {
                throw new RuntimeException(
                        "Exception within " + getter + " method of property '" + property + "'! [" + obj.getClass() + "]", e.getCause());
            } catch (final NoSuchMethodException e) {
                if (i == getter.length() - 1) {
                    throw new RuntimeException("No " + getter + " method found for property! '" + property + "'! [" + obj.getClass() + "]",
                            e);
                }
            }
        }
        throw new IllegalStateException("No getters defined in 'createGetterNames()'!");
    }
319301
public static function copyPropertyValues($srcObject,$destObject,$fieldMap=null,$fieldAccess=false)
    {
        if(!is_object($srcObject)||!is_object($destObject)){
            return false;
        }
        $destFields=[];
        if($fieldAccess){
            $destFields=array_keys(get_object_vars($destObject));
        }
        if($fieldMap==null){
            $fieldMap=[];
        }
        foreach (get_object_vars($srcObject) as $prop=>$value){
            $destProp=array_key_exists($prop, $fieldMap)?$fieldMap[$prop]:$prop;
            if(self::hasSetter($destObject, $destProp)){
                self::setPropertyValue($destObject, $destProp, $value);
            }else if(in_array($destProp, $destFields)){
                $destObject->$destProp=$value;
            }
        }
    }
1401
public static Properties getFieldsAsProperties(Object obj, Class<?>[] clazzes) throws Exception {
        Properties props = new Properties();
        for (Field field : obj.getClass().getDeclaredFields()) {
            if (Modifier.isStatic(field.getModifiers()))
                continue;
            field.setAccessible(true);
            Class<?> type = field.getType();
            if (clazzes == null || contains(type, clazzes)) {
                Object val = field.get(obj);
                if (val != null)
                    props.put(field.getName(), val.toString());

            }
        }

        return props;
    }