设置对象或数组字段值
@param object|array $item            数组或对象
@param unknown $field                字段名或数组键
@param unknown $value                字段值或数组值
@param string $objectFieldAccess     设置对象属性时,是否允许直接访问对象的属性(默认为false,只能通过etter设置)
493870
public static function setFieldValue(&$item,$field,$value,$objectFieldAccess=false)
    {
        if(is_array($item)){
            $item[$field]=$value;
        }else if(is_object($item)){
            ObjectUtil::setPropertyValue($item, $field, $value,$objectFieldAccess);
        }
    }
751670
private static function getFieldValue($item,$field,$isObject=false, $fieldGetter=null)
    {
        if(!$isObject){
            return $item[$field];
        }else if($isObject && $fieldGetter){
            return $item->$fieldGetter();
        }else if($isObject && property_exists($item, $field)){
            return $item->$field;
        }
        return null;
    }
759671
protected function getFieldAccessorValue(Field $field, $view)
    {
        $fieldAccessor = sprintf('$%s->%s', $this->getSingularVariable($this->modelName), $field->name);

        if ($field->hasForeignRelation() && $field->isOnView($view)) {
            $relation = $field->getForeignRelation();
            if (Helpers::isNewerThanOrEqualTo('5.5')) {
                $fieldAccessor = sprintf('optional($%s->%s)->%s', $this->getSingularVariable($this->modelName), $relation->name, $relation->getField());
            } else {
                $fieldAccessor = sprintf('$%s->%s->%s', $this->getSingularVariable($this->modelName), $relation->name, $relation->getField());
                $fieldAccessor = sprintf(" isset(%s) ? %s : '' ", $fieldAccessor, $fieldAccessor);
            }
        }

        if ($field->isBoolean()) {
            return sprintf("(%s) ? '%s' : '%s'", $fieldAccessor, $field->getTrueBooleanOption()->text, $field->getFalseBooleanOption()->text);
        }

        if ($field->isMultipleAnswers()) {
            return sprintf("implode('%s', %s)", $field->optionsDelimiter, $fieldAccessor);
        }

        return $fieldAccessor;
    }
293391
private function find_item_key( $item, $field ) {
		foreach ( array( $field, $this->prefix . '_' . $field ) as $maybe_key ) {
			if ( ( is_object( $item ) && ( property_exists( $item, $maybe_key ) || isset( $item->$maybe_key ) ) ) || ( is_array( $item ) && array_key_exists( $maybe_key, $item ) ) ) {
				$key = $maybe_key;
				break;
			}
		}

		if ( ! isset( $key ) ) {
			\WP_CLI::error( "Invalid field: $field." );
		}

		return $key;
	}
733772
protected function checkItem( $field, $value, $rules, $data, $title = '', $msg = [] )
	{
		if( isset( $this->remove[$field] ) && true === $this->remove[$field] && empty( $this->append[$field] ) ){
			// 字段已经移除 无需验证
			return true;
		}
		// 支持多规则验证 require|in:a,b,c|... 或者 ['require','in'=>'a,b,c',...]
		if( is_string( $rules ) ){
			$rules = explode( '|', $rules );
		}
		if( isset( $this->append[$field] ) ){
			// 追加额外的验证规则
			$rules = array_merge( $rules, $this->append[$field] );
		}
		$lang = require_once "lang/zh-cn.php";
		$i    = 0;
		foreach( $rules as $key => $rule ){
			if( $rule instanceof \Closure ){
				$result = call_user_func_array( $rule, [$value, $data] );
				$info   = is_numeric( $key ) ? '' : $key;
			} else{
				// 判断验证类型
				list( $type, $rule, $info ) = $this->getValidatorType( $key, $rule );
				if( isset( $this->append[$field] ) && in_array( $info, $this->append[$field] ) ){
				} elseif( isset( $this->remove[$field] ) && in_array( $info, $this->remove[$field] ) ){
					// 规则已经移除
					$i ++;
					continue;
				}
				if( 'must' == $info || 0 === strpos( $info, 'require' ) || (!is_null( $value ) && '' !== $value) ){
					// 验证类型
					$callback = isset( self::$type[$type] ) ? self::$type[$type] : [$this, $type];
					// 验证数据
					$result = call_user_func_array( $callback, [$value, $rule, $data, $field, $title] );
				} else{
					$result = true;
				}
			}
			if( false === $result ){
				// 验证失败 返回错误信息
				if( !empty( $msg[$i] ) ){
					$message = $msg[$i];
					if( is_string( $message ) && strpos( $message, '{%' ) === 0 ){
						$message = $lang[substr( $message, 2, - 1 )];
					}
				} else{
					$message = $this->getRuleMsg( $field, $title, $info, $rule );
				}
				return $message;
			} elseif( true !== $result ){
				// 返回自定义错误信息
				if( is_string( $result ) && false !== strpos( $result, ':' ) ){
					$result = str_replace( [':attribute', ':rule'], [$title, (string)$rule], $result );
				}
				return $result;
			}
			$i ++;
		}
		return $result;
	}
931420
void setField(int accessor, Object value) {
    try {
      jmfPart.setValue(accessor, value);
    } catch (JMFException e) {
      FFDCFilter.processException(e, "setField", "87", this);
      if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) SibTr.debug(this, tc, "setField failed: " + e);
    }
  }
307784
private function getPropertyValue($object, Property $field)
    {
        return $this->accessor->getValue($object, $field->getProperty());
    }
409755
protected function validate($field, $value, array $item_rules)
    {
        $this->preserveItem($field, $value, $item_rules);
        
        if (! array_key_exists('required', $item_rules)) {
            $item_rules['required'] = false;
        }
        
        if ($item_rules['required'] || $this->required($field, $value, $item_rules['required'])) {
            foreach ($item_rules as $rule => $satisfier) {
                $this->validateRule($this, $field, $value, $rule, $satisfier);
            }
        }
    }
1339858
public FieldAccessor create(final Field field) {

        ArgUtils.notNull(field, "field");

        final FieldAccessor accessor = new FieldAccessor();

        // 共通情報の設定
        accessor.name = field.getName();
        accessor.targetType = field.getType();
        accessor.declaringClass = field.getDeclaringClass();

        // フィールド情報の設定
        setupWithFiled(accessor, field);

        // getter情報の設定
        if(ClassUtils.isPrimitiveBoolean(accessor.getType())) {
            ClassUtils.extractBooleanGetter(accessor.getDeclaringClass(), accessor.getName())
                    .ifPresent(getter -> setupWithGetter(accessor, getter));

        } else {
            ClassUtils.extractGetter(accessor.getDeclaringClass(), accessor.getName(), accessor.getType())
                    .ifPresent(getter -> setupWithGetter(accessor, getter));
        }

        // setter情報の設定
        ClassUtils.extractSetter(accessor.getDeclaringClass(), accessor.getName(), accessor.getType())
                .ifPresent(setter -> setupWithSetter(accessor, setter));

        // コンポーネントタイプの設定
        if(Collection.class.isAssignableFrom(accessor.getType())) {
            ParameterizedType type = (ParameterizedType) field.getGenericType();
            accessor.componentType = Optional.of((Class<?>) type.getActualTypeArguments()[0]);

        } else if(accessor.getType().isArray()) {
            accessor.componentType = Optional.of(accessor.getType().getComponentType());

        } else if(Map.class.isAssignableFrom(accessor.getType())) {
            ParameterizedType type = (ParameterizedType) field.getGenericType();
            accessor.componentType = Optional.of((Class<?>) type.getActualTypeArguments()[1]);
        }

        // 位置・ラベル情報のアクセッサの設定
        if(accessor.hasAnnotation(XlsMapColumns.class)) {
            // マップ形式の場合
            accessor.mapPositionSetter = mapPositionSetterFactory.create(accessor.getDeclaringClass(), accessor.getName());
            accessor.mapLabelSetter = mapLabelSetterFactory.create(accessor.getDeclaringClass(), accessor.getName());

        } else if(accessor.hasAnnotation(XlsArrayColumns.class)
                || accessor.hasAnnotation(XlsArrayCells.class)
                || accessor.hasAnnotation(XlsLabelledArrayCells.class)
                || accessor.hasAnnotation(XlsIterateTables.class)){
            // リストや配列形式の場合
            accessor.arrayPositionSetter = arrayPositionSetterFactory.create(accessor.getDeclaringClass(), accessor.getName());
            accessor.arrayLabelSetter = arrayLabelSetterFactory.create(accessor.getDeclaringClass(), accessor.getName());

            if(accessor.hasAnnotation(XlsArrayColumns.class)
                    || accessor.hasAnnotation(XlsLabelledArrayCells.class)) {
                // インデックスが付いていないラベルの設定
                accessor.labelSetter = labelSetterFactory.create(accessor.getDeclaringClass(), accessor.getName());
            }

        } else {
            // リストやMapではない通常のプロパティの場合
            accessor.positionSetter = positionSetterFactory.create(accessor.getDeclaringClass(), accessor.getName());
            accessor.positionGetter = positionGetterFactory.create(accessor.getDeclaringClass(), accessor.getName());

            accessor.labelSetter = labelSetterFactory.create(accessor.getDeclaringClass(), accessor.getName());
            accessor.labelGetter = labelGetterFactory.create(accessor.getDeclaringClass(), accessor.getName());

        }

        return accessor;
    }
957921
public function getValue(ArrayAccess $item): string
    {
        $value = $item->offsetExists($this->name)
            ? $item->offsetGet($this->name)
            : '';

        if (is_callable($this->filter)) {
            if ($this->filter instanceof ContextAwareFilterInterface) {
                $this->filter->setContext(clone $item);
            }

            $value = call_user_func($this->filter, $value);
        }

        return $value;
    }
308275
static public function renderField($value, array $options, $item)
    {
        if (empty($options['name'])) {
            return '';
        }
        if (empty($value) || !is_array($value)) {
            return '';
        }

        if (!$item instanceof EntityInterface) {
            return '';
        }

        $output = field_view_field($item->getEntityTypeId(), $item, $options['name'], self::LIST_VIEW_MODE);

        return drupal_render($output);
    }
655026
protected function setIfDefined($object, $field)
    {
        $propertyAccessor = $this->getPropertyAccessor();
        if (!$this->_has($field)) {
            return $propertyAccessor->isReadable($object, $field) ?
                $propertyAccessor->getValue($object, $field) :
                null
            ;
        }

        $propertyAccessor->setValue(
            $object,
            $field,
            $value = $this->_get($field)
        );

        return $value;
    }
511029
protected void setField(Field field, Object object) throws IllegalAccessException {
		dataObject.setField(field, object);
	}
456284
private function setFieldValue($entity, \ReflectionProperty $reflectionProperty, $value)
    {
        if ($reflectionProperty) {
            $reflectionProperty->setAccessible(true);
            $value = $reflectionProperty->setValue($entity, $value);
        }
    }
303335
private function handleMultiTap($item, $column, $value, $operator, $inverse)
    {
        list($objectToSearch, $columnToSearch) = $this->tapThroughObjects($column, $item);

        if ($objectToSearch instanceof self) {
            foreach ($objectToSearch as $subObject) {
                // The column has a tap that ends in a collection.
                return $this->whereObject($subObject, $columnToSearch, $operator, $value, $inverse);
            }
        } else {
            // The column has a tap that ends in direct access
            return $this->whereObject($objectToSearch, $columnToSearch, $operator, $value, $inverse);
        }
    }
810700
protected function processFile(DataObject $object, $field, $value, $class)
    {
        // Initialise:
        
        $source = null;
        $folder = null;
        
        // Detect Value Type:
        
        if (is_array($value)) {
            
            // Handle Array Value:
            
            $source = isset($value['Source']) ? $value['Source'] : null;
            $folder = isset($value['Folder']) ? $value['Folder'] : null;
            
        } else {
            
            // Handle String Value:
            
            $source = $value;
            
        }
        
        // Obtain Folder (if required):
        
        if (!$folder) {
            $folder = $this->getFolderName($object, $field);
        }
        
        // Obtain Source Path:
        
        $path = Director::getAbsFile($source);
        
        // Does Source Exist?
        
        if (file_exists($path)) {
            
            // Obtain Base Name:
            
            $basename = basename($path);
            
            // Define Asset Filename:
            
            $filename = sprintf('%s/%s', $folder, $basename);
            
            // Obtain or Create File:
            
            if (!($file = File::find($filename))) {
                $file = Injector::inst()->create($class);
            }
            
            // Define File Contents:
            
            $file->setFromLocalFile($path, $filename);
            
            // Write and Publish File:
            
            $file->write();
            $file->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
            
            // Answer File ID:
            
            return $file->ID;
        }
    }
566455
public static void setProperty(final Object object, final Field field, final Object value) throws IllegalAccessException {
        boolean access = field.isAccessible();
        field.setAccessible(true);
        field.set(object, value);
        field.setAccessible(access);
    }