friendica/src/Factory/ConfigFactory.php

69 lines
1.8 KiB
PHP
Raw Normal View History

2019-02-03 21:22:04 +00:00
<?php
namespace Friendica\Factory;
use Friendica\Core;
2019-02-03 21:22:04 +00:00
use Friendica\Core\Config;
use Friendica\Core\Config\Adapter;
use Friendica\Core\Config\Cache;
use Friendica\Util\Config\ConfigCacheLoader;
2019-02-03 21:22:04 +00:00
class ConfigFactory
{
/**
* @param ConfigCacheLoader $loader The Config Cache loader (INI/config/.htconfig)
*
* @return Cache\ConfigCache
*/
public static function createCache(ConfigCacheLoader $loader)
2019-02-03 21:22:04 +00:00
{
$configCache = new Cache\ConfigCache();
2019-02-03 21:22:04 +00:00
$loader->loadConfigFiles($configCache);
return $configCache;
}
/**
* @param Cache\ConfigCache $configCache The config cache of this adapter
*
* @return Config\Configuration
2019-02-03 21:22:04 +00:00
*/
public static function createConfig(Cache\ConfigCache $configCache)
2019-02-03 21:22:04 +00:00
{
if ($configCache->get('system', 'config_adapter') === 'preload') {
$configAdapter = new Adapter\PreloadConfigAdapter();
2019-02-03 21:22:04 +00:00
} else {
$configAdapter = new Adapter\JITConfigAdapter();
2019-02-03 21:22:04 +00:00
}
$configuration = new Config\Configuration($configCache, $configAdapter);
// Set the config in the static container for legacy usage
Core\Config::init($configuration);
return $configuration;
2019-02-03 21:22:04 +00:00
}
/**
* @param Cache\ConfigCache $configCache The config cache of this adapter
* @param int $uid The UID of the current user
*
* @return Config\PConfiguration
2019-02-03 21:22:04 +00:00
*/
public static function createPConfig(Cache\ConfigCache $configCache, $uid = null)
2019-02-03 21:22:04 +00:00
{
if ($configCache->get('system', 'config_adapter') === 'preload') {
$configAdapter = new Adapter\PreloadPConfigAdapter($uid);
2019-02-03 21:22:04 +00:00
} else {
$configAdapter = new Adapter\JITPConfigAdapter();
2019-02-03 21:22:04 +00:00
}
$configuration = new Config\PConfiguration($configCache, $configAdapter);
// Set the config in the static container for legacy usage
Core\PConfig::init($configuration);
return $configuration;
2019-02-03 21:22:04 +00:00
}
}