friendica/src/Factory/ConfigFactory.php

69 lines
1.9 KiB
PHP
Raw Normal View History

2019-02-03 16:22:04 -05:00
<?php
namespace Friendica\Factory;
use Friendica\Core;
2019-02-03 16:22:04 -05:00
use Friendica\Core\Config;
use Friendica\Core\Config\Cache;
2019-07-12 17:01:01 -04:00
use Friendica\Model\Config\Config as ConfigModel;
2019-07-15 14:13:53 -04:00
use Friendica\Model\Config\PConfig as PConfigModel;
2019-03-24 07:54:26 -04:00
use Friendica\Util\Config\ConfigFileLoader;
2019-02-03 16:22:04 -05:00
class ConfigFactory
{
/**
2019-03-24 07:54:26 -04:00
* @param ConfigFileLoader $loader The Config Cache loader (INI/config/.htconfig)
*
* @return Cache\ConfigCache
*/
2019-03-24 07:54:26 -04:00
public static function createCache(ConfigFileLoader $loader)
2019-02-03 16:22:04 -05:00
{
$configCache = new Cache\ConfigCache();
2019-03-24 07:54:26 -04:00
$loader->setupCache($configCache);
2019-02-03 16:22:04 -05:00
return $configCache;
}
/**
2019-07-12 17:01:01 -04:00
* @param Cache\ConfigCache $configCache The config cache of this adapter
* @param ConfigModel $configModel The configuration model
*
* @return Config\Configuration
2019-02-03 16:22:04 -05:00
*/
2019-07-12 17:01:01 -04:00
public static function createConfig(Cache\ConfigCache $configCache, ConfigModel $configModel)
2019-02-03 16:22:04 -05:00
{
if ($configCache->get('system', 'config_adapter') === 'preload') {
2019-07-12 17:01:01 -04:00
$configuration = new Config\PreloadConfiguration($configCache, $configModel);
2019-02-03 16:22:04 -05:00
} else {
2019-07-12 17:01:01 -04:00
$configuration = new Config\JitConfiguration($configCache, $configModel);
2019-02-03 16:22:04 -05:00
}
// Set the config in the static container for legacy usage
Core\Config::init($configuration);
return $configuration;
2019-02-03 16:22:04 -05:00
}
/**
* @param Cache\ConfigCache $configCache The config cache
* @param Cache\PConfigCache $pConfigCache The personal config cache
2019-07-15 14:13:53 -04:00
* @param PConfigModel $configModel The configuration model
*
* @return Config\PConfiguration
2019-02-03 16:22:04 -05:00
*/
2019-07-15 14:13:53 -04:00
public static function createPConfig(Cache\ConfigCache $configCache, Cache\PConfigCache $pConfigCache, PConfigModel $configModel)
2019-02-03 16:22:04 -05:00
{
if ($configCache->get('system', 'config_adapter') === 'preload') {
2019-07-15 14:13:53 -04:00
$configuration = new Config\PreloadPConfiguration($pConfigCache, $configModel);
2019-02-03 16:22:04 -05:00
} else {
2019-07-15 14:13:53 -04:00
$configuration = new Config\JitPConfiguration($pConfigCache, $configModel);
2019-02-03 16:22:04 -05:00
}
// Set the config in the static container for legacy usage
Core\PConfig::init($configuration);
return $configuration;
2019-02-03 16:22:04 -05:00
}
}