创建对象实例
@param string $forClass       类名
@param array $constructorArgs 构造参数
@return object
@throws \Exception
323221
public function newInstance($forClass,$constructorArgs=[])
    {
        $class = new \ReflectionClass($forClass);
        $constructor = $class->getConstructor();

        //无构造函数
        if($constructor==null){
            return new $forClass();
        }

        //有构造函数
        $parameters=$constructor->getParameters();
        $paramValues=[];
        for($i=0;$i<count($parameters);$i++){
            $parameter=$parameters[$i];
            $name=$parameter->name;
            $isDefaultValueAvailable=$parameter->isDefaultValueAvailable();
//             $allowsNull=$parameter->allowsNull();
//             $isArray=$parameter->isArray();
//             $isOptional=$parameter->isOptional();

            //参数取值:配置>默认
            if(array_key_exists($name, $constructorArgs)){
                //按参数名取值
                $paramValues[]=$this->getPropertyValue($constructorArgs[$name]);
            }else if(array_key_exists($i, $constructorArgs)){
                //按顺序取值
                $paramValues[]=$this->getPropertyValue($constructorArgs[$i]);
            }else if($isDefaultValueAvailable){
                $paramValues[]=$parameter->getDefaultValue();
            }else{
                throw new \Exception("Too few arguments to function ".$forClass."::__construct()");
            }
        }

        //创建实例
        $obj = $class->newInstanceArgs($paramValues);
        return $obj;
    }
561692
protected static function getObject($objectOrClass): object
    {
        self::assertParam($objectOrClass);

        if (\is_string($objectOrClass)) {
            try {
                $objectOrClass = new $objectOrClass();
            } catch (\Error $e) {
                try {
                    $class = new \ReflectionClass($objectOrClass);
                    $objectOrClass = $class->newInstanceWithoutConstructor();
                    // @codeCoverageIgnoreStart
                } catch (\ReflectionException $exception) {
                    throw new \RuntimeException(
                        '[' . typeOf($exception) . '] ' . $exception->getMessage(),
                        (int)$exception->getCode(),
                        $exception
                    );
                }
                // @codeCoverageIgnoreEnd
            }
        }
        return $objectOrClass;
    }
1218170
public static function getInstance(...$constructorParams)
    {
        $class = get_called_class();
        if (isset(static::$instanceOfClass[$class])) {
            return static::$instanceOfClass[$class];
        }
        static::$instanceOfClass[$class] = $nstnc = new static(...$constructorParams);
        return $nstnc;
    }
979416
private function injectConstructor(MethodInjection $constructorInject): array
    {
        $constructorParameters = [];

        /* @var ArgsInjection $parameter */
        foreach ($constructorInject->getParameters() as $parameter) {
            $argValue = $parameter->getValue();
            if (\is_array($argValue)) {
                $constructorParameters[] = $this->injectArrayArgs($argValue);
                continue;
            }
            if ($parameter->isRef()) {
                $constructorParameters[] = $this->get($parameter->getValue());
                continue;
            }
            $constructorParameters[] = $parameter->getValue();
        }

        return $constructorParameters;
    }
525562
public static <T> Constructor<T>[] candidateConstructors(Constructor<T>[] constructors, Class<?>[] argTypes) {
        return candidates(constructors, collectSignatures(constructors), collectVarArgs(constructors), argTypes);
    }
8870
@SuppressWarnings("unchecked")
    static <T> Class<T> forClass(final String clsName, final boolean cacheResult) throws IllegalArgumentException {
        Class<?> cls = clsNamePool.get(clsName);

        if (cls == null) {
            cls = BUILT_IN_TYPE.get(clsName);

            if (cls == null) {
                try {
                    cls = Class.forName(clsName);
                } catch (ClassNotFoundException e) {
                    String newClassName = clsName;

                    if (newClassName.indexOf(WD._PERIOD) < 0) {
                        int index = newClassName.indexOf("[]");

                        if (((index < 0) && !SYMBOL_OF_PRIMITIVE_ARRAY_CLASS_NAME.containsKey(newClassName))
                                || ((index > 0) && !SYMBOL_OF_PRIMITIVE_ARRAY_CLASS_NAME.containsKey(newClassName.substring(0, index)))) {
                            newClassName = "java.lang." + newClassName;

                            try {
                                cls = Class.forName(newClassName);

                                BUILT_IN_TYPE.put(clsName, cls);
                            } catch (ClassNotFoundException e1) {
                                // ignore.
                            }
                        }
                    }

                    if (cls == null) {
                        newClassName = clsName;
                        int index = newClassName.indexOf("[]");

                        if (index > 0) {
                            String componentTypeName = newClassName.substring(0, index);
                            String temp = newClassName.replaceAll("\\[\\]", "");

                            if (componentTypeName.equals(temp)) {
                                int dimensions = (newClassName.length() - temp.length()) / 2;
                                String prefixOfArray = "";

                                while (dimensions-- > 0) {
                                    prefixOfArray += "[";
                                }

                                String symbolOfPrimitiveArraryClassName = SYMBOL_OF_PRIMITIVE_ARRAY_CLASS_NAME.get(componentTypeName);

                                if (symbolOfPrimitiveArraryClassName != null) {
                                    try {
                                        cls = Class.forName(prefixOfArray + symbolOfPrimitiveArraryClassName);

                                        BUILT_IN_TYPE.put(clsName, cls);
                                    } catch (ClassNotFoundException e2) {
                                        // ignore.
                                    }
                                } else {
                                    try {
                                        final Type<?> componentType = N.typeOf(componentTypeName);

                                        if (componentType.clazz().equals(Object.class) && !componentType.name().equals(ObjectType.OBJECT)) {
                                            throw new IllegalArgumentException("No Class found by name: " + clsName);
                                        }

                                        cls = Class.forName(prefixOfArray + "L" + componentType.clazz().getCanonicalName() + ";");
                                    } catch (ClassNotFoundException e3) {
                                        // ignore.
                                    }
                                }
                            }
                        }

                        if (cls == null) {
                            newClassName = clsName;
                            int lastIndex = -1;

                            while ((lastIndex = newClassName.lastIndexOf(WD._PERIOD)) > 0) {
                                newClassName = newClassName.substring(0, lastIndex) + "$" + newClassName.substring(lastIndex + 1);

                                try {
                                    cls = Class.forName(newClassName);
                                    break;
                                } catch (ClassNotFoundException e3) {
                                    // ignore.
                                }
                            }
                        }
                    }
                }
            }

            if (cls == null) {
                throw new IllegalArgumentException("No class found by name: " + clsName);
            }

            if (cacheResult) {
                clsNamePool.put(clsName, cls);
            }
        }

        return (Class<T>) cls;
    }
1116283
public function getById(int $id, string $forClassName)
    {
        $params    = $this->getQueryParams();
        $type      = CorrelationTypeHelper::getGraphTypeByClass($forClassName);
        $uriAppend = "{$type}/{$id}";

        unset($params['limit'], $params['offset']);

        $response = $this->handler->handle('GET', false, $uriAppend, $params)->getData();
        if (!$response) {
            return [];
        }

        $functionalNames = [];
        if ($filter = $this->getFilter()) {
            $functionalNames = current($filter->getElements())['functionalNames'] ?? null;
        }

        return $this->client->elastic()
                            ->search($this->prepareElasticSearchBody($response, ['functionalNameId' => $functionalNames]))
                            ->all();
    }
1203014
public function makeFor(FqcnCollection $fqcnCollection, $classname)
    {
        $namespaceVisitor = new NamespaceVisitor($fqcnCollection);
        $forClassnameVisitor = new ForClassnameVisitor($fqcnCollection, $classname);
        $forParser = new Parser();
        $forParser->addVisitor($namespaceVisitor);
        $forParser->addVisitor($forClassnameVisitor);

        return $forParser;
    }
620170
public static function fromConstructs(array $constructs): self
    {
        $exception = new self(\sprintf(
            "Multiple definitions have been found for the following constructs:\n\n%s",
            \implode("\n", \array_map(static function (Construct $construct) {
                return \sprintf(
                    ' - "%s" defined in "%s"',
                    $construct->name(),
                    \implode('", "', $construct->fileNames())
                );
            }, $constructs))
        ));

        $exception->constructs = $constructs;

        return $exception;
    }
582486
public function buildForReply()
    {
        if (!method_exists($this, 'toReply')) {
            throw new \Exception(__CLASS__.'未实现此方法：toReply()');
        }

        $base = array(
                 'ToUserName'   => $this->to,
                 'FromUserName' => $this->from,
                 'CreateTime'   => time(),
                 'MsgType'      => $this->getDefaultMessageType(),
                );

        return XML::build(array_merge($base, $this->toReply()));
    }
1129722
private void initScriptClasses(Set<Class<?>> classes)throws Exception
	{
		ClassRegister classRegister=new ClassRegister();
		for (Class<?> clazz : classes) {
			onClassFind(clazz, classRegister);
		}
		Set<Class<? extends S>> scriptClass=findScriptClass(classes);
		Set<Class<? extends S>> instanceAbleScript = findInstanceAbleScript(scriptClass);
		for(Class<? extends S> clazz:instanceAbleScript)
		{
			onScriptClassFind(clazz, classRegister);//交给子类处理
		}
		ClassData cd=new ClassData();
		cd.intMap.putAll(classRegister.intMap);
		cd.stringMap.putAll(classRegister.stringMap);
		_log.info("loadScriptClass complete,id mapping size:"+cd.intMap.size()+",name mapping size:"+cd.stringMap.size());
		this.classData=cd;
	}
1374862
private <T> Constructor<T> findFromStringConstructorByType(Class<T> cls) {
        try {
            return cls.getDeclaredConstructor(String.class);
        } catch (NoSuchMethodException ex) {
            try {
                return cls.getDeclaredConstructor(CharSequence.class);
            } catch (NoSuchMethodException ex2) {
                throw new IllegalArgumentException("Constructor not found", ex2);
            }
        }
    }
1084051
public function setConstructor($constructor, $method = null, $params = null)
    {

        if (!is_null($method)){
            $constructor .= '::' . $method;
        }

        if (!is_null($params)) {
            $constructor .= ':' . $params;
        }

        $this->constructor = $constructor;
        return $this;
    }
727252
public function buildForStaff()
    {
        if (!method_exists($this, 'toStaff')) {
            throw new \Exception(__CLASS__.'未实现此方法：toStaff()');
        }

        $base = array(
                 'touser'  => $this->to,
                 'msgtype' => $this->getDefaultMessageType(),
                );
        if (!empty($this->staff)) {
            $base['customservice'] = array('kf_account' => $this->staff);
        }

        return array_merge($base, $this->toStaff());
    }
933060
public static function getListBy($conditions,$constructor=null)
	{
		$model = static::find()->filterBy($conditions);
		if( null === $constructor )
		{
			$constructor = array_keys($model->recordColumnsGet());
		}
		if( is_callable($constructor) )
		{
			$constructor($model);
		}
		else
		{
			arrayize($constructor);
			$model->setColumns($constructor);
		}
		return $model->load();
	}
257264
public function setInstance($classOrAlias,$object){
		$this->getClassLoaderService()->setInstance($classOrAlias,$object,$this->getNamespace());
	}
1304760
protected function constructObject(
        /*# string */ $class,
        array $constructorArguments
    ) {
        $invoke = false;
        $reflector = new \ReflectionClass($class);
        $constructor = $reflector->getConstructor();

        // dereference arguments
        $this->dereferenceArray($constructorArguments);

        // not constructor defined
        if (is_null($constructor)) {
            $instance = new $class();
            $invoke = true;

        // singleton
        } elseif (!$constructor->isPublic() &&
            method_exists($class, 'getInstance')) {
            $instance = $class::getInstance();
            $invoke = true;

        // normal class with constructor
        } else {
            $constructorArguments = $this->matchMethodArguments(
                $constructor->getParameters(),
                $constructorArguments
            );
            $instance = $reflector->newInstanceArgs($constructorArguments);
        }

        // __invoke() defined
        if ($invoke && count($constructorArguments) &&
            method_exists($class, '__invoke')) {
            $this->executeCallable(
                [$instance, '__invoke'],
                $constructorArguments
            );
        }

        return $instance;
    }