mirror of
https://github.com/wallabag/wallabag.git
synced 2025-09-15 18:57:05 +00:00
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:
parent
39f603e015
commit
6aca334d53
36 changed files with 855 additions and 699 deletions
|
@ -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\ChromeImport;
|
||||
use Wallabag\ImportBundle\Redis\Producer as RedisProducer;
|
||||
|
||||
class ChromeController extends BrowserController
|
||||
{
|
||||
private ChromeImport $chromeImport;
|
||||
private Config $craueConfig;
|
||||
private RabbitMqProducer $rabbitMqProducer;
|
||||
private RedisProducer $redisProducer;
|
||||
|
||||
public function __construct(ChromeImport $chromeImport, Config $craueConfig, RabbitMqProducer $rabbitMqProducer, RedisProducer $redisProducer)
|
||||
{
|
||||
$this->chromeImport = $chromeImport;
|
||||
$this->craueConfig = $craueConfig;
|
||||
$this->rabbitMqProducer = $rabbitMqProducer;
|
||||
$this->redisProducer = $redisProducer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/chrome", name="import_chrome")
|
||||
*/
|
||||
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 ChromeController extends BrowserController
|
|||
*/
|
||||
protected function getImportService()
|
||||
{
|
||||
$service = $this->get(ChromeImport::class);
|
||||
|
||||
if ($this->get(Config::class)->get('import_with_rabbitmq')) {
|
||||
$service->setProducer($this->get('old_sound_rabbit_mq.import_chrome_producer'));
|
||||
} elseif ($this->get(Config::class)->get('import_with_redis')) {
|
||||
$service->setProducer($this->get('wallabag_import.producer.redis.chrome'));
|
||||
if ($this->craueConfig->get('import_with_rabbitmq')) {
|
||||
$this->chromeImport->setProducer($this->rabbitMqProducer);
|
||||
} elseif ($this->craueConfig->get('import_with_redis')) {
|
||||
$this->chromeImport->setProducer($this->redisProducer);
|
||||
}
|
||||
|
||||
return $service;
|
||||
return $this->chromeImport;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue