Resolve class arguments dependencies

@param string $needle
@param Container $container
@param mixed $explicit
@return mixed|null
499054
public function resolve(string $needle, Container $container, $explicit = null)
    {
        // Check for explicit dependency closure or object instance
        if (is_array($explicit) && array_key_exists($needle, $explicit)) {
            if ($explicit[$needle] instanceof Closure) {
                return $explicit[$needle]($container);
            } elseif (is_object($explicit[$needle])) {
                return $explicit[$needle];
            }
        } elseif ($explicit instanceof Closure) {
            return $explicit($container, $needle);
        }
        return null;
    }
959907
function resolve($class, \Closure $__resolve_compatible = null)
    {
        return parent::resolve($class, function($class, $resource, $match) {
            if (false === $fileIncludeClass = \Poirot\Loader\funcWatchFileExists($class, $resource, $match, '.php'))
                return false;

            ## require file so class can be accessible (AutoLoading Goes Work)
            require_once $fileIncludeClass;
            return $fileIncludeClass;
        });
    }
754437
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $container = ContainerScope::getContainer();
        if (empty($container)) {
            throw new ScopeException("Unable to run SpiralCommand outside of IoC scope.");
        }

        $reflection = new \ReflectionMethod($this, 'perform');
        $reflection->setAccessible(true);

        /** @var ResolverInterface $resolver */
        $resolver = $container->get(ResolverInterface::class);

        try {
            list($this->input, $this->output) = [$input, $output];

            //Executing perform method with method injection
            return $reflection->invokeArgs($this, $resolver->resolveArguments(
                $reflection,
                compact('input', 'output')
            ));
        } finally {
            list($this->input, $this->output) = [null, null];
        }
    }
1301346
public function getDependencies(array $parameters)
    {
    	$dependencies = array();

        foreach ($parameters as $parameter) {

            try {

                $dependency = $parameter->getClass();

            } catch (ReflectionException $e) {

                throw new ResolveException('Target <' . $parameter . '> could not be found.', $e->getCode(), $e);

            }

            if (is_null($dependency)) {
                // It 's a string or the like
                $dependencies[] = $this->resolveArgument($parameter);

            } else {

                $dependencies[] = $this->resolveClass($parameter);

            }
        }

        return (array) $dependencies;
    }
993408
private function resolveParams($params, $args)
    {
        foreach ($params as $param) {
            $class = $param->getClass();

            // if the param is not a class, check $args for the value
            if (\is_null($class)) {
                $this->resolveParam($args, $param);
                continue;
            }

            $className = $class->getName();

            // if the class exists in the container, inject it
            if ($this->resolveFromContainer($className)) {
                continue;
            }

            if ($class->isInterface()) {
                throw new ConcreteClassNotFoundException("$className is an interface with no bound implementation.");
            }

            // else the param is a class, so run $this->resolve on it
            $this->addToStack($this->resolve($className, $args));
        }
    }
1357207
public function getDependency(string $index)
    {
        if (! isset($this->container[$index])) {
            throw $this->unbound($index);
        }
        $dependency = $this->container[$index];

        return $dependency->inject($this);
    }
877827
public function resolve(BindingInterface $binding, Container $container, $args = [], $explicit = null)
    {
        return $binding->resolve($container, $args, $explicit);
    }
952446
private Collection<DependencyInfo> createDependencyInfos(Collection<PhpPackage> phpPackages, Collection<DependencyInfo> dependencyInfos, Collection<String> directDependencies) {
        HashMap<DependencyInfo, Collection<String>> parentToChildMap = new HashMap<>();
        HashMap<String, DependencyInfo> packageDependencyMap = new HashMap<>();
        // collect packages data and create its dependencyInfo
        for (PhpPackage phpPackage : phpPackages) {
            DependencyInfo dependencyInfo = createDependencyInfo(phpPackage);
            if (dependencyInfo != null) {
                parentToChildMap.put(dependencyInfo, phpPackage.getPackageRequire().keySet());
                packageDependencyMap.put(phpPackage.getName(), dependencyInfo);
            } else {
                logger.debug("Didn't succeed to create dependencyInfo for {}", phpPackage.getName());
            }
        }
        if (!packageDependencyMap.isEmpty()) {
            for (String directDependency : directDependencies) {
                // create hierarchy tree
                DependencyInfo dependencyInfo = packageDependencyMap.get(directDependency);
                if (dependencyInfo != null) {
                    collectChildren(dependencyInfo, packageDependencyMap, parentToChildMap);
                    dependencyInfos.add(dependencyInfo);
                } else {
                    logger.debug("Didn't found {} in map {}", directDependency, packageDependencyMap.getClass().getName());
                }
            }
        } else {
            logger.debug("The map {} is empty ", packageDependencyMap.getClass().getName());
        }
        return dependencyInfos;
    }
1206994
public function execute($packageName, $textConstraint = '*', $onlyLocal = true)
    {
        // Find packages that are or provide the requested package first
        $pool = $this->getRequiredPool($packageName, $textConstraint, $onlyLocal);
        $packages = $pool->whatProvides($packageName);
        if (empty($packages)) {
            // sprintf('Could not find package "%s" in your project', $packageName),
            return null;
        }

        // Get the needle stack
        $needles = $this->getNeedles($packageName, $packages, $this->inverted);

        // Parse constraint if one was supplied
        $constraint = null;
        if ($textConstraint !== '*') {
            $versionParser = new VersionParser();
            $constraint = $versionParser->parseConstraints($textConstraint);
        }

        // Resolve dependencies
        /** @var InstalledFilesystemRepository $repository */
        $repository = $this->getComposer()->getRepositoryManager()->getLocalRepository();
        $results = $repository->getDependents($needles, $constraint, $this->inverted, $this->recursive);
        if (empty($results)) {
            // There is no installed package depending on $packageName
            return null;
        }

        // sprintf('The following packages are involved in the dependency on "%s"%s', $packageName, $extra),
        return $this->getDependencies($results);
    }
832837
protected Object resolveProviderConfig(String exp, Map<String, ? extends Object> contextMap, LaContainer container,
            Class<?> resultType) {
        if (exp.startsWith(PROVIDER_GET) && exp.endsWith(METHOD_MARK) && exp.contains(".") && !exp.contains("\"")) {
            final String[] tokens = exp.split("\\.");
            if (tokens.length > 1) {
                Object component = null;
                BeanDesc beanDesc = null;
                for (String prop : tokens) {
                    if (prop.endsWith(METHOD_MARK)) { // method
                        if (component == null) { // e.g. getJdbcUrl() only
                            break;
                        }
                        final String methodName = prop.substring(0, prop.length() - METHOD_MARK.length());
                        component = beanDesc.invoke(component, methodName, (Object[]) null);
                        beanDesc = BeanDescFactory.getBeanDesc(component.getClass());
                    } else { // component or property
                        if (beanDesc == null) { // first element
                            if (container.hasComponentDef(prop)) { // component
                                component = container.getComponent(prop);
                                beanDesc = BeanDescFactory.getBeanDesc(component.getClass());
                            } else {
                                break;
                            }
                        } else { // next elements, property
                            final PropertyDesc propertyDesc = beanDesc.getPropertyDesc(prop);
                            if (propertyDesc != null) {
                                component = propertyDesc.getValue(component);
                                beanDesc = BeanDescFactory.getBeanDesc(component.getClass());
                            } else {
                                break;
                            }
                        }
                    }
                }
                if (component != null) {
                    return component;
                }
            }
        }
        return null;
    }
305432
public function resolve(ContainerInterface $container, $id, $definition)
    {
        if (is_null($definition)) {
            $definition = $id;
        }

        $reflection = new ReflectionClass($definition);
        if (!$reflection->isInstantiable()) {
            return false;
        }

        $constructor = $reflection->getConstructor();
        if (is_null($constructor)) {
            return $reflection->newInstance();
        }

        $dependencies = [];
        foreach ($constructor->getParameters() as $parameter) {
            $class = $parameter->getClass();
            if (is_null($class)) {
                return false;
            }
            $dependencies[] = $container->get($class->getName());
        };

        return $reflection->newInstanceArgs($dependencies);
    }
823109
public static function fetchDependency(string $dependency)
    {
        $container = self::buildContainer();

        if ($container->has($dependency)) {
            return $container->get($dependency);
        }

        return null;
    }
418223
public static function getDependencies( array $parameters, array $primitives = [], $classAndMethod = null )
	{
		$dependencies = [];

		if ( !array_key_exists( 'fw', $primitives ) )
			$primitives['fw'] = Framework::fw();

		foreach ( $parameters as $parameter )
		{
			try
			{
				/*
				 * If the class is null, it means the dependency is a string or some other
				 * primitive type which we can not resolve since it is not a class and
				 * we will just bomb out with an error since we have no-where to go.
				 */
				if ( array_key_exists( $parameter->name, $primitives ) )
					$dependencies[] = $primitives[$parameter->name];
				else if ( is_null( $parameter->getClass() ) )
					$dependencies[] = static::resolve( $parameter->name );
				else
				{
					$depend = static::resolveClass( $parameter->getClass()->name );
					if ( is_null( $depend ) )
						throw new BindingException();
					if ( is_array( $depend ) )
					{
						if ( array_key_exists( $parameter->name, $depend ) )
							$depend = $depend[$parameter->name];
						else
							$depend = $depend[0];
					}
					$dependencies[] = $depend;
				}
			}
			catch ( BindingException $e )
			{
				/*
				 * If we can not resolve the class instance, we will check to see if the value
				 * is optional, and if it is we will return the optional parameter value as
				 * the value of the dependency, similarly to how we do this with scalars.
				 */
				if ( $parameter->isDefaultValueAvailable() )
					$dependencies[] = $parameter->getDefaultValue();
				else if ( $parameter->isOptional() )
					$dependencies[] = null;
				else
				{
					$parameterClass = $parameter->getClass()->name;
					foreach ( $primitives as $prim )
						if ( $prim instanceof $parameterClass )
						{
							$dependencies[] = $prim;
							continue;
						}

					$params = [];
					foreach ( $parameters as $param )
						$params[] = ( !is_null( $param->getClass() ) ? $param->getClass()->getName() . " " : "" ) . ( $param->isPassedByReference() ? "&" : "" ) . "$" . $param->getName() . ( $param->isDefaultValueAvailable() ? " = " . ( is_array( $param->getDefaultValue() ) ? "[" . implode( ', ', $param->getDefaultValue() ) . "]" : $param->getDefaultValue() ) : ( $param->isOptional() ? " = null" : "" ) );
					throw new BindingException( "Dependency injection failed for " . $parameter . " on " . $classAndMethod . "( " . implode( ', ', $params ) . " )" );
				}
			}
		}

		return $dependencies;
	}
908728
public function initDependencyContainer(Dependency\ContainerInterface $container = null)
    {
        if (null === $container) {
            $container = Dependency\Container::getInstance();
        }

        $this->dependencyContainer = $container;

        return $this;
    }
94992
public function get($dependencyClassname, $guaranteeNew = false)
    {
        if (!class_exists($dependencyClassname) && !($this->container->has($dependencyClassname) && !$guaranteeNew)) {
            throw new ClassDoesNotExistException($dependencyClassname);
        }

        $dependency = $this->getDependency($dependencyClassname, $guaranteeNew);
        $this->container->set($dependencyClassname, $dependency);
        return $dependency;
    }
602387
@Override
    public String execute(MavenWorkingSession session) {
        final String declaredVersion = dependency.getVersion();
        String resolvedVersion = declaredVersion;

        // is not able to infer anything, it was not configured
        if (Validate.isNullOrEmptyOrQuestionMark(resolvedVersion)) {

            // version is ignored here, so we have to iterate to get the dependency we are looking for
            if (session.getDependencyManagement().contains(dependency)) {

                // get the dependency from internal dependencyManagement
                MavenDependency resolved = null;
                Iterator<MavenDependency> it = session.getDependencyManagement().iterator();
                while (it.hasNext()) {
                    resolved = it.next();
                    if (resolved.equals(dependency)) {
                        break;
                    }
                }
                // we have resolved a version from dependency management
                resolvedVersion = resolved.getVersion();
                log.log(Level.FINE, "Resolved version {0} from the POM file for the artifact {1}", new Object[] {
                        resolved.getVersion(), dependency.toCanonicalForm() });

            }

        }

        // SHRINKRES-102 test-jar has special behavior
        if (Validate.isNullOrEmptyOrQuestionMark(resolvedVersion) && dependency.getPackaging().equals(PackagingType.JAR) && dependency.getClassifier().equals(PackagingType.TEST_JAR.getClassifier())) {
            MavenCoordinate coordinate = MavenCoordinates.createCoordinate(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), PackagingType.TEST_JAR, PackagingType.TEST_JAR.getClassifier());
            MavenDependency newDependency = new MavenDependencyImpl(coordinate, dependency.getScope(), dependency.isOptional(), dependency.getExclusions().toArray(new MavenDependencyExclusion[0]));

            // version is ignored here, so we have to iterate to get the dependency we are looking for
            if (session.getDependencyManagement().contains(newDependency)) {

                // get the dependency from internal dependencyManagement
                MavenDependency resolved = null;
                Iterator<MavenDependency> it = session.getDependencyManagement().iterator();
                while (it.hasNext()) {
                    resolved = it.next();
                    if (resolved.equals(newDependency)) {
                        break;
                    }
                }
                // we have resolved a version from dependency management
                resolvedVersion = resolved.getVersion();
                log.log(Level.FINE, "Resolved version {0} from the POM file for the artifact {1} via {2}", new Object[] {
                        resolved.getVersion(), dependency.toCanonicalForm() , newDependency.toCanonicalForm()});

            }
        }

        // Still unresolved?
        if (Validate.isNullOrEmptyOrQuestionMark(resolvedVersion)) {

            // log available version management
            if (log.isLoggable(Level.FINER)) {
                StringBuilder sb = new StringBuilder("Available version management: \n");
                for (final MavenDependency depmgmt : session.getDependencyManagement()) {
                    sb.append(depmgmt).append("\n");
                }
                log.log(Level.FINER, sb.toString());
            }

            throw new ResolutionException(
                    MessageFormat
                            .format(
                                    "Unable to get version for dependency specified by {0}, it was not provided in neither <dependencyManagement> nor <dependencies> sections.",
                                    dependency.toCanonicalForm()));
        }

        // Return
        return resolvedVersion;
    }
1141387
public static function ldMatch($collection, $needle, $tolerance = 7)
    {
        return WURFL_Handlers_Matcher_LDMatcher::INSTANCE()->match($collection, $needle, $tolerance);
    }