singleton instance
@param String $name
@param array $config
@param Container $repository
@param Repository $cache
@return Self
9799
public static function getInstance($name, array $config, Container $repository, Repository $cache)
    {
        if (self::$oInstance == false) {
            self::$oInstance = new Registry($name, $config, $repository, $cache);
        }
        return self::$oInstance;
    }
1114058
public static function fromConfig(Config $config)
    {
        $message = sprintf(
            'Could not instantiate OptionRepository from Config with starting key "%1$s".',
            empty($config->getKeys())
                ? '<none>'
                : $config->getKeys()[0]
        );

        return new static($message);
    }
257518
public function singleton($name, $object)
    {
        if (IOC::hasSingleton($name)) {
            return IOC::singleton($name);
        } else {
            IOC::singleton($name, $object);
            return $object;
        }
    }
433254
private function createSearchRepository(
        ContainerBuilder $container,
        string $name,
        array $repositoryConfiguration,
        string $indexName
    ) {
        $repositoryName = "apisearch.repository_$name.$indexName";
        $repositoryTransformableName = "apisearch.repository_transformable_$name.$indexName";
        $clientName = "apisearch.client_$name";

        switch ($repositoryConfiguration['adapter']) {
            case 'in_memory':
                $repositoryDefinition = $container
                    ->register($repositoryName, InMemoryRepository::class)
                    ->setPublic($this->repositoryIsTest($repositoryConfiguration));
                break;

            case 'disk':
                $repositoryDefinition = $container
                    ->register($repositoryName, DiskRepository::class)
                    ->addArgument($repositoryConfiguration['disk_file'].'.'.$name)
                    ->setPublic($this->repositoryIsTest($repositoryConfiguration));
                break;

            case 'http':
            case 'http_test':
                $repositoryDefinition = $container
                    ->register($repositoryName, HttpRepository::class)
                    ->addArgument(new Reference($clientName))
                    ->setPublic($this->repositoryIsTest($repositoryConfiguration));
                break;

            case 'service':
                $container->setAlias($repositoryName, $repositoryConfiguration['search']['repository_service']);
                $aliasDefinition = $container->getAlias($repositoryName);
                $aliasDefinition->setPublic($this->repositoryIsTest($repositoryConfiguration));
                $repositoryDefinition = $container->getDefinition($repositoryConfiguration['search']['repository_service']);
                break;
        }

        $this->injectRepositoryCredentials(
            $repositoryDefinition,
            $name,
            $repositoryConfiguration,
            $indexName
        );

        $definition = $container
            ->register($repositoryTransformableName, TransformableRepository::class)
            ->setDecoratedService($repositoryName)
            ->addArgument(new Reference($repositoryTransformableName.'.inner'))
            ->addArgument(new Reference('apisearch.transformer'))
            ->setPublic($this->repositoryIsTest($repositoryConfiguration));

        $this->injectRepositoryCredentials(
            $definition,
            $name,
            $repositoryConfiguration,
            $indexName
        );

        $container
            ->getDefinition('apisearch.repository_bucket')
            ->addMethodCall(
                'addRepository',
                [$name, $indexName, new Reference($repositoryName)]
            )
            ->setPublic($this->repositoryIsTest($repositoryConfiguration));
    }
379685
protected function createFluentDriver(string $name): ProviderContract
    {
        $config = $this->config['fluent'][$name] ?? [];
        $cache = $this->getCacheRepository($config);

        return $this->createProvider(new Fluent($name, $config, $this->app->make('db'), $cache));
    }
892748
public static function instance(array $config = array())
    {
        if (!(self::$instance instanceof Phery)) {
            self::$instance = new Phery($config);
        } else if ($config) {
            self::$instance->config($config);
        }

        return self::$instance;
    }
1265990
public function delete_store_instance($name) {
        if (!array_key_exists($name, $this->configstores)) {
            throw new cache_exception('The requested store does not exist.');
        }
        if ($this->configstores[$name]['default']) {
            throw new cache_exception('The can not delete the default stores.');
        }
        foreach ($this->configmodemappings as $mapping) {
            if ($mapping['store'] === $name) {
                throw new cache_exception('You cannot delete a cache store that has mode mappings.');
            }
        }
        foreach ($this->configdefinitionmappings as $mapping) {
            if ($mapping['store'] === $name) {
                throw new cache_exception('You cannot delete a cache store that has definition mappings.');
            }
        }

        // Call instance_deleted()
        $class = 'cachestore_'.$this->configstores[$name]['plugin'];
        $store = new $class($name, $this->configstores[$name]['configuration']);
        $store->instance_deleted();

        unset($this->configstores[$name]);
        $this->config_save();
        return true;
    }
1287332
public function connect($config = [], $name = false)
    {
        $this->connection = Connection::instance($config, $name);
        $query            = $this->connection->getConfig('query');

        if (__CLASS__ != trim($query, '\\')) {
            return new $query($this->connection);
        }

        $this->prefix = $this->connection->getConfig('prefix');

        return $this;
    }
184658
protected function instantiateCache(Cache $cache = null)
    {
        if (is_null($this->cache) || ! is_null($cache)) {
            $this->cache = ! is_null($cache)
                ? $cache
                : new Cache($this->config);
        }

        return $this->cache;
    }
959076
public static function newInstance($name, $data = null)
  {
    if (!is_array($data)) {
      $data = array();
    }

    $config = self::getInstance($name);
    $config->_data = $data;

    return $config;
  }
658270
private function createCache(array $config, ContainerBuilder $container)
    {
        $type = $config['type'];
        if (array_key_exists($type, $this->cacheFactories)) {
            $id = sprintf('tbbc_cache.%s_cache', $config['name']);
            $this->cacheFactories[$type]->create($container, $id, $config);

            return $id;
        }

        // TODO: throw exception ?
    }
484054
public static function instance($config_name)
    {
        if (empty(self::$instance[$config_name])) {
            $config = self::$config[$config_name];
            self::$instance[$config_name] = new \Beanbun\Lib\DbConnection($config);
        }
        return self::$instance[$config_name];
    }
1236044
public static function initialize($namespace, $config, $cache)
    {
        $context = new self($namespace);
        $context->cache = $cache;
        $context->config = $config;
        $context->prefix = $config->get('app.prefix', null);
        $context->parameters = Parameters::wrap([]);
        self::$instance = $context;
        return $context;
    }
921424
public static function make(array $config = [], $name = '')
    {
        if (!\is_array($config)) {
            throw new \InvalidArgumentException('Logger config is must be an array and not allow empty.');
        }

        $name = $name ?: ($config['name'] ?? '');

        if (!$name) {
            throw new \InvalidArgumentException('Logger name is required.');
        }

        if (!isset(self::$loggers[$name])) {
            self::$loggers[$name] = new static($config, $name);
        }

        // register shutdown function
        if (!self::$shutdownRegistered) {
            register_shutdown_function(function () {
                // make regular flush before other shutdown functions, which allows session data collection and so on
                self::flushAll();

                // make sure log entries written by shutdown functions are also flushed
                // ensure "flush()" is called last when there are multiple shutdown functions
                register_shutdown_function([self::class, 'flushAll'], true);
            });

            self::$shutdownRegistered = true;
        }

        return self::$loggers[$name];
    }
182739
private function instanceCache($name)
    {
        self::$cache = new $name();
        self::$cache->connect($this->getConfig());
    }
409326
protected function registerAssetsManagerInstance($name, array $config)
	{
		$this->app->singleton("stolz.assets.group.$name", function ($app) use ($config) {

			if( ! isset($config['public_dir']))
				$config['public_dir'] = public_path();

			return new Assets($config);
		});
	}
848571
private static function instance($con_name, $config = [])
    {
        if (!isset(self::$instance[$con_name])) {
            self::$instance[$con_name] = Db::connect($config, $con_name);
        }
        return self::$instance[$con_name];
    }