2019-02-03 21:22:04 +00:00
|
|
|
<?php
|
2020-02-09 14:45:36 +00:00
|
|
|
/**
|
2023-01-01 14:36:24 +00:00
|
|
|
* @copyright Copyright (C) 2010-2023, the Friendica project
|
2020-02-09 14:45:36 +00:00
|
|
|
*
|
|
|
|
* @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 21:22:04 +00:00
|
|
|
|
2021-10-23 09:29:16 +00:00
|
|
|
namespace Friendica\Core\Config\Factory;
|
2019-02-03 21:22:04 +00:00
|
|
|
|
2021-10-26 19:44:29 +00:00
|
|
|
use Friendica\Core\Config\Util;
|
|
|
|
use Friendica\Core\Config\ValueObject\Cache;
|
2019-02-03 21:22:04 +00:00
|
|
|
|
2023-01-01 20:10:37 +00:00
|
|
|
/**
|
|
|
|
* The config factory for creating either the cache or the whole model
|
|
|
|
*/
|
2021-10-26 19:44:29 +00:00
|
|
|
class Config
|
2019-02-03 21:22:04 +00:00
|
|
|
{
|
2021-09-12 11:44:29 +00:00
|
|
|
/**
|
|
|
|
* The key of the $_SERVER variable to override the config directory
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
const CONFIG_DIR_ENV = 'FRIENDICA_CONFIG_DIR';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Sub directory of the config-files
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
const CONFIG_DIR = 'config';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Sub directory of the static config-files
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
const STATIC_DIR = 'static';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $basePath The basepath of FRIENDICA
|
2021-10-26 19:44:29 +00:00
|
|
|
* @param array $server The $_SERVER array
|
2021-09-12 11:44:29 +00:00
|
|
|
*
|
2023-01-01 20:10:37 +00:00
|
|
|
* @return Util\ConfigFileManager
|
2021-09-12 11:44:29 +00:00
|
|
|
*/
|
2023-01-01 20:10:37 +00:00
|
|
|
public function createConfigFileLoader(string $basePath, array $server = []): Util\ConfigFileManager
|
2021-09-12 11:44:29 +00:00
|
|
|
{
|
|
|
|
if (!empty($server[self::CONFIG_DIR_ENV]) && is_dir($server[self::CONFIG_DIR_ENV])) {
|
|
|
|
$configDir = $server[self::CONFIG_DIR_ENV];
|
|
|
|
} else {
|
|
|
|
$configDir = $basePath . DIRECTORY_SEPARATOR . self::CONFIG_DIR;
|
|
|
|
}
|
|
|
|
$staticDir = $basePath . DIRECTORY_SEPARATOR . self::STATIC_DIR;
|
|
|
|
|
2023-01-01 20:10:37 +00:00
|
|
|
return new Util\ConfigFileManager($basePath, $configDir, $staticDir, new Util\ConfigFileTransformer());
|
2021-09-12 11:44:29 +00:00
|
|
|
}
|
|
|
|
|
2019-02-03 21:46:50 +00:00
|
|
|
/**
|
2023-01-01 20:10:37 +00:00
|
|
|
* @param Util\ConfigFileManager $configFileManager The Config Cache manager (INI/config/.htconfig)
|
|
|
|
* @param array $server
|
2019-02-03 21:46:50 +00:00
|
|
|
*
|
2020-01-19 21:23:44 +00:00
|
|
|
* @return Cache
|
2019-02-03 21:46:50 +00:00
|
|
|
*/
|
2023-01-01 20:10:37 +00:00
|
|
|
public function createCache(Util\ConfigFileManager $configFileManager, array $server = []): Cache
|
2019-02-03 21:22:04 +00:00
|
|
|
{
|
2020-01-19 21:23:44 +00:00
|
|
|
$configCache = new Cache();
|
2023-01-01 20:10:37 +00:00
|
|
|
$configFileManager->setupCache($configCache, $server);
|
2019-02-03 21:22:04 +00:00
|
|
|
|
|
|
|
return $configCache;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-10-26 19:44:29 +00:00
|
|
|
* @param Cache $configCache The config cache of this adapter
|
|
|
|
* @param Repository\Config $configRepo The configuration repository
|
2019-02-03 21:46:50 +00:00
|
|
|
*
|
2021-10-26 19:44:29 +00:00
|
|
|
* @return Capability\IManageConfigValues
|
2019-02-03 21:22:04 +00:00
|
|
|
*/
|
2023-01-01 20:10:37 +00:00
|
|
|
public function create(Util\ConfigFileManager $loader, Cache $configCache, Repository\Config $configRepo)
|
2019-02-03 21:22:04 +00:00
|
|
|
{
|
2019-02-10 18:52:21 +00:00
|
|
|
if ($configCache->get('system', 'config_adapter') === 'preload') {
|
2023-01-01 20:10:37 +00:00
|
|
|
$configuration = new Type\PreloadConfig($loader, $configCache, $configRepo);
|
2019-02-03 21:22:04 +00:00
|
|
|
} else {
|
2023-01-01 20:10:37 +00:00
|
|
|
$configuration = new Type\JitConfig($loader, $configCache, $configRepo);
|
2019-02-03 21:22:04 +00:00
|
|
|
}
|
2019-02-10 18:52:21 +00:00
|
|
|
|
|
|
|
return $configuration;
|
2019-02-03 21:22:04 +00:00
|
|
|
}
|
|
|
|
}
|