forked from wallabag/wallabag
Move to controller as a service
Mostly using autowiring to inject deps. The only tricky part was for import because all producer use the same class and have a different alias. So we must write them down in the service definition, autowiring doesn't work in that case. Usually: - if a controller has a constructor, it means injected services are at least re-used once in actions - otherwise, service are injected per action
This commit is contained in:
@ -3,18 +3,34 @@
|
||||
namespace Wallabag\ImportBundle\Controller;
|
||||
|
||||
use Craue\ConfigBundle\Util\Config;
|
||||
use OldSound\RabbitMqBundle\RabbitMq\Producer as RabbitMqProducer;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use Wallabag\ImportBundle\Import\WallabagV2Import;
|
||||
use Wallabag\ImportBundle\Redis\Producer as RedisProducer;
|
||||
|
||||
class WallabagV2Controller extends WallabagController
|
||||
{
|
||||
private WallabagV2Import $wallabagImport;
|
||||
private Config $craueConfig;
|
||||
private RabbitMqProducer $rabbitMqProducer;
|
||||
private RedisProducer $redisProducer;
|
||||
|
||||
public function __construct(WallabagV2Import $wallabagImport, Config $craueConfig, RabbitMqProducer $rabbitMqProducer, RedisProducer $redisProducer)
|
||||
{
|
||||
$this->wallabagImport = $wallabagImport;
|
||||
$this->craueConfig = $craueConfig;
|
||||
$this->rabbitMqProducer = $rabbitMqProducer;
|
||||
$this->redisProducer = $redisProducer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/wallabag-v2", name="import_wallabag_v2")
|
||||
*/
|
||||
public function indexAction(Request $request)
|
||||
public function indexAction(Request $request, TranslatorInterface $translator)
|
||||
{
|
||||
return parent::indexAction($request);
|
||||
return parent::indexAction($request, $translator);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -22,15 +38,13 @@ class WallabagV2Controller extends WallabagController
|
||||
*/
|
||||
protected function getImportService()
|
||||
{
|
||||
$service = $this->get(WallabagV2Import::class);
|
||||
|
||||
if ($this->get(Config::class)->get('import_with_rabbitmq')) {
|
||||
$service->setProducer($this->get('old_sound_rabbit_mq.import_wallabag_v2_producer'));
|
||||
} elseif ($this->get(Config::class)->get('import_with_redis')) {
|
||||
$service->setProducer($this->get('wallabag_import.producer.redis.wallabag_v2'));
|
||||
if ($this->craueConfig->get('import_with_rabbitmq')) {
|
||||
$this->wallabagImport->setProducer($this->rabbitMqProducer);
|
||||
} elseif ($this->craueConfig->get('import_with_redis')) {
|
||||
$this->wallabagImport->setProducer($this->redisProducer);
|
||||
}
|
||||
|
||||
return $service;
|
||||
return $this->wallabagImport;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user