1
0
mirror of https://github.com/RSS-Bridge/rss-bridge.git synced 2025-07-30 21:30:14 +02:00

refactor: introduce DI container (#4238)

* refactor: introduce DI container

* add bin/test
This commit is contained in:
Dag
2024-08-29 22:48:59 +02:00
committed by GitHub
parent e010fd4d52
commit 58544cd61a
18 changed files with 231 additions and 89 deletions

View File

@@ -2,18 +2,12 @@
final class RssBridge
{
private static Logger $logger;
private static CacheInterface $cache;
private static HttpClient $httpClient;
private static Container $container;
public function __construct(
Logger $logger,
CacheInterface $cache,
HttpClient $httpClient
Container $container
) {
self::$logger = $logger;
self::$cache = $cache;
self::$httpClient = $httpClient;
self::$container = $container;
}
public function main(Request $request): Response
@@ -83,10 +77,9 @@ final class RssBridge
return new Response(render(__DIR__ . '/../templates/error.html.php', ['message' => 'Invalid action']), 400);
}
$className = '\\' . $actionName;
$actionObject = new $className();
$controller = self::$container[$actionName];
$response = $actionObject($request);
$response = $controller($request);
return $response;
}
@@ -94,16 +87,16 @@ final class RssBridge
public static function getLogger(): Logger
{
// null logger is only for the tests not to fail
return self::$logger ?? new NullLogger();
return self::$container['logger'] ?? new NullLogger();
}
public static function getCache(): CacheInterface
{
return self::$cache;
return self::$container['cache'];
}
public static function getHttpClient(): HttpClient
{
return self::$httpClient;
return self::$container['http_client'];
}
}