mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-08-06 16:46:30 +02:00
refactor: extract exception and cache middleware (#4248)
This commit is contained in:
@@ -82,6 +82,10 @@ final class Configuration
|
||||
}
|
||||
}
|
||||
|
||||
if (Debug::isEnabled()) {
|
||||
self::setConfig('cache', 'type', 'array');
|
||||
}
|
||||
|
||||
if (!is_array(self::getConfig('system', 'enabled_bridges'))) {
|
||||
self::throwConfigError('system', 'enabled_bridges', 'Is not an array');
|
||||
}
|
||||
|
@@ -23,6 +23,8 @@ final class RssBridge
|
||||
$handler = $this->container[$actionName];
|
||||
|
||||
$middlewares = [
|
||||
new CacheMiddleware($this->container['cache']),
|
||||
new ExceptionMiddleware($this->container['logger']),
|
||||
new SecurityMiddleware(),
|
||||
new MaintenanceMiddleware(),
|
||||
new BasicAuthMiddleware(),
|
||||
@@ -34,6 +36,6 @@ final class RssBridge
|
||||
foreach (array_reverse($middlewares) as $middleware) {
|
||||
$action = fn ($req) => $middleware($req, $action);
|
||||
}
|
||||
return $action($request);
|
||||
return $action($request->withAttribute('action', $actionName));
|
||||
}
|
||||
}
|
||||
|
@@ -56,22 +56,14 @@ $container['logger'] = function () {
|
||||
// $logger->addHandler(new StreamHandler('/tmp/rss-bridge.txt', Logger::INFO));
|
||||
|
||||
// Uncomment this for debug logging to fs
|
||||
//$logger->addHandler(new StreamHandler('/tmp/rss-bridge-debug.txt', Logger::DEBUG));
|
||||
// $logger->addHandler(new StreamHandler('/tmp/rss-bridge-debug.txt', Logger::DEBUG));
|
||||
return $logger;
|
||||
};
|
||||
|
||||
$container['cache'] = function ($c) {
|
||||
/** @var CacheFactory $cacheFactory */
|
||||
$cacheFactory = $c['cache_factory'];
|
||||
$type = Configuration::getConfig('cache', 'type');
|
||||
if (!$type) {
|
||||
throw new \Exception('No cache type configured');
|
||||
}
|
||||
if (Debug::isEnabled()) {
|
||||
$cache = $cacheFactory->create('array');
|
||||
} else {
|
||||
$cache = $cacheFactory->create($type);
|
||||
}
|
||||
$cache = $cacheFactory->create(Configuration::getConfig('cache', 'type'));
|
||||
return $cache;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user