Resolve services, factories, callables by given token
@param string $name
@return mixed
17391
public function tokenResolve($name)
    {
        if(strpos($name, 'self.callable') === 0)
            $name = str_replace('self.callable.', 'callable.', $name);

        if(strpos($name, 'self.factory') === 0)
            $name = str_replace('self.factory.', 'factory.', $name);

        switch($name)
        {
            case 'self':
                return $this;
                break;
            default:
                $split = explode('.', $name, 2);

                if(isset($split[1]))
                {
                    switch($split[0])
                    {
                        case 'self':
                            return $this->{$split[1]};
                            break;
                        case 'service':
                            return $this->get($split[1]);
                            break;
                        case 'factory':
                            return $this->create($split[1]);
                            break;
                        case 'callable':
                            return $this->__call($split[1]);
                            break;
                        default:
                            return $this->{$arg};
                            break;
                    }
                }
                else
                {
                    return $this->get($name);
                }
                break;
        }
    }
754720
private function createServiceFromFactory(string $name, array $options = null)
    {
        $factory = $this->factories[$name] ?? null;

        if (is_string($factory) && class_exists($factory)) {
            $factory = new $factory();
            if ($factory instanceof FactoryInterface) {
                $this->factories[$name] = $factory;
                return $factory($this->creationContext, $name, $options);
            }
            throw InvalidArgumentException::fromInvalidFactory($factory);
        }

        if (is_callable($factory)) {
            return $factory($this->creationContext, $name, $options);
        } elseif (isset($this->invokables[$name])) {
            $invokable = $this->invokables[$name];
            return $options === null ? new $invokable() : new $invokable($options);
        }

        foreach ($this->abstractFactories as $idx => $abstractFactory) {
            if ($abstractFactory->canCreate($this->creationContext, $name)) {
                return $abstractFactory($this->creationContext, $name, $options);
            }
        }

        throw ServiceNotFoundException::fromUnknownService($name);
    }
764497
private function factory($name)
    {
        $factory = FabricateFactory::create(self::getInstance()->registry->find($name));
        $factory->setConfig(self::getInstance()->config);
        return $factory;
    }
678469
protected function makeService($name)
    {
        $config = $this->getConfig($name);

        // First we will check by the service name to see if an extension has been
        // registered specifically for that service. If it has we will call the
        // Closure and pass it the config allowing it to resolve the service.
        if (isset($this->extensions[$name])) {
            return call_user_func($this->extensions[$name], $config, $name);
        }

        $config = $this->getDbConfig($name);
        $type = $config['type'];

        // Next we will check to see if a type extension has been registered for a service type
        // and will call the factory Closure if so, which allows us to have a more generic
        // resolver for the service types themselves which applies to all services.
        if (isset($this->types[$type])) {
            return $this->types[$type]->make($name, $config);
        }

        throw new InvalidArgumentException("Unsupported service type '$type'.");
    }
242605
public function resolveMiddlewareClassName( $name )
	{
		$map = $this->middleware;

		// If the middleware is the name of a middleware group, we will return the array
		// of middlewares that belong to the group. This allows developers to group a
		// set of middleware under single keys that can be conveniently referenced.
		if ( isset( $this->middlewareGroups[$name] ) )
		{
			return $this->parseMiddlewareGroup( $name );
			// When the middleware is simply a Closure, we will return this Closure instance
			// directly so that Closures can be registered as middleware inline, which is
			// convenient on occasions when the developers are experimenting with them.
		}
		elseif ( isset( $map[$name] ) && $map[$name] instanceof Closure )
		{
			return $map[$name];
			// Finally, when the middleware is simply a string mapped to a class name the
			// middleware name will get parsed into the full class name and parameters
			// which may be run using the Pipeline which accepts this string format.
		}
		else
		{
			list( $name, $parameters ) = array_pad( explode( ':', $name, 2 ), 2, null );

			return ( isset( $map[$name] ) ? $map[$name] : $name ) . ( $parameters !== null ? ':' . $parameters : '' );
		}
	}
1046125
public function findServiceByName($name)
    {
        foreach ($this->services as $service) {
            if ($service->getName() === $name) {
                return $service;
            }
        }

        throw new \OutOfBoundsException(sprintf('There is no service named %s', $name));
    }
1288743
public function resolve($name)
    {
        try {
            return parent::resolve($name);
        } catch (\DomainException $e) {
            if (substr($name, -10) === 'Repository') {
                $name = substr($name, 0, -10);
                $name .= 'Model';

                try {
                    return parent::resolve($name);
                } catch (\DomainException $ex) {
                    throw new \DomainException($e->getMessage(), $e->getCode(), $e);
                }
            } elseif (substr($name, -5) === 'Model') {
                $name = substr($name, 0, -5);
                $name .= 'Repository';

                try {
                    return parent::resolve($name);
                } catch (\DomainException $ex) {
                    throw new \DomainException($e->getMessage(), $e->getCode(), $e);
                }
            }
        }
    }
893541
protected function resolve( $name )
	{
		$config = $this->getConfig( $name );

		if ( is_null( $config ) )
			throw new InvalidArgumentException( "Password resetter [{$name}] is not defined." );

		// The password broker uses a token repository to validate tokens and send user
		// password e-mails, as well as validating that password reset process as an
		// aggregate service of sorts providing a convenient interface for resets.
		return new PasswordBroker( $this->createTokenRepository( $config ), AccountManager::i()->resolveAuth( $config['provider'] ), Mailer::i(), $config['email'] );
	}
192829
public function factory($name)
    {
        if (isset($this->factories[$name])) {
            return $this->factories[$name];
        }

        if (class_exists($class = $this->inflect($name))) {
            return $this->factories[$name] = new $class();
        }

        throw new InvalidArgumentException("Unsupported factory [$name].");
    }
818937
public function get($name)
    {
        if(array_key_exists($name, $this->services))
            return $this->services[$name];

        return $this->services[$name] = $this->solve('service', $name, array($this));
    }
799631
protected static function resolveFacadeInstance($name)
    {
        if (is_object($name)) {
            return $name;
        }

        if (isset(static::$resolvedInstance[$name])) {
            return static::$resolvedInstance[$name];
        }

        return static::$resolvedInstance[$name] = static::$app->getContainer()->get($name);
    }
242684
private function resolveFilter($name)
    {
        $info = $this->unresolvedFilters[$name];
        $child = $this->createFilter($name, $info['type'], $info['options']);
        $this->filters[$name] = $child;
        unset($this->unresolvedFilters[$name]);

        return $child;
    }
268275
protected function get($name)
    {
        return isset($this->sources[$name]) ? $this->sources[$name] : $this->resolve($name);
    }
1289985
public function resolveCallableFromCache(string $name, callable $closure)
    {
        if($this->cache->has(self::CACHE_CALLABLE . $name)) {
            return $this->cache->get(self::CACHE_CALLABLE . $name);
        }

        $resolved = $this->resolveCallable($name, $closure);

        //cache closure
        $this->store(self::CACHE_CALLABLE . $name, $resolved);

        return $resolved;
    }
942082
public function resolveCallable(?string $name, callable $closure, ?array $parameters = null)
    {
        $definitions = isset($name) && $this->container->isDefined($name)
            ? $this->container->getDefiniition($name) : null;

        $callable = $this->getCallable($closure);
        $parameters = $parameters ?? $this->resolveParameters($callable->getParameters() ?? null, $definitions);

        return $callable->invokeArgs($parameters);
    }
432485
protected function get($name)
    {
        return isset($this->repositories[$name]) ? $this->repositories[$name] : $this->resolve($name);
    }
647162
public function get($name)
    {
        if (!isset($this->indexed[$name])) {
            return null;
        }
        if (empty($this->indexed[$name])) {
            $this->indexed[$name] = $this->factory->target($name);
        }
        return $this->indexed[$name];
    }