获取构造函数参数

@param MethodInjection $constructorInject

@return array
@throws \InvalidArgumentException
@throws \ReflectionException
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;
    }
307574
private static Object injectAndPostConstruct(Object injectionProvider, Class Klass, List injectedBeanStorage)
    {
        Object instance = null;
        if (injectionProvider != null)
        {
            try
            {

                Object managedObject = _FactoryFinderProviderFactory.INJECTION_PROVIDER_INJECT_CLASS_METHOD.invoke(injectionProvider, Klass);

                instance = _FactoryFinderProviderFactory.MANAGED_OBJECT_GET_OBJECT_METHOD.invoke(managedObject, null);

                if (instance != null) {

                    Object creationMetaData = _FactoryFinderProviderFactory.MANAGED_OBJECT_GET_CONTEXT_DATA_METHOD.invoke
                                    (managedObject, CreationalContext.class);

                    addBeanEntry(instance, creationMetaData, injectedBeanStorage);

                    _FactoryFinderProviderFactory.INJECTION_PROVIDER_POST_CONSTRUCT_METHOD.invoke(
                                                                                                  injectionProvider, instance, creationMetaData);
                }
            } catch (Exception ex)
            {
                throw new FacesException(ex);
            }
        }
        return instance;
    }
498681
private function invokeObjectMethod($object, $method, $namedParams, $classParams)
    {
        if (!method_exists($object, $method)) {
            $class = get_class($object);
            throw new \InvalidArgumentException("Method $class::$method does not exist.");
        }

        $reflection = new \ReflectionMethod($object, $method);
        $params = $reflection->getParameters();

        $invokeParams = $this->mapParameters($params, $namedParams, $classParams);

        return call_user_func_array([$object, $method], $invokeParams);
    }
28876
private function fromClassMethodArray($handler)
    {
        if (count($handler) != 2) {
            throw new \InvalidArgumentException('Class method array constructor can only contain 2 elements.');
        }
        $this->class = $handler[0];
        $this->method = $handler[1];
    }
918097
private function resolveConstructorArguments(ReflectionMethod $constructor, array $arguments)
    {
        $constructorParameters = $constructor->getParameters();

        foreach ($constructorParameters as $position => $parameter) {
            if ($parameter->getClass() && ServiceMocker::class === $parameter->getClass()->getName()) {
                $arguments[$position] = $this->serviceMocker;
            }
        }

        return $arguments;
    }
671772
private function parseMethods(array $methodAnnotations, string $className, array $publicMethods)
    {
        // 循环解析
        foreach ($publicMethods as $method) {
            /* @var \ReflectionMethod $method*/
            if ($method->isStatic()) {
                continue;
            }

            /* @var \ReflectionClass $declaredClass*/
            $declaredClass = $method->getDeclaringClass();
            $declaredName = $declaredClass->getName();

            // 不是当前类方法
            if ($declaredName != $className) {
                continue;
            }
            $this->parseMethodAnnotations($className, $method, $methodAnnotations);
        }
    }
1032200
private function newBeanInstance(\ReflectionClass $reflectionClass, array $constructorParameters)
    {
        if ($reflectionClass->hasMethod('__construct')) {
            return $reflectionClass->newInstanceArgs($constructorParameters);
        }

        return $reflectionClass->newInstance();
    }
488703
public static function collect(string $className, $objectAnnotation = null, string $propertyName = '', string $methodName = '', $propertyValue = null)
    {
        if ($objectAnnotation instanceof Reference) {
            // phpdoc解析
            $phpReader     = new PhpDocReader();
            $property      = new \ReflectionProperty($className, $propertyName);
            $propertyClass = $phpReader->getPropertyClass($property);
            $name          = $objectAnnotation->getName();
            $pool          = $objectAnnotation->getPool();
            $version       = $objectAnnotation->getVersion();
            $breaker       = $objectAnnotation->getBreaker();
            $packer        = $objectAnnotation->getPacker();
            $fallback      = $objectAnnotation->getFallback();

            $className      = sprintf("%s.%s.%s.%s.%s.%s", $name, $propertyClass, $version, $pool, $breaker, $packer);
            $className      = md5($className);
            $proxyClassName = str_replace("\\", '_', $propertyClass);
            $className      = $proxyClassName . '_' . $className;

            if (empty($name)) {
                throw new RpcClientException('@Reference must be define name! ');
            }
            if (isset(self::$references[$className])) {
                return $className;
            }

            self::$references[$className] = [
                $name,
                $propertyClass,
                $version,
                $pool,
                $breaker,
                $packer,
                $fallback
            ];

            return $className;
        }

        return null;
    }
79150
public function createArray($object)
    {
        if (!is_object($object)) {
            throw new \InvalidArgumentException('The first param should be a object.');
        }

        $array = [];
        if ($object instanceof Object2ArrayInterface) {
            $array = $object->__toArray();
            array_walk_recursive(
                $array,
                function (&$item) {
                    if (is_object($item)) {
                        $item = $this->createArray($item);
                    }
                }
            );
        } else {
            foreach (Utils::getClassProperties(get_class($object)) as $property) {
                if ($this->context->getReader()->isReadable($object, $property->getName())) {
                    $value = $this->context->getReader()->getValue($object, $property->getName());
                    $types = $types = Utils::getPropertyTypes($property);
                    $value = $this->parseValue($value, $types, $property, $object);

                    if ($value === null && $this->context->isIgnoreNulls()) {
                        continue;
                    }

                    $transformedName = $this->context->getNamingStrategy()->transformName($property->getName());
                    $array[$transformedName] = $value;
                }
            }
        }

        return $array;
    }
229705
private function computeArguments(
        \ReflectionMethod $constructor,
        MapInterface $properties
    ): MapInterface {
        $arguments = $properties->clear();

        foreach ($constructor->getParameters() as $parameter) {
            if ($this->canInject($parameter, $properties)) {
                $arguments = $arguments->put(
                    $parameter->name,
                    $properties->get($parameter->name)
                );
            }
        }

        return $arguments;
    }
715185
public function injectIntoMethod( $object, $methodName = "injectDependencies" ){
        $ref = new \ReflectionClass($object);
        try{
            $refMethod = $ref->getMethod( $methodName );
        }catch( ReflectionException  $e ){
            return null;
        }
        
        $toInject = [];
        foreach ($refMethod->getParameters() as $p) {
            $className = $p->getClass()->name;
            if( $className === "Pimple\\Container" ){
                $toInject[] = $this->container;
            }else{
                $toInject[] = $this->container[ $className ];
            }
        }
        return $refMethod->invoke( $object, ... $toInject );
    }
1289338
private function resolverConstructor(array $args)
    {
        $methodArgs = [];
        foreach ($args as $arg) {
            // 数组参数解析
            if (is_array($arg)) {
                $injectProperty = $this->resolverArrayArgs($arg);
                $methodArgs[] = new ArgsInjection($injectProperty, false);
                continue;
            }

            // 普通参数解析
            list($injectProperty, $isRef) = $this->getTransferProperty($arg);
            $methodArgs[] = new ArgsInjection($injectProperty, (bool)$isRef);
        }

        $methodInject = new MethodInjection("__construct", $methodArgs);
        return $methodInject;
    }
577046
private function getParametersDefinition(\ReflectionFunctionAbstract $constructor)
    {
        $parameters = [];

        foreach ($constructor->getParameters() as $index => $parameter) {
            // Skip optional parameters
            if ($parameter->isOptional()) {
                continue;
            }

            $parameterClass = $parameter->getClass();

            if ($parameterClass) {
                $parameters[$index] = new EntryReference($parameterClass->getName());
            }
        }

        return $parameters;
    }
266008
public function parser(string $className, $objectAnnotation = null, string $propertyName = "", string $methodName = "", $propertyValue = null)
    {
        $injectValue = $objectAnnotation->getName();
        if (!empty($injectValue)) {
            return [$injectValue, true];
        }

        // phpdoc解析
        $phpReader = new PhpDocReader();
        $property = new \ReflectionProperty($className, $propertyName);
        $propertyClass = $phpReader->getPropertyClass($property);

        $isRef = true;
        $injectProperty = $propertyClass;
        return [$injectProperty, $isRef];
    }
587778
public function getDefinition($instanceOrClass)
    {
        if ($instanceOrClass instanceof BaseElement) {
            $instanceOrClass = get_class($instanceOrClass);
        }

        if (!is_string($instanceOrClass)) {
            throw new InvalidArgumentException(sprintf(
                'Given argument to %s is not an instance of a class extending %s and is not a string',
                __METHOD__,
                BaseElement::class
            ));
        }

        $definitions = $this->getDefinitions();

        if (!isset($definitions[$instanceOrClass])) {
            throw new InvalidArgumentException(sprintf('Unknown element "%s"', $instanceOrClass));
        }

        return $definitions[$instanceOrClass];
    }
581012
public function fetchAllObject(string $className = 'stdClass', array $constructorArgs = []):  ? array
    {
        $r = $this->DriverStatement->fetchAll(PDO::FETCH_CLASS, $className, $constructorArgs);
        return $r ?: null;
    }
53393
public function get($key, $config = [])
    {
    	$key= $this->resolveAlias($key);
    	
        if (isset($this->_singletons[$key])) {  // singleton
            return $this->_singletons[$key];
        } elseif (!isset($this->_definitions[$key])) {  // not set, try build, key tread as className 
            $tryDef = static::formatDefinition($key, $config);
            if (!isset($tryDef['class']) || !class_exists($tryDef['class'])) {
                return null;
            }
            $key = $tryDef['class'];
            return $this->build($key, $config);
        }
        
        $definition = $this->_definitions[$key];
        
        if (is_callable($definition, true)) {// not strict callable, true 参数会使用 'className:method' 也是 callable
            if (!is_callable($definition, false) && is_string($definition)) {
                $definition = $this->resolveCallable($definition); 
            }
            // callable: function($container, $config)
            $object = call_user_func($definition, $this, $config); 
        } elseif (is_array($definition)) {
            $concrete = $definition['class'];
            unset($definition['class']);
			
            if ($config) {
                $definition = array_merge($definition, $config);
            }
            
            $object = $this->build($concrete, $definition);
        } elseif (is_object($definition)) {
            return $this->_singletons[$key] = $definition;
        } else {
            throw new InvalidConfigException("Unexpected object definition type: " . gettype($definition));
        }
		
        // 判断是否存在 _singletons 的 key，不能使用 isset()
        if (array_key_exists($key, $this->_singletons)) {
            // singleton
            $this->_singletons[$key] = $object;
            // set alias
            $this->alias('\\' . get_class($object), $key);
        }

        return $object;
    }