diff options
author | 2024-09-01 21:48:14 +0200 | |
---|---|---|
committer | 2024-09-01 21:48:14 +0200 | |
commit | a6bdc322b01de91b7a9e27243b30a65caf2d3c5a (patch) | |
tree | 7bcfa9d74912856df81f0d8f2a3345d0e15a3f11 /lib | |
parent | 36fd72c87e5e96923a61bc79aeff8cc97b950423 (diff) | |
download | rss-bridge-a6bdc322b01de91b7a9e27243b30a65caf2d3c5a.tar.gz rss-bridge-a6bdc322b01de91b7a9e27243b30a65caf2d3c5a.tar.zst rss-bridge-a6bdc322b01de91b7a9e27243b30a65caf2d3c5a.zip |
refactor: extract exception and cache middleware (#4248)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Configuration.php | 4 | ||||
-rw-r--r-- | lib/RssBridge.php | 4 | ||||
-rw-r--r-- | lib/dependencies.php | 12 |
3 files changed, 9 insertions, 11 deletions
diff --git a/lib/Configuration.php b/lib/Configuration.php index 44fd3612..187848fb 100644 --- a/lib/Configuration.php +++ b/lib/Configuration.php @@ -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'); } diff --git a/lib/RssBridge.php b/lib/RssBridge.php index 5e90fb13..c7b132d6 100644 --- a/lib/RssBridge.php +++ b/lib/RssBridge.php @@ -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)); } } diff --git a/lib/dependencies.php b/lib/dependencies.php index 227a66f1..45ae5d61 100644 --- a/lib/dependencies.php +++ b/lib/dependencies.php @@ -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; }; |