初始化对象

@param $bean
169587
private static function prepareBean($bean) {
        $class = new \ReflectionClass(get_class($bean));
        if ($class->hasMethod('_initialize')) {
            self::invokeWithIocParams($bean, "_initialize");
            static::$injectBeans[] = $bean;
            if (static::$injectBeans[ 0 ] === $bean) {
                for ($i = count(static::$injectBeans) - 1; $i > -1; $i--) {
                    $class = new \ReflectionClass(get_class(static::$injectBeans[ $i ]));
                    if ($class->hasMethod('_prepared')) {
                        static::$injectBeans[ $i ]->_prepared();
                    }
                }
                static::$injectBeans = array();
            }
        }
    }
934674
public function clearTag(string $tag): void
    {
        // 指定标签清除
        $keys = $this->getTagItems($tag);

        $this->handler->deleteMulti($keys);

        $tagName = $this->getTagKey($tag);
        $this->rm($tagName);
    }
35923
public static Object getFieldValue(Object bean, String fieldNameOrIndex) {
		if (null == bean || null == fieldNameOrIndex) {
			return null;
		}

		if (bean instanceof Map) {
			return ((Map<?, ?>) bean).get(fieldNameOrIndex);
		} else if (bean instanceof Collection) {
			return CollUtil.get((Collection<?>) bean, Integer.parseInt(fieldNameOrIndex));
		} else if (ArrayUtil.isArray(bean)) {
			return ArrayUtil.get(bean, Integer.parseInt(fieldNameOrIndex));
		} else {// 普通Bean对象
			return ReflectUtil.getFieldValue(bean, fieldNameOrIndex);
		}
	}
58656
public function execute($sql) {

        //如果开启了调试模式，那么把所有对数据库写操作的语句记录下来
        if ( SQL_LOG &&
            (strpos($sql, 'INSERT') !== false
                || strpos($sql, 'DELETE') !== false
                || strpos($sql, 'REPLACE') !== false
                    || strpos($sql, 'UPDATE') !== false)) {
            Log::info($sql, 'sql');
        }
        if ( $this->link == null ) $this->connect();
        try {
            $result = $this->link->query($sql);
        } catch ( PDOException $e ) {
            $exception = new DBException("SQL错误:" . $e->getMessage());
            $exception->setCode($e->getCode());
            $exception->setQuery($sql);
            if ( APP_DEBUG ) {
                __print($sql);
            }
            throw $exception;
        }
        return $result;
    }
214952
private static void doBeanMapping(BeanMappingParam param, BeanMappingField beanField, BatchObjectHolder holder) {
        // 定义valueContext
        ValueProcessContext valueContext = new ValueProcessContext(param, param.getConfig(), beanField, holder,
                                                                   param.getCustomValueContext());
        // 检查一下targetClass是否有设置，针对bean对象有效
        // 如果目标对象是map，需要客户端强制设定targetClass
        GetExecutor getExecutor = beanField.getGetExecutor();
        if (getExecutor == null && StringUtils.isNotEmpty(beanField.getSrcField().getName())) {// 可能存在为空
            Class locatorClass = beanField.getSrcField().getLocatorClass();// 从locatorClass中获取
            if (locatorClass == null) {
                locatorClass = param.getSrcRef().getClass();
                beanField.getSrcField().setLocatorClass(locatorClass);
            }
            getExecutor = Uberspector.getInstance().getGetExecutor(locatorClass, beanField.getSrcField().getName());
            beanField.setGetExecutor(getExecutor);
        }

        SetExecutor setExecutor = beanField.getSetExecutor();
        if (setExecutor == null && StringUtils.isNotEmpty(beanField.getTargetField().getName())) {// 可能存在为空
            Class locatorClass = beanField.getTargetField().getLocatorClass();// 从locatorClass中获取
            if (locatorClass == null) {
                locatorClass = param.getTargetRef().getClass();
                beanField.getTargetField().setLocatorClass(locatorClass);
            }
            setExecutor = Uberspector.getInstance().getSetExecutor(locatorClass, beanField.getTargetField().getName(),
                                                                   beanField.getTargetField().getClazz());
            beanField.setSetExecutor(setExecutor);
        }

        // 获取新的srcRef
        // 获取get结果
        ValueProcessInvocation invocation = new ValueProcessInvocation(getExecutor, setExecutor, valueContext,
                                                                       param.getProcesses());
        Object srcRef = invocation.getInitialValue();

        // 设置下srcClass
        Class getResultClass = (srcRef != null) ? srcRef.getClass() : null;
        // 设置下srcClass
        if (getExecutor != null && beanField.getSrcField().getClazz() == null) {
            beanField.getSrcField().setClazz(
                                             Uberspector.getInstance().getGetClass(getExecutor,
                                                                                   param.getSrcRef().getClass(),
                                                                                   getResultClass));
        }

        if (setExecutor != null && beanField.getTargetField().getClazz() == null) {
            beanField.getTargetField().setClazz(
                                                Uberspector.getInstance().getSetClass(setExecutor,
                                                                                      param.getTargetRef().getClass(),
                                                                                      getResultClass));
            if (setExecutor instanceof MapSetExecutor) {
                beanField.getTargetField().setClazz(HashMap.class);// 注意这里强制传递为HashMap.class
            }
        }

        // 执行set,反射构造一个子Model
        // 如果嵌套对象为null，则直接略过该对象处理，目标对象也为null,此时srcRef可能为null
        Object value = invocation.proceed(srcRef); // 在目标节点对象上，创建一个子节点
        if (srcRef == null && value == null) {
            return; // 如果为null，则不做递归处理
        }

        if (beanField.getSrcField().getClazz() == null || beanField.getTargetField().getClazz() == null) {
            throw new BeanMappingException("srcClass or targetClass is null , " + beanField.toString());
        }
        // change for v1.0.2
        BeanMappingObject object = beanField.getNestObject();
        if (object == null) {
            if (StringUtils.isNotEmpty(beanField.getNestName())) {

                object = BeanMappingConfigHelper.getInstance().getBeanMappingObject(beanField.getNestName());
            } else {
                object = BeanMappingConfigHelper.getInstance().getBeanMappingObject(
                                                                                    beanField.getSrcField().getClazz(),
                                                                                    beanField.getTargetField().getClazz());
            }

            beanField.setNestObject(object);// cache一下结果
        }

        if (object == null) {
            throw new BeanMappingException("no bean mapping config for " + beanField.toString());
        }
        BeanMappingParam newParam = new BeanMappingParam();
        newParam.setTargetRef(value);// 为新创建的子model，注意使用value，可以在SetValueProcess中会创建新对象
        newParam.setSrcRef(srcRef);
        newParam.setConfig(object);
        // 复制并传递
        newParam.setProcesses(param.getProcesses());
        // 进行递归调用
        execute(newParam);
    }
700812
private void registerDAODefinition(ConfigurableListableBeanFactory beanFactory,
            BeanDefinition beanDefinition) {
        final String daoClassName = beanDefinition.getBeanClassName();
        MutablePropertyValues propertyValues = beanDefinition.getPropertyValues();
        /*
         * 属性及其设置要按 JadeFactoryBean 的要求来办
         */
        propertyValues.addPropertyValue("objectType", daoClassName);
        propertyValues.addPropertyValue("dataAccessFactory", getDataAccessFactory(beanFactory));
        propertyValues.addPropertyValue("rowMapperFactory", getRowMapperFactory());
        propertyValues.addPropertyValue("interpreterFactory", getInterpreterFactory(beanFactory));
        String cacheProviderName = getCacheProviderName(beanFactory);
        if (cacheProviderName != null) {
            RuntimeBeanReference beanRef = new RuntimeBeanReference(cacheProviderName);
            propertyValues.addPropertyValue("cacheProvider", beanRef);
        }
        String statementWrapperProvider = getStatementWrapperProvider(beanFactory);
        if (statementWrapperProvider != null) {
            RuntimeBeanReference beanRef = new RuntimeBeanReference(statementWrapperProvider);
            propertyValues.addPropertyValue("statementWrapperProvider", beanRef);
        }
        ScannedGenericBeanDefinition scannedBeanDefinition = (ScannedGenericBeanDefinition) beanDefinition;
        scannedBeanDefinition.setPropertyValues(propertyValues);
        scannedBeanDefinition.setBeanClass(JadeFactoryBean.class);

        DefaultListableBeanFactory defaultBeanFactory = (DefaultListableBeanFactory) beanFactory;
        defaultBeanFactory.registerBeanDefinition(daoClassName, beanDefinition);

        if (logger.isDebugEnabled()) {
            logger.debug("[jade] register DAO: " + daoClassName);
        }
    }
618801
private void populateMap(Object bean) {
		final Collection<PropDesc> props = BeanUtil.getBeanDesc(bean.getClass()).getProps();

		Method getter;
		Object value;
		for (PropDesc prop : props) {
			// 得到property对应的getter方法
			getter = prop.getGetter();
			if (null == getter) {
				// 无Getter跳过
				continue;
			}

			// 只读取有getter方法的属性
			try {
				value = getter.invoke(bean);
			} catch (Exception ignore) {
				// 忽略读取失败的属性
				continue;
			}

			if (ObjectUtil.isNull(value) && this.config.isIgnoreNullValue()) {
				// 值为null且用户定义跳过则跳过
				continue;
			}

			if (value != bean) {
				// 防止循环引用
				this.rawHashMap.put(prop.getFieldName(), JSONUtil.wrap(value, this.config.isIgnoreNullValue()));
			}
		}
	}
1142183
public final void configure(Object bean)
  {
    Objects.requireNonNull(bean);
    
    Thread thread = Thread.currentThread();
    ClassLoader loader = thread.getContextClassLoader();
    
    /*
    ContextConfig oldContext = ContextConfig.getCurrent();
    
    try {
      ContextConfig.setCurrent(new ContextConfig(new Config()));
      
      ConfigType<?> type = TypeFactoryConfig.getType(bean);

      configure(bean, type);
    } finally {
      ContextConfig.setCurrent(oldContext);
    }
    */
  }
522136
private function beforeCommand(string $class, string $command, bool $server)
    {
        if ($server) {
            return;
        }
        $this->bootstrap();
        BeanFactory::reload();

        // 初始化
        $spanId = 0;
        $logId = uniqid();

        $uri = $class . '->' . $command;
        $contextData = [
            'logid'       => $logId,
            'spanid'      => $spanId,
            'uri'         => $uri,
            'requestTime' => microtime(true),
        ];

        RequestContext::setContextData($contextData);
    }
1083052
public static void validate(@NotNull Object bean) {
        Assert.notNull(bean, "bean不能为null");
        Set<ConstraintViolation<Object>> constraintViolations = validator.validate(bean);
        check(constraintViolations);
    }
463411
void setValue(T bean, String value) {
    ref.writeValue(converter.fromCharacters(value), bean);
  }
1066784
protected final function onInitValidator($fields = []) {
		if (empty($fields)) {
			if (isset($this->_fields) && $this->_fields) {
				$fields = $this->_fields;
			} else if (!isset($this->_fields)) {
				$obj  = new \ReflectionObject($this);
				$vars = $obj->getProperties(\ReflectionProperty::IS_PUBLIC);
				foreach ($vars as $var) {
					$name            = $var->getName();
					$fields[ $name ] = ['annotation' => new Annotation($var)];
				}
				unset($obj, $vars);
			}
		}
		if ($fields) {
			foreach ($fields as $field => $def) {
				$rule = [];
				/**@var $ann \wulaphp\util\Annotation */
				$ann  = $def['annotation'];
				$anns = $ann->getAll();
				if (!$anns) continue;
				$multiple = $def['type'] == 'array' || $def['type'] == '[]';
				foreach ($anns as $an => $va) {
					if (isset($this->preDefinedRule[ $an ]) && !is_array($va)) {
						// 用=>分隔参数与提示消息.$r[0]参数,$r[1]为提示信息
						$r   = $va ? preg_split('/\s*=>\s*/u', $va) : [];
						$len = count($r);
						if ($len == 0) {
							$rule[ $an ] = null;
						} else {
							if (preg_match('/^\(.+\)$/', trim($r[0]))) {
								if (isset($r[1])) {
									$rule[ $an . $r[0] ] = $r[1];
								} else {
									$rule[ $an . $r[0] ] = null;
								}
							} else {
								$rule[ $an ] = $r[0];
							}
						}
					}
				}
				if ($rule) {
					$this->addRule($field, $rule, $multiple);
				}
			}
		}
	}
744182
protected function beforeRender($data=null)
    {
        // 非调试模式下，清除缓存区以免影响输出?
        if (!Config::get('debug')) {
            //ob_end_clean();
        }
        $this->clearRenderBuffer();
        
        $data && $this->responseData($data);
        
    }
850530
private <T> void destroyReference(final Bean<T> bean, final T beanInstance) {
        bean.destroy(beanInstance);
    }
1040121
public static function needWarp($bean) {
        if (array_key_exists($bean, static::$beforeActions) || array_key_exists($bean, static::$afterActions) || array_key_exists($bean, static::$aroundActions)) {
            return true;
        }
        return false;
    }
1362432
public static function wrap($bean, $modelClass = null)
    {
        if (is_array($bean)) {
            $collection = new Collection($bean);
            $collection->map(function ($item) use ($modelClass) {
                if ($modelClass) {
                    return new $modelClass($item);
                } else {
                    return new static($item);
                }
            });
            return $collection;
        } elseif ($bean instanceof OODBBean) {
            if ($modelClass) {
                return new $modelClass($bean);
            } else {
                return new static($bean);
            }
        } else {
            return $bean;
        }
    }
1273334
public function setRule($rule)
    {
        if ('$' == substr($rule, -1, 1)) {
            // 是否完整匹配
            $rule = substr($rule, 0, -1);

            $this->option['complete_match'] = true;
        }

        $rule = '/' != $rule ? ltrim($rule, '/') : '';

        if ($this->parent && $prefix = $this->parent->getFullName()) {
            $rule = $prefix . ($rule ? '/' . ltrim($rule, '/') : '');
        }

        if (false !== strpos($rule, ':')) {
            $this->rule = preg_replace(['/\[\:(\w+)\]/', '/\:(\w+)/'], ['<\1?>', '<\1>'], $rule);
        } else {
            $this->rule = $rule;
        }

        // 生成路由标识的快捷访问
        $this->setRuleName();
    }