mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-08-03 09:35:57 +02:00
refactor: introduce DI container (#4238)
* refactor: introduce DI container * add bin/test
This commit is contained in:
parent
e010fd4d52
commit
58544cd61a
18 changed files with 231 additions and 89 deletions
78
lib/dependencies.php
Normal file
78
lib/dependencies.php
Normal file
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
$container = new Container();
|
||||
|
||||
$container[ConnectivityAction::class] = function ($c) {
|
||||
return new ConnectivityAction($c['bridge_factory']);
|
||||
};
|
||||
|
||||
$container[DetectAction::class] = function ($c) {
|
||||
return new DetectAction($c['bridge_factory']);
|
||||
};
|
||||
|
||||
$container[DisplayAction::class] = function ($c) {
|
||||
return new DisplayAction($c['cache'], $c['logger'], $c['bridge_factory']);
|
||||
};
|
||||
|
||||
$container[FindfeedAction::class] = function ($c) {
|
||||
return new FindfeedAction($c['bridge_factory']);
|
||||
};
|
||||
|
||||
$container[FrontpageAction::class] = function ($c) {
|
||||
return new FrontpageAction($c['bridge_factory']);
|
||||
};
|
||||
|
||||
$container[HealthAction::class] = function () {
|
||||
return new HealthAction();
|
||||
};
|
||||
|
||||
$container[ListAction::class] = function ($c) {
|
||||
return new ListAction($c['bridge_factory']);
|
||||
};
|
||||
|
||||
$container['bridge_factory'] = function ($c) {
|
||||
return new BridgeFactory($c['cache'], $c['logger']);
|
||||
};
|
||||
|
||||
|
||||
$container['http_client'] = function () {
|
||||
return new CurlHttpClient();
|
||||
};
|
||||
|
||||
$container['cache_factory'] = function ($c) {
|
||||
return new CacheFactory($c['logger']);
|
||||
};
|
||||
|
||||
$container['logger'] = function () {
|
||||
$logger = new SimpleLogger('rssbridge');
|
||||
if (Debug::isEnabled()) {
|
||||
$logger->addHandler(new ErrorLogHandler(Logger::DEBUG));
|
||||
} else {
|
||||
$logger->addHandler(new ErrorLogHandler(Logger::INFO));
|
||||
}
|
||||
// Uncomment this for info logging to fs
|
||||
// $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));
|
||||
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);
|
||||
}
|
||||
return $cache;
|
||||
};
|
||||
|
||||
return $container;
|
Loading…
Add table
Add a link
Reference in a new issue