|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Manage configuration for the application.
|
|
|
|
*/
|
|
|
|
class Minz_Configuration {
|
|
|
|
/**
|
|
|
|
* The list of configurations.
|
|
|
|
*/
|
|
|
|
private static $config_list = array();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a new configuration to the list of configuration.
|
|
|
|
*
|
|
|
|
* @param $namespace the name of the current configuration
|
|
|
|
* @param $config_filename the filename of the configuration
|
|
|
|
* @param $default_filename a filename containing default values for the configuration
|
|
|
|
* @param $configuration_setter an optional helper to set values in configuration
|
|
|
|
*/
|
|
|
|
public static function register($namespace, $config_filename, $default_filename = null,
|
|
|
|
$configuration_setter = null) {
|
|
|
|
self::$config_list[$namespace] = new Minz_Configuration(
|
|
|
|
$namespace, $config_filename, $default_filename, $configuration_setter
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse a file and return its data.
|
|
|
|
*
|
|
|
|
* @param $filename the name of the file to parse.
|
|
|
|
* @return an array of values
|
|
|
|
* @throws Minz_FileNotExistException if the file does not exist or is invalid.
|
|
|
|
*/
|
|
|
|
public static function load($filename) {
|
|
|
|
$data = @include($filename);
|
|
|
|
if (is_array($data)) {
|
|
|
|
return $data;
|
|
|
|
} else {
|
|
|
|
throw new Minz_FileNotExistException($filename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the configuration related to a given namespace.
|
|
|
|
*
|
|
|
|
* @param $namespace the name of the configuration to get.
|
|
|
|
* @return a Minz_Configuration object
|
|
|
|
* @throws Minz_ConfigurationNamespaceException if the namespace does not exist.
|
|
|
|
*/
|
|
|
|
public static function get($namespace) {
|
|
|
|
if (!isset(self::$config_list[$namespace])) {
|
|
|
|
throw new Minz_ConfigurationNamespaceException(
|
|
|
|
$namespace . ' namespace does not exist'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return self::$config_list[$namespace];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The namespace of the current configuration.
|
|
|
|
*/
|
|
|
|
private $namespace = '';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The filename for the current configuration.
|
|
|
|
*/
|
|
|
|
private $config_filename = '';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The filename for the current default values, null by default.
|
|
|
|
*/
|
|
|
|
private $default_filename = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The configuration values, an empty array by default.
|
|
|
|
*/
|
|
|
|
private $data = array();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An object which help to set good values in configuration.
|
|
|
|
*/
|
|
|
|
private $configuration_setter = null;
|
|
|
|
|
|
|
|
public function removeExtension($ext_name) {
|
|
|
|
unset(self::$extensions_enabled[$ext_name]);
|
|
|
|
$legacyKey = array_search($ext_name, self::$extensions_enabled, true);
|
|
|
|
if ($legacyKey !== false) { //Legacy format FreshRSS < 1.11.1
|
|
|
|
unset(self::$extensions_enabled[$legacyKey]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public function addExtension($ext_name) {
|
|
|
|
if (!isset(self::$extensions_enabled[$ext_name])) {
|
|
|
|
self::$extensions_enabled[$ext_name] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new Minz_Configuration object.
|
|
|
|
*
|
|
|
|
* @param $namespace the name of the current configuration.
|
|
|
|
* @param $config_filename the file containing configuration values.
|
|
|
|
* @param $default_filename the file containing default values, null by default.
|
|
|
|
* @param $configuration_setter an optional helper to set values in configuration
|
|
|
|
*/
|
|
|
|
private function __construct($namespace, $config_filename, $default_filename = null,
|
|
|
|
$configuration_setter = null) {
|
|
|
|
$this->namespace = $namespace;
|
|
|
|
$this->config_filename = $config_filename;
|
|
|
|
$this->default_filename = $default_filename;
|
|
|
|
$this->_configurationSetter($configuration_setter);
|
|
|
|
|
|
|
|
if ($this->default_filename != null) {
|
|
|
|
$this->data = self::load($this->default_filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
$this->data = array_replace_recursive(
|
|
|
|
$this->data, self::load($this->config_filename)
|
|
|
|
);
|
|
|
|
} catch (Minz_FileNotExistException $e) {
|
|
|
|
if ($this->default_filename == null) {
|
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a configuration setter for the current configuration.
|
|
|
|
* @param $configuration_setter the setter to call when modifying data. It
|
|
|
|
* must implement an handle($key, $value) method.
|
|
|
|
*/
|
|
|
|
public function _configurationSetter($configuration_setter) {
|
|
|
|
if (is_callable(array($configuration_setter, 'handle'))) {
|
|
|
|
$this->configuration_setter = $configuration_setter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the value of the given param.
|
|
|
|
*
|
|
|
|
* @param $key the name of the param.
|
|
|
|
* @param $default default value to return if key does not exist.
|
|
|
|
* @return the value corresponding to the key.
|
|
|
|
* @throws Minz_ConfigurationParamException if the param does not exist
|
|
|
|
*/
|
|
|
|
public function param($key, $default = null) {
|
|
|
|
if (isset($this->data[$key])) {
|
|
|
|
return $this->data[$key];
|
|
|
|
} elseif (!is_null($default)) {
|
|
|
|
return $default;
|
|
|
|
} else {
|
|
|
|
Minz_Log::warning($key . ' does not exist in configuration');
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A wrapper for param().
|
|
|
|
*/
|
|
|
|
public function __get($key) {
|
|
|
|
return $this->param($key);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set or remove a param.
|
|
|
|
*
|
|
|
|
* @param $key the param name to set.
|
|
|
|
* @param $value the value to set. If null, the key is removed from the configuration.
|
|
|
|
*/
|
|
|
|
public function _param($key, $value = null) {
|
|
|
|
if (!is_null($this->configuration_setter) && $this->configuration_setter->support($key)) {
|
|
|
|
$this->configuration_setter->handle($this->data, $key, $value);
|
|
|
|
} elseif (isset($this->data[$key]) && is_null($value)) {
|
|
|
|
unset($this->data[$key]);
|
|
|
|
} elseif (!is_null($value)) {
|
|
|
|
$this->data[$key] = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A wrapper for _param().
|
|
|
|
*/
|
|
|
|
public function __set($key, $value) {
|
|
|
|
$this->_param($key, $value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Save the current configuration in the configuration file.
|
|
|
|
*/
|
|
|
|
public function save() {
|
|
|
|
$back_filename = $this->config_filename . '.bak.php';
|
|
|
|
@rename($this->config_filename, $back_filename);
|
|
|
|
|
|
|
|
if (file_put_contents($this->config_filename,
|
|
|
|
"<?php\nreturn " . var_export($this->data, true) . ';',
|
|
|
|
LOCK_EX) === false) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
Require PHP 5.5+ (#2495)
* Require PHP 5.5+
https://github.com/FreshRSS/FreshRSS/issues/2469#issuecomment-522255093
I think it would be reasonable to require PHP 5.5+ for the core of
FreshRSS after all.
As Frenzie said, WordPress currently requires PHP 5.6.20+, and it is the
most popular PHP application.
We would loose about 20% of the PHP servers according to
https://w3techs.com/technologies/details/pl-php/5/all but I expect this
number to drop fast after the release of CentOS 8 (CentOS accounts for
17% of Linux servers
https://w3techs.com/technologies/details/os-linux/all/all ).
Distributions:
* no impact on Ubuntu, Fedora, Alpine, OpenWRT, FreeBSD, OpenSuze,
Mageia, as all active versions have PHP > 7
* no impact on OpenSuze, Synology, as all active versions have PHP > 5.5
* we drop Debian 8 Jessie (-2020) - we keep supporting Debian 9 Stretch
(2017-06) - current is Debian 10 Buster
* we drop Red Hat 7 (-2024) - we keep supporting RHEL 8 (2019-05)
* we drop CentOS 7 (-2024) - we will support CentOS 8 (to be released
soonish)
When dropping older versions, I can better like when it is for a good
reason, and there is actually one with PHP 5.5, namely generators
(yield) https://php.net/language.generators.overview which I consider
using.
* Version note for JSON.php
* hex2bin
* Update .travis.yml
Co-Authored-By: Frans de Jonge <fransdejonge@gmail.com>
5 years ago
|
|
|
// Clear PHP cache for include
|
|
|
|
if (function_exists('opcache_invalidate')) {
|
|
|
|
opcache_invalidate($this->config_filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|