Create a config based off running inside a cluster

@return Config
14111
public static function InClusterConfig()
    {
        $config = new Config();
        $config->setToken(file_get_contents('/var/run/secrets/kubernetes.io/serviceaccount/token'));
        $config->setCertificateAuthorityPath('/var/run/secrets/kubernetes.io/serviceaccount/ca.crt');
        $config->setServer('https://kubernetes.default.svc');

        return $config;
    }
1350329
public static function fromConfig()
	{
		$mailer = self::getInstance();

		$services = Config::get ('mailer.services');

		if (!$services) {
			return $mailer;
		}

		foreach ($services as $k => $v) {
			$service = MapperFactory::getServiceMapper()->getFromToken($k);
			if ($service) {
				$service->setFromConfig ($v);
				$mailer->addService ($service);
			}
		}

		return $mailer;
	}
897743
private function createNewConfig() : Config
    {
        $globalPath = $this->globalPath ?: getenv('HOME');
        $tokenFile  = sprintf('%s/.keep-a-changelog/token', $globalPath);
        $token = is_readable($tokenFile)
            ? trim(file_get_contents($tokenFile))
            : '';
        return new Config($token);
    }
421025
protected static function create()
    {
        $config = new static();

        $config->config = (new ConfigFactory())->create($config->getProjectPath(), $config->CONFIG_FILE);

        return $config;
    }
1351402
protected function initialiseConfiguration()
    {
        $configuration = $this->registerConfiguration($this->environment);

        if ( ! is_array($configuration)) {
            throw new \RuntimeException(sprintf(
                'The configuration must be a valid array (%s given).',
                $this->varToString($configuration)
            ));
        }

        return $this->configuration = new Configuration($configuration);
    }
714283
protected function initConfig() {
		$config = Xml::read($this->file);

		if ($config->getName() !== 'container') {
			throw new InvalidConfig('Root element of a config must be a "container"', null, null, $config);
		}

		$this->override = ($config->override === 'true');
		
		$this->includes     = [];
		$this->parameters   = new stdClass();
		$this->services     = new stdClass();
		$this->initializers = new stdClass();
		
		foreach ($config->getContent() as $element) {
			$name = $element->getName();
			
			if ($name === 'includes') {
				$this->includes = array_merge($this->includes, $this->processIncludes($element));
				continue;
			}
			
			if ($name === 'parameters') {
				$this->parameters = Std::objectMerge($this->parameters, $this->processParameters($element));
				continue;
			}
			
			if ($name === 'services') {
				$this->services = Std::objectMerge($this->services, $this->processServices($element));
				continue;
			}
			
			if ($name === 'initializers') {
				$this->initializers = Std::objectMerge($this->initializers, $this->processInitializers($element));
				continue;
			}
			
			throw new InvalidConfig('Unknown element "' . $element->getName() . '" in container', null, null, $element->getName());
		}
	}
54279
protected function buildManager()
    {
        $config = new Configuration;

        $this->setUpGeneralConfigurations($config);
        $this->setUpSpecificConfigurations($config);

        $eventManager = $this->getEventManager();
        if ($this->getEventSubscribers() !== null) {
            /* @var array $eventSubscribers */
            $eventSubscribers = $this->getEventSubscribers();

            foreach ($eventSubscribers as $eventSubscriber) {
                $eventManager->addEventSubscriber($eventSubscriber);
            }
        }

        return DocumentManager::create($this->getConnection($config), $config, $eventManager);
    }
829810
public function getConfig()
    {
        if ($this->cache instanceof Cache\CacheInterface && !empty($configs = $this->cache->getConfig())) {
            return $configs;
        }

        $configs = $this->moduleHandler->getModulesConfig();
        foreach ($this->files as $file) {
            $config = require $file;
            if (!is_array($config)) {
                throw new Exception\RuntimeException(sprintf('The config in "%s" file must be array data type', $file));
            }
            $configs = ArrayUtils::merge($configs, require $file);
        }

        return $this->cleanUp($configs);
    }
676030
public static function newInstance()
    {
        $config = self::create();

        $config->username = 'null';
        $config->password = 'null';
        $config->credentials = ['null', 'null'];
        $config->bindtoInterface = 'null';
        $config->timeout = 5;

        return $config;
    }
351977
protected function createMemcacheDriver()
    {
        $serverArray    = $this->config['servers'];
        $persistent     = boolval($this->config['persistent']);
        $name           = trim($this->config['server_name']);
        $prefix         = trim($this->config['prefix']);
        $expireTime     = intval($this->config['lifetime']);

        if ($persistent && (strlen($name) > 0)) {
            $memcached  = new Memcached($name);
        } else {
            $memcached  = new Memcached();
        }

        if (!sizeof($memcached->getServerList())) {
            $memcached->addServers($serverArray);
        }

        $store = new MemcachedStore($memcached, $prefix);
        return new CacheSessionHandler($store, $expireTime);
    }
656648
public static function initKernel()
    {
        $configFiles = self::getConfigFiles();

        $fs = new Filesystem();

        if(!$fs->exists($configFiles['bundles'])){
            $fs->copy($configFiles['bundles_dist'], $configFiles['bundles'], true);
        }
        if(!$fs->exists($configFiles['config'])){
            $fs->copy($configFiles['config_dist'], $configFiles['config'], true);
        }
        if(!$fs->exists($configFiles['routing'])){
            $fs->copy($configFiles['routing_dist'], $configFiles['routing'], true);
        }
        if(!$fs->exists($configFiles['security'])){
            $fs->copy($configFiles['security_dist'], $configFiles['security'], true);
        }
    }
718451
public function create()
    {

        $callback = $this->callback;

        if (is_callback_function($callback)) {
            $callback($this);
        }

        $params = [

            'index' => $this->name,

            'body' => [
                "settings" => [
                    'number_of_shards' => $this->shards,
                    'number_of_replicas' => $this->replicas
                ]
            ],

            'client' => [
                'ignore' => $this->ignores
            ]
        ];

        if (count($this->mappings)) {
            $params["body"]["mappings"] = $this->mappings;
        }

        return $this->connection->indices()->create($params);
    }
1139772
public static Config loadClusterConfig() {
    Config defaultConfig = loadDefaults(
        Key.HERON_CLUSTER_HOME.getDefaultString(), Key.HERON_CLUSTER_CONF.getDefaultString());
    Config clusterConfig = Config.toClusterMode(defaultConfig); //to token-substitute the conf paths

    Config.Builder cb = Config.newBuilder()
        .putAll(defaultConfig)
        .putAll(loadConfig(Context.packingFile(clusterConfig)))
        .putAll(loadConfig(Context.healthmgrFile(clusterConfig)))
        .putAll(loadConfig(Context.schedulerFile(clusterConfig)))
        .putAll(loadConfig(Context.stateManagerFile(clusterConfig)))
        .putAll(loadConfig(Context.uploaderFile(clusterConfig)))
        .putAll(loadConfig(Context.downloaderFile(clusterConfig)))
        .putAll(loadConfig(Context.statefulConfigFile(clusterConfig)));

    // Add the override config at the end to replace any existing configs
    cb.putAll(loadConfig(Context.overrideFile(clusterConfig)));

    return cb.build();
  }
168273
protected function _getConfig()
    {
        if ($this->config === null) {
            $configFinder = new ConfigFinder();
            $this->config = $configFinder->loadAll();
        }

        return $this->config;
    }
243447
public FailureDetectorConfig setCluster(Cluster cluster) {
        Utils.notNull(cluster);
        this.cluster = cluster;
        /*
         * FIXME: this is the hacky way to refresh the admin connection
         * verifier, but it'll just work. The clean way to do so is to have a
         * centralized metadata management, and all references of cluster object
         * point to that.
         */
        if(this.connectionVerifier instanceof AdminConnectionVerifier) {
            ((AdminConnectionVerifier) connectionVerifier).setCluster(cluster);
        }
        return this;
    }
917680
public function configure()
    {
        $this->config = new Configuration();

        $this->config->setNamingStrategy(new Mapping\DefaultNamingStrategy());

        $cache = new ApcCache();
        if ($cache->isSupported()) {
            $cache->setPrefix('samurai.onikiri.table.schema');
        } else {
            $cache = new ArrayCache();
        }
        $this->config->setSchemaCacher($cache);

        return $this->config;
    }
136054
public function init()
    {
        $config = new Config($this->getSetting('config'), $this->getEnvironment());

        $this->container = (new Container)
            ->setConfig($config)
            ->setInstance('core', $this)
            ->setInstance('config', $config);

        $services = $this->loadServices();
        $this->container->setServices($services);

        $this->modules = $this->loadModules();
        $this->loadRoutesAndServices();

        $this->router = (new Router($this->routes, $this->modules))
            ->setRequest($this->request)
            ->setBasePath($this->request->getBasePath());

        $this->container->addServices($this->services)
            ->setInstance('router', $this->router);

        foreach ($this->modules as $module) {
            $module->setContainer($this->container);
        }

        return $this;
    }