2019-02-03 22:22:04 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Friendica\Factory;
|
|
|
|
|
2019-02-10 19:52:21 +01:00
|
|
|
use Friendica\Core;
|
2019-02-03 22:22:04 +01:00
|
|
|
use Friendica\Core\Config;
|
2019-02-10 19:52:21 +01:00
|
|
|
use Friendica\Core\Config\Adapter;
|
|
|
|
use Friendica\Core\Config\Cache;
|
2019-07-12 23:01:01 +02:00
|
|
|
use Friendica\Model\Config\Config as ConfigModel;
|
2019-03-24 12:54:26 +01:00
|
|
|
use Friendica\Util\Config\ConfigFileLoader;
|
2019-02-03 22:22:04 +01:00
|
|
|
|
|
|
|
class ConfigFactory
|
|
|
|
{
|
2019-02-03 22:46:50 +01:00
|
|
|
/**
|
2019-03-24 12:54:26 +01:00
|
|
|
* @param ConfigFileLoader $loader The Config Cache loader (INI/config/.htconfig)
|
2019-02-03 22:46:50 +01:00
|
|
|
*
|
2019-02-10 19:52:21 +01:00
|
|
|
* @return Cache\ConfigCache
|
2019-02-03 22:46:50 +01:00
|
|
|
*/
|
2019-03-24 12:54:26 +01:00
|
|
|
public static function createCache(ConfigFileLoader $loader)
|
2019-02-03 22:22:04 +01:00
|
|
|
{
|
2019-02-10 19:52:21 +01:00
|
|
|
$configCache = new Cache\ConfigCache();
|
2019-03-24 12:54:26 +01:00
|
|
|
$loader->setupCache($configCache);
|
2019-02-03 22:22:04 +01:00
|
|
|
|
|
|
|
return $configCache;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-07-12 23:01:01 +02:00
|
|
|
* @param Cache\ConfigCache $configCache The config cache of this adapter
|
|
|
|
* @param ConfigModel $configModel The configuration model
|
2019-02-03 22:46:50 +01:00
|
|
|
*
|
2019-02-10 19:52:21 +01:00
|
|
|
* @return Config\Configuration
|
2019-02-03 22:22:04 +01:00
|
|
|
*/
|
2019-07-12 23:01:01 +02:00
|
|
|
public static function createConfig(Cache\ConfigCache $configCache, ConfigModel $configModel)
|
2019-02-03 22:22:04 +01:00
|
|
|
{
|
2019-02-10 19:52:21 +01:00
|
|
|
if ($configCache->get('system', 'config_adapter') === 'preload') {
|
2019-07-12 23:01:01 +02:00
|
|
|
$configuration = new Config\PreloadConfiguration($configCache, $configModel);
|
2019-02-03 22:22:04 +01:00
|
|
|
} else {
|
2019-07-12 23:01:01 +02:00
|
|
|
$configuration = new Config\JitConfiguration($configCache, $configModel);
|
2019-02-03 22:22:04 +01:00
|
|
|
}
|
2019-02-10 19:52:21 +01:00
|
|
|
|
|
|
|
|
|
|
|
// Set the config in the static container for legacy usage
|
|
|
|
Core\Config::init($configuration);
|
|
|
|
|
|
|
|
return $configuration;
|
2019-02-03 22:22:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-07-12 23:05:48 +02:00
|
|
|
* @param Cache\ConfigCache $configCache The config cache
|
|
|
|
* @param Cache\PConfigCache $pConfigCache The personal config cache
|
2019-02-10 19:52:21 +01:00
|
|
|
* @param int $uid The UID of the current user
|
2019-02-03 22:46:50 +01:00
|
|
|
*
|
2019-02-10 19:52:21 +01:00
|
|
|
* @return Config\PConfiguration
|
2019-02-03 22:22:04 +01:00
|
|
|
*/
|
2019-07-12 23:05:48 +02:00
|
|
|
public static function createPConfig(Cache\ConfigCache $configCache, Cache\PConfigCache $pConfigCache, $uid = null)
|
2019-02-03 22:22:04 +01:00
|
|
|
{
|
2019-02-10 19:52:21 +01:00
|
|
|
if ($configCache->get('system', 'config_adapter') === 'preload') {
|
|
|
|
$configAdapter = new Adapter\PreloadPConfigAdapter($uid);
|
2019-02-03 22:22:04 +01:00
|
|
|
} else {
|
2019-02-10 19:52:21 +01:00
|
|
|
$configAdapter = new Adapter\JITPConfigAdapter();
|
2019-02-03 22:22:04 +01:00
|
|
|
}
|
2019-02-10 19:52:21 +01:00
|
|
|
|
2019-07-12 23:05:48 +02:00
|
|
|
$configuration = new Config\PConfiguration($pConfigCache, $configAdapter);
|
2019-02-10 19:52:21 +01:00
|
|
|
|
|
|
|
// Set the config in the static container for legacy usage
|
|
|
|
Core\PConfig::init($configuration);
|
|
|
|
|
|
|
|
return $configuration;
|
2019-02-03 22:22:04 +01:00
|
|
|
}
|
|
|
|
}
|