2019-03-23 15:37:05 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Friendica\Util\Config;
|
|
|
|
|
2019-03-24 12:54:26 +01:00
|
|
|
/**
|
|
|
|
* An abstract class in case of handling with config files
|
|
|
|
*/
|
|
|
|
abstract class ConfigFileManager
|
2019-03-23 15:37:05 +01:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The Sub directory of the config-files
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
const SUBDIRECTORY = 'config';
|
|
|
|
|
2019-03-23 15:40:09 +01:00
|
|
|
/**
|
|
|
|
* The default name of the user defined config file
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
const CONFIG_LOCAL = 'local';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The default name of the user defined ini file
|
|
|
|
* @var string
|
|
|
|
*/
|
2019-03-24 12:54:26 +01:00
|
|
|
const CONFIG_INI = 'local';
|
2019-03-23 15:40:09 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The default name of the user defined legacy config file
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
const CONFIG_HTCONFIG = 'htconfig';
|
|
|
|
|
2019-03-23 15:37:05 +01:00
|
|
|
protected $baseDir;
|
|
|
|
protected $configDir;
|
|
|
|
|
2019-03-23 15:40:09 +01:00
|
|
|
/**
|
|
|
|
* @param string $baseDir The base directory of Friendica
|
|
|
|
*/
|
2019-03-23 15:37:05 +01:00
|
|
|
public function __construct($baseDir)
|
|
|
|
{
|
|
|
|
$this->baseDir = $baseDir;
|
|
|
|
$this->configDir = $baseDir . DIRECTORY_SEPARATOR . self::SUBDIRECTORY;
|
|
|
|
}
|
|
|
|
|
2019-03-23 15:40:09 +01:00
|
|
|
/**
|
|
|
|
* Gets the full name (including the path) for a *.config.php (default is local.config.php)
|
|
|
|
*
|
|
|
|
* @param string $name The config name (default is empty, which means local.config.php)
|
|
|
|
*
|
|
|
|
* @return string The full name or empty if not found
|
|
|
|
*/
|
|
|
|
protected function getConfigFullName($name = '')
|
2019-03-23 15:37:05 +01:00
|
|
|
{
|
2019-03-23 15:40:09 +01:00
|
|
|
$name = !empty($name) ? $name : self::CONFIG_LOCAL;
|
|
|
|
|
2019-03-23 15:37:05 +01:00
|
|
|
$fullName = $this->configDir . DIRECTORY_SEPARATOR . $name . '.config.php';
|
|
|
|
return file_exists($fullName) ? $fullName : '';
|
|
|
|
}
|
|
|
|
|
2019-03-23 15:40:09 +01:00
|
|
|
/**
|
|
|
|
* Gets the full name (including the path) for a *.ini.php (default is local.ini.php)
|
|
|
|
*
|
|
|
|
* @param string $name The config name (default is empty, which means local.ini.php)
|
|
|
|
*
|
|
|
|
* @return string The full name or empty if not found
|
|
|
|
*/
|
|
|
|
protected function getIniFullName($name = '')
|
2019-03-23 15:37:05 +01:00
|
|
|
{
|
2019-03-23 15:40:09 +01:00
|
|
|
$name = !empty($name) ? $name : self::CONFIG_INI;
|
|
|
|
|
2019-03-23 15:37:05 +01:00
|
|
|
$fullName = $this->configDir . DIRECTORY_SEPARATOR . $name . '.ini.php';
|
|
|
|
return file_exists($fullName) ? $fullName : '';
|
|
|
|
}
|
|
|
|
|
2019-03-23 15:40:09 +01:00
|
|
|
/**
|
|
|
|
* Gets the full name (including the path) for a .*.php (default is .htconfig.php)
|
|
|
|
*
|
|
|
|
* @param string $name The config name (default is empty, which means .htconfig.php)
|
|
|
|
*
|
|
|
|
* @return string The full name or empty if not found
|
|
|
|
*/
|
|
|
|
protected function getHtConfigFullName($name = '')
|
2019-03-23 15:37:05 +01:00
|
|
|
{
|
2019-03-23 15:40:09 +01:00
|
|
|
$name = !empty($name) ? $name : self::CONFIG_HTCONFIG;
|
|
|
|
|
2019-03-23 15:37:05 +01:00
|
|
|
$fullName = $this->baseDir . DIRECTORY_SEPARATOR . '.' . $name . '.php';
|
|
|
|
return file_exists($fullName) ? $fullName : '';
|
|
|
|
}
|
|
|
|
}
|