mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2024-12-18 00:43:19 +03:00
fix: extract duplicate config loading (#4242)
Also fix a problem with bin/cache-prune and FileCache and its enable_purge option
This commit is contained in:
parent
9f48370eb0
commit
3e1a8b29d9
8 changed files with 36 additions and 80 deletions
|
@ -89,7 +89,9 @@ class DisplayAction implements ActionInterface
|
||||||
$this->cache->set($cacheKey, $response, 60 * 15);
|
$this->cache->set($cacheKey, $response, 60 * 15);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rand(1, 100) === 2) {
|
// For 1% of requests, prune cache
|
||||||
|
if (rand(1, 100) === 1) {
|
||||||
|
// This might be resource intensive!
|
||||||
$this->cache->prune();
|
$this->cache->prune();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,16 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require __DIR__ . '/../lib/bootstrap.php';
|
require __DIR__ . '/../lib/bootstrap.php';
|
||||||
|
require __DIR__ . '/../lib/config.php';
|
||||||
$config = [];
|
|
||||||
if (file_exists(__DIR__ . '/../config.ini.php')) {
|
|
||||||
$config = parse_ini_file(__DIR__ . '/../config.ini.php', true, INI_SCANNER_TYPED);
|
|
||||||
if (!$config) {
|
|
||||||
http_response_code(500);
|
|
||||||
exit("Error parsing config.ini.php\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Configuration::loadConfiguration($config, getenv());
|
|
||||||
|
|
||||||
$container = require __DIR__ . '/../lib/dependencies.php';
|
$container = require __DIR__ . '/../lib/dependencies.php';
|
||||||
|
|
||||||
|
|
|
@ -6,19 +6,19 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require __DIR__ . '/../lib/bootstrap.php';
|
require __DIR__ . '/../lib/bootstrap.php';
|
||||||
|
require __DIR__ . '/../lib/config.php';
|
||||||
$config = [];
|
|
||||||
if (file_exists(__DIR__ . '/../config.ini.php')) {
|
|
||||||
$config = parse_ini_file(__DIR__ . '/../config.ini.php', true, INI_SCANNER_TYPED);
|
|
||||||
if (!$config) {
|
|
||||||
http_response_code(500);
|
|
||||||
exit("Error parsing config.ini.php\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Configuration::loadConfiguration($config, getenv());
|
|
||||||
|
|
||||||
$container = require __DIR__ . '/../lib/dependencies.php';
|
$container = require __DIR__ . '/../lib/dependencies.php';
|
||||||
|
|
||||||
|
/** @var CacheInterface $cache */
|
||||||
$cache = $container['cache'];
|
$cache = $container['cache'];
|
||||||
|
|
||||||
|
if (
|
||||||
|
Configuration::getConfig('cache', 'type') === 'file'
|
||||||
|
&& !Configuration::getConfig('FileCache', 'enable_purge')
|
||||||
|
) {
|
||||||
|
// Override enable_purge for this execution
|
||||||
|
Configuration::setConfig('FileCache', 'enable_purge', true);
|
||||||
|
}
|
||||||
|
|
||||||
$cache->prune();
|
$cache->prune();
|
||||||
|
|
11
bin/test
11
bin/test
|
@ -6,16 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require __DIR__ . '/../lib/bootstrap.php';
|
require __DIR__ . '/../lib/bootstrap.php';
|
||||||
|
require __DIR__ . '/../lib/config.php';
|
||||||
$config = [];
|
|
||||||
if (file_exists(__DIR__ . '/../config.ini.php')) {
|
|
||||||
$config = parse_ini_file(__DIR__ . '/../config.ini.php', true, INI_SCANNER_TYPED);
|
|
||||||
if (!$config) {
|
|
||||||
http_response_code(500);
|
|
||||||
exit("Error parsing config.ini.php\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Configuration::loadConfiguration($config, getenv());
|
|
||||||
|
|
||||||
$container = require __DIR__ . '/../lib/dependencies.php';
|
$container = require __DIR__ . '/../lib/dependencies.php';
|
||||||
|
|
||||||
|
|
|
@ -97,8 +97,10 @@ class FileCache implements CacheInterface
|
||||||
}
|
}
|
||||||
$expiration = $item['expiration'] ?? time();
|
$expiration = $item['expiration'] ?? time();
|
||||||
if ($expiration === 0 || $expiration > time()) {
|
if ($expiration === 0 || $expiration > time()) {
|
||||||
|
// Cached forever, or not expired yet
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
// Expired, so delete file
|
||||||
unlink($cacheFile);
|
unlink($cacheFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
13
index.php
13
index.php
|
@ -5,17 +5,8 @@ if (version_compare(\PHP_VERSION, '7.4.0') === -1) {
|
||||||
exit("RSS-Bridge requires minimum PHP version 7.4\n");
|
exit("RSS-Bridge requires minimum PHP version 7.4\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
require_once __DIR__ . '/lib/bootstrap.php';
|
require __DIR__ . '/lib/bootstrap.php';
|
||||||
|
require __DIR__ . '/lib/config.php';
|
||||||
$config = [];
|
|
||||||
if (file_exists(__DIR__ . '/config.ini.php')) {
|
|
||||||
$config = parse_ini_file(__DIR__ . '/config.ini.php', true, INI_SCANNER_TYPED);
|
|
||||||
if (!$config) {
|
|
||||||
http_response_code(500);
|
|
||||||
exit("Error parsing config.ini.php\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Configuration::loadConfiguration($config, getenv());
|
|
||||||
|
|
||||||
$container = require __DIR__ . '/lib/dependencies.php';
|
$container = require __DIR__ . '/lib/dependencies.php';
|
||||||
|
|
||||||
|
|
|
@ -15,43 +15,6 @@ final class Configuration
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function checkInstallation(): array
|
|
||||||
{
|
|
||||||
$errors = [];
|
|
||||||
|
|
||||||
// OpenSSL: https://www.php.net/manual/en/book.openssl.php
|
|
||||||
if (!extension_loaded('openssl')) {
|
|
||||||
$errors[] = 'openssl extension not loaded';
|
|
||||||
}
|
|
||||||
|
|
||||||
// libxml: https://www.php.net/manual/en/book.libxml.php
|
|
||||||
if (!extension_loaded('libxml')) {
|
|
||||||
$errors[] = 'libxml extension not loaded';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Multibyte String (mbstring): https://www.php.net/manual/en/book.mbstring.php
|
|
||||||
if (!extension_loaded('mbstring')) {
|
|
||||||
$errors[] = 'mbstring extension not loaded';
|
|
||||||
}
|
|
||||||
|
|
||||||
// SimpleXML: https://www.php.net/manual/en/book.simplexml.php
|
|
||||||
if (!extension_loaded('simplexml')) {
|
|
||||||
$errors[] = 'simplexml extension not loaded';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Client URL Library (curl): https://www.php.net/manual/en/book.curl.php
|
|
||||||
// Allow RSS-Bridge to run without curl module in CLI mode without root certificates
|
|
||||||
if (!extension_loaded('curl') && !(php_sapi_name() === 'cli' && empty(ini_get('curl.cainfo')))) {
|
|
||||||
$errors[] = 'curl extension not loaded';
|
|
||||||
}
|
|
||||||
|
|
||||||
// JavaScript Object Notation (json): https://www.php.net/manual/en/book.json.php
|
|
||||||
if (!extension_loaded('json')) {
|
|
||||||
$errors[] = 'json extension not loaded';
|
|
||||||
}
|
|
||||||
return $errors;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function loadConfiguration(array $customConfig = [], array $env = [])
|
public static function loadConfiguration(array $customConfig = [], array $env = [])
|
||||||
{
|
{
|
||||||
if (!file_exists(__DIR__ . '/../config.default.ini.php')) {
|
if (!file_exists(__DIR__ . '/../config.default.ini.php')) {
|
||||||
|
@ -204,7 +167,10 @@ final class Configuration
|
||||||
return self::$config[strtolower($section)][strtolower($key)] ?? $default;
|
return self::$config[strtolower($section)][strtolower($key)] ?? $default;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function setConfig(string $section, string $key, $value): void
|
/**
|
||||||
|
* @internal Please avoid usage
|
||||||
|
*/
|
||||||
|
public static function setConfig(string $section, string $key, $value): void
|
||||||
{
|
{
|
||||||
self::$config[strtolower($section)][strtolower($key)] = $value;
|
self::$config[strtolower($section)][strtolower($key)] = $value;
|
||||||
}
|
}
|
||||||
|
|
13
lib/config.php
Normal file
13
lib/config.php
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
$config = [];
|
||||||
|
if (file_exists(__DIR__ . '/../config.ini.php')) {
|
||||||
|
$config = parse_ini_file(__DIR__ . '/../config.ini.php', true, INI_SCANNER_TYPED);
|
||||||
|
if (!$config) {
|
||||||
|
http_response_code(500);
|
||||||
|
exit("Error parsing config.ini.php\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Configuration::loadConfiguration($config, getenv());
|
Loading…
Reference in a new issue