2019-02-03 16:22:04 -05:00
|
|
|
<?php
|
2020-02-09 09:45:36 -05:00
|
|
|
/**
|
|
|
|
* @copyright Copyright (C) 2020, Friendica
|
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
2019-02-03 16:22:04 -05:00
|
|
|
|
|
|
|
namespace Friendica\Factory;
|
|
|
|
|
2020-01-19 16:50:44 -05:00
|
|
|
use Exception;
|
2019-02-03 16:22:04 -05:00
|
|
|
use Friendica\Core\Config;
|
2019-02-10 13:52:21 -05:00
|
|
|
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-07-20 19:22:10 -04:00
|
|
|
use Friendica\Util\ConfigFileLoader;
|
2019-02-03 16:22:04 -05:00
|
|
|
|
|
|
|
class ConfigFactory
|
|
|
|
{
|
2019-02-03 16:46:50 -05:00
|
|
|
/**
|
2019-03-24 07:54:26 -04:00
|
|
|
* @param ConfigFileLoader $loader The Config Cache loader (INI/config/.htconfig)
|
2019-02-03 16:46:50 -05:00
|
|
|
*
|
2020-01-19 16:23:44 -05:00
|
|
|
* @return Cache
|
2020-01-19 16:50:44 -05:00
|
|
|
*
|
|
|
|
* @throws Exception
|
2019-02-03 16:46:50 -05:00
|
|
|
*/
|
2020-10-06 14:06:52 -04:00
|
|
|
public function createCache(ConfigFileLoader $loader, array $server = [])
|
2019-02-03 16:22:04 -05:00
|
|
|
{
|
2020-01-19 16:23:44 -05:00
|
|
|
$configCache = new Cache();
|
2020-10-06 14:06:52 -04:00
|
|
|
$loader->setupCache($configCache, $server);
|
2019-02-03 16:22:04 -05:00
|
|
|
|
|
|
|
return $configCache;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-01-19 16:23:44 -05:00
|
|
|
* @param Cache $configCache The config cache of this adapter
|
|
|
|
* @param ConfigModel $configModel The configuration model
|
2019-02-03 16:46:50 -05:00
|
|
|
*
|
2020-01-19 15:29:36 -05:00
|
|
|
* @return Config\IConfig
|
2019-02-03 16:22:04 -05:00
|
|
|
*/
|
2020-01-19 16:23:44 -05:00
|
|
|
public function createConfig(Cache $configCache, ConfigModel $configModel)
|
2019-02-03 16:22:04 -05:00
|
|
|
{
|
2019-02-10 13:52:21 -05:00
|
|
|
if ($configCache->get('system', 'config_adapter') === 'preload') {
|
2020-01-19 15:29:36 -05:00
|
|
|
$configuration = new Config\PreloadConfig($configCache, $configModel);
|
2019-02-03 16:22:04 -05:00
|
|
|
} else {
|
2020-01-19 15:29:36 -05:00
|
|
|
$configuration = new Config\JitConfig($configCache, $configModel);
|
2019-02-03 16:22:04 -05:00
|
|
|
}
|
2019-02-10 13:52:21 -05:00
|
|
|
|
|
|
|
|
|
|
|
return $configuration;
|
2019-02-03 16:22:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-01-19 16:23:44 -05:00
|
|
|
* @param Cache $configCache The config cache
|
|
|
|
* @param \Friendica\Core\PConfig\Cache $pConfigCache The personal config cache
|
|
|
|
* @param PConfigModel $configModel The configuration model
|
2019-02-03 16:46:50 -05:00
|
|
|
*
|
2020-01-19 16:23:44 -05:00
|
|
|
* @return \Friendica\Core\PConfig\IPConfig
|
2019-02-03 16:22:04 -05:00
|
|
|
*/
|
2020-01-19 16:23:44 -05:00
|
|
|
public function createPConfig(Cache $configCache, \Friendica\Core\PConfig\Cache $pConfigCache, PConfigModel $configModel)
|
2019-02-03 16:22:04 -05:00
|
|
|
{
|
2019-02-10 13:52:21 -05:00
|
|
|
if ($configCache->get('system', 'config_adapter') === 'preload') {
|
2020-01-19 16:23:44 -05:00
|
|
|
$configuration = new \Friendica\Core\PConfig\PreloadPConfig($pConfigCache, $configModel);
|
2019-02-03 16:22:04 -05:00
|
|
|
} else {
|
2020-01-19 16:23:44 -05:00
|
|
|
$configuration = new \Friendica\Core\PConfig\JitPConfig($pConfigCache, $configModel);
|
2019-02-03 16:22:04 -05:00
|
|
|
}
|
2019-02-10 13:52:21 -05:00
|
|
|
|
|
|
|
return $configuration;
|
2019-02-03 16:22:04 -05:00
|
|
|
}
|
|
|
|
}
|