friendica/src/Factory/ConfigFactory.php

65 lines
1.7 KiB
PHP
Raw Normal View History

2019-02-03 22:22:04 +01:00
<?php
namespace Friendica\Factory;
use Exception;
2019-02-03 22:22:04 +01:00
use Friendica\Core\Config;
use Friendica\Core\Config\Cache;
2019-07-12 23:01:01 +02:00
use Friendica\Model\Config\Config as ConfigModel;
2019-07-15 20:13:53 +02:00
use Friendica\Model\Config\PConfig as PConfigModel;
use Friendica\Util\ConfigFileLoader;
2019-02-03 22:22:04 +01:00
class ConfigFactory
{
/**
2019-03-24 12:54:26 +01:00
* @param ConfigFileLoader $loader The Config Cache loader (INI/config/.htconfig)
*
* @return Cache
*
* @throws Exception
*/
public function createCache(ConfigFileLoader $loader)
2019-02-03 22:22:04 +01:00
{
$configCache = new Cache();
2019-03-24 12:54:26 +01:00
$loader->setupCache($configCache);
2019-02-03 22:22:04 +01:00
return $configCache;
}
/**
* @param Cache $configCache The config cache of this adapter
* @param ConfigModel $configModel The configuration model
*
* @return Config\IConfig
2019-02-03 22:22:04 +01:00
*/
public function createConfig(Cache $configCache, ConfigModel $configModel)
2019-02-03 22:22:04 +01:00
{
if ($configCache->get('system', 'config_adapter') === 'preload') {
$configuration = new Config\PreloadConfig($configCache, $configModel);
2019-02-03 22:22:04 +01:00
} else {
$configuration = new Config\JitConfig($configCache, $configModel);
2019-02-03 22:22:04 +01:00
}
return $configuration;
2019-02-03 22:22:04 +01:00
}
/**
* @param Cache $configCache The config cache
* @param \Friendica\Core\PConfig\Cache $pConfigCache The personal config cache
* @param PConfigModel $configModel The configuration model
*
* @return \Friendica\Core\PConfig\IPConfig
2019-02-03 22:22:04 +01:00
*/
public function createPConfig(Cache $configCache, \Friendica\Core\PConfig\Cache $pConfigCache, PConfigModel $configModel)
2019-02-03 22:22:04 +01:00
{
if ($configCache->get('system', 'config_adapter') === 'preload') {
$configuration = new \Friendica\Core\PConfig\PreloadPConfig($pConfigCache, $configModel);
2019-02-03 22:22:04 +01:00
} else {
$configuration = new \Friendica\Core\PConfig\JitPConfig($pConfigCache, $configModel);
2019-02-03 22:22:04 +01:00
}
return $configuration;
2019-02-03 22:22:04 +01:00
}
}