Resolve the binding

@param Container $container
@param array $args
@param callable|null $explicit
@return mixed|null
@throws \Exception
322529
public function resolve(Container $container, array $args = [], $explicit = null)
    {
        $definition = $this->definition;

        if (!is_null($explicit) && !empty($explicit)) {
            $definition = $explicit;
        }

        if (is_string($definition)) {
            // a string should be resolved once only, if more than one, it mean that the class behind the
            // string have also dependency on itself and may go on infinite loop
            $this->n++;
            if ($this->n > 1) {
                throw new InfiniteLoopResolutionException($definition);
            }
            $args = $this->classResolver->resolve($definition, $container, $args, $explicit);
            $instance = $this->instantiator->instantiate($definition, $args);
            // since it is a prototype, when we reach this line, it mean that prototype has been resolved properly,
            // so we decrease $n to allow other call to this prototype
            $this->n--;
            return $instance;
        } elseif (is_array($definition)) {
            return $this->arrayDefinition
                ->newInstancesOnly()
                ->resolve($definition, $container, $args);
        }

        throw new \Exception(__CLASS__.': Invalid definition for '.$this->name);
    }
565239
public function register(Container $container)
    {
        $container->share(get_class($this->package), $this->package)
            ->bindShared(AbstractPackage::class, get_class($this->package));

        $container->share('controller.resolver', function (Container $container) {
            return new ControllerResolver($this->package, $container);
        });

        $container->share('repository.resolver', function (Container $container) {
            return new RepositoryResolver($this->package, $container);
        })->alias('model.resolver', 'repository.resolver');

        $container->share('view.resolver', function (Container $container) {
            return new ViewResolver($this->package, $container);
        });

        $container->share('mvc.resolver', function (Container $container) {
            return new MvcResolver(
                $container->get('controller.resolver'),
                $container->get('repository.resolver'),
                $container->get('view.resolver')
            );
        });

        if ($this->package->app->isWeb()) {
            // Router
            $container->prepareSharedObject(PackageRouter::class)->alias('router', PackageRouter::class);
        }
    }
394329
public function resolve($value, array $args, $context, ResolveInfo $info)
    {
        $result = call_user_func_array(
            $this->connectionResolver,
            func_get_args()
        );

        if (!$result instanceof SS_List) {
            throw new \Exception('Connection::resolve() must resolve to a SS_List instance.');
        }

        return $this->resolveList($result, $args, $context, $info);
    }
986413
public function add($obj, $args = [])
    {
        if (isset($this->_factoryTrait)) {
            // Factory allows us to pass string-type objects
            $args1 = $args;
            if (is_array($args1)) {
                unset($args1['desired_name']);
                unset($args1[0]);
                $obj = $this->factory($obj, $args1);
            } else {
                $obj = $this->factory($obj);
            }
        }
        $obj = $this->_add_Container($obj, $args);

        if (isset($obj->_initializerTrait)) {
            if (!$obj->_initialized) {
                $obj->init();
            }
            if (!$obj->_initialized) {
                throw new Exception([
                    'You should call parent::init() when you override initializer',
                    'obj'=> $obj,
                ]);
            }
        }

        return $obj;
    }
862466
public function handleDependencies(DependencyContainerInterface $container): DependencyContainerInterface
    {
        $container = $this->addShellFacade($container);
        $container = $this->addCommandList($container);

        return $container;
    }
7941
private function resolveArguments(ContainerBuilder $container, array $arguments, $isRoot = false)
    {
        foreach ($arguments as $k => $argument) {
            if ($isRoot) {
                // yes, we are specifically fetching the definition from the
                // container to ensure we are not operating on stale data
                $arguments[$k] = $argument = $container->getDefinition($k);
                $this->currentId = $k;
            }
            if (is_array($argument)) {
                $arguments[$k] = $this->resolveArguments($container, $argument);
            } elseif ($argument instanceof Definition) {
                if ($argument instanceof DefinitionDecorator) {
                    $arguments[$k] = $argument = $this->resolveDefinition($container, $argument);
                    if ($isRoot) {
                        $container->setDefinition($k, $argument);
                    }
                }
                $argument->setArguments($this->resolveArguments($container, $argument->getArguments()));
                $argument->setMethodCalls($this->resolveArguments($container, $argument->getMethodCalls()));
                $argument->setProperties($this->resolveArguments($container, $argument->getProperties()));

                $configurator = $this->resolveArguments($container, array($argument->getConfigurator()));
                $argument->setConfigurator($configurator[0]);

                $factory = $this->resolveArguments($container, array($argument->getFactory()));
                $argument->setFactory($factory[0]);
            }
        }

        return $arguments;
    }
213449
private function resolveParameters(string $id, array $parameters, ContainerInterface $container): array
    {
        $resolved = [];
        foreach ($parameters as $parameter) {
            $resolved[] = $this->getParameterValue($id, $parameter, $container);
        }
        return $resolved;
    }
1206949
private function resolveDefinition(ContainerBuilder $container, DefinitionDecorator $definition)
    {
        try {
            return $this->doResolveDefinition($container, $definition);
        } catch (ExceptionInterface $e) {
            $r = new \ReflectionProperty($e, 'message');
            $r->setAccessible(true);
            $r->setValue($e, sprintf('Service "%s": %s', $this->currentId, $e->getMessage()));

            throw $e;
        }
    }
494236
protected function resolveArguments(
        ContainerInterface $container,
        \ReflectionMethod $method,
        array $parameters
    ) {
        try {
            //Getting set of arguments should be sent to requested method
            return $container->get(ResolverInterface::class)->resolveArguments(
                $method,
                $parameters
            );
        } catch (ArgumentException $e) {
            throw new ControllerException(
                "Missing/invalid parameter '{$e->getParameter()->name}'",
                ControllerException::BAD_ARGUMENT
            );
        } catch (ContainerExceptionInterface $e) {
            throw new ControllerException($e->getMessage(), ControllerException::ERROR, $e);
        }
    }
182688
public function getCallable(?ContainerInterface $container = null) : callable
    {
        $callable = $this->handler;

        if (is_string($callable) && strpos($callable, '::') !== false) {
            $callable = explode('::', $callable);
        }

        if (is_array($callable) && isset($callable[0]) && is_object($callable[0])) {
            $callable = [$callable[0], $callable[1]];
        }

        if (is_array($callable) && isset($callable[0]) && is_string($callable[0])) {
            $callable = [$this->resolveClass($container, $callable[0]), $callable[1]];
        }

        if (is_string($callable) && method_exists($callable, '__invoke')) {
            $callable = $this->resolveClass($container, $callable);
        }

        if (! is_callable($callable)) {
            throw new InvalidArgumentException('Could not resolve a callable for this route');
        }

        return $callable;
    }
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);
    }
1001449
public function process(ContainerBuilder $container)
    {
        $parameterBag = $container->getParameterBag();

        foreach ($container->getDefinitions() as $id => $definition) {
            try {
                $definition->setClass($parameterBag->resolveValue($definition->getClass()));
                $definition->setFile($parameterBag->resolveValue($definition->getFile()));
                $definition->setArguments($parameterBag->resolveValue($definition->getArguments()));

                $factory = $definition->getFactory();

                if (is_array($factory) && isset($factory[0])) {
                    $factory[0] = $parameterBag->resolveValue($factory[0]);
                    $definition->setFactory($factory);
                }

                $calls = array();
                foreach ($definition->getMethodCalls() as $name => $arguments) {
                    $calls[$parameterBag->resolveValue($name)] = $parameterBag->resolveValue($arguments);
                }
                $definition->setMethodCalls($calls);

                $definition->setProperties($parameterBag->resolveValue($definition->getProperties()));
            } catch (ParameterNotFoundException $e) {
                $e->setSourceId($id);

                throw $e;
            }
        }

        $aliases = array();
        foreach ($container->getAliases() as $name => $target) {
            $aliases[$parameterBag->resolveValue($name)] = $parameterBag->resolveValue($target);
        }
        $container->setAliases($aliases);

        $parameterBag->resolve();
    }
624699
public static function create(Container $container = null) : Application
    {
        if ($container !== null) {
            $valueResolver   = $container->getValueResolver();
            $injectionPolicy = $container->getInjectionPolicy();
        } else {
            $valueResolver   = new DefaultValueResolver();
            $injectionPolicy = new InjectionPolicy\NullPolicy();
        }

        return new Application($valueResolver, $injectionPolicy);
    }
951419
private function arrayHelperMethod( $fn, array $args )
    {

        $class = $this->classGet();
        $fnArguments = array( $this->collection );

        foreach( $args as $container ) {

            // validate the arguments
            if( !( $container instanceof $this ) ) {
                throw new \InvalidArgumentException("You can only `{$fn}` containers.");
            }
            $containerClass = $container->classGet();
            if( isset($class) and isset( $containerClass ) and ( $class !== $containerClass ) ) {
                throw new IncompatibleContainerException("Container -> `{$containerClass}` not compatible with `{$class}`");
            }

            $fnArguments[] = $container->collection;

        }

        $output = $this->newContainer(
            call_user_func_array(
                $fn,
                $fnArguments
            )
        );
        return $output;

    }
109784
public function resolve(ContainerInterface $container, $id, $definition)
    {
        $definition = substr($definition, 1);
        if ($container->has($definition)) {
            return $container->get($definition);
        }

        return false;
    }
405325
public function get(ContainerInterface $container = null)
    {
        if (empty($this->arguments)) {
            $instance = new $this->class();
        } else {
            $ref = new \ReflectionClass($this->class);
            $instance = $ref->newInstanceArgs($this->prepare($container, $this->arguments));
        }

        return $this->executeMethods($instance, $container);
    }
1185074
public function bindForCallback(string $abstract, $concrete, callable $callback)
    {
        $hasOriginal      = $this->container->bound($abstract);
        $originalInstance = false;

        if ($hasOriginal) {
            $binding = $this->container->getBindings()[$abstract] ?? null;

            $hasInstance = $binding && $binding['shared'] && $this->container->resolved($abstract);

            if ($hasInstance) {
                $originalInstance = $this->container->make($abstract);
            }
        }

        $this->container->instance($abstract, $concrete);

        try {
            $return = $callback();
            return $return;
        } finally {
            unset($this->container[$abstract]);

            if ($hasOriginal && (isset($binding) && $binding)) {
                $this->container->bind($abstract, $binding['concrete'], $binding['shared']);

                if ($originalInstance) {
                    $this->container->instance($abstract, $originalInstance);
                }
            }
        }
    }