Make controllers get parameters from constructor

This commit is contained in:
Yassine Guedidi
2025-11-23 02:16:01 +01:00
parent da8254ab18
commit cf57bb3ed1
22 changed files with 110 additions and 44 deletions

View File

@@ -20,7 +20,13 @@ services:
$encryptionKeyPath: "%wallabag.site_credentials.encryption_key_path%"
$fetchingErrorMessageTitle: "%wallabag.fetching_error_message_title%"
$fetchingErrorMessage: '%wallabag.fetching_error_message%'
$version: "%wallabag.version%"
$paypalUrl: "%wallabag.paypal_url%"
$languages: '%wallabag.languages%'
$feedLimit: "%wallabag.feed_limit%"
$apiLimitMassActions: "%wallabag.api_limit_mass_actions%"
$allowMimetypes: "%wallabag.allow_mimetypes%"
$resourceDir: "%wallabag.resource_dir%"
$lifeTime: '%wallabag.cache_lifetime%'
$logoPath: 'web/img/appicon/apple-touch-icon-152.png'
$registrationEnabled: '%fosuser_registration%'
@@ -32,6 +38,7 @@ services:
$fonts: '%wallabag.fonts%'
$defaultIgnoreOriginInstanceRules: '%wallabag.default_ignore_origin_instance_rules%'
$defaultUserAgent: "%wallabag_user_agent%"
$addonsUrl: "%addons_url%"
Wallabag\:
resource: '../../src/*'

View File

@@ -539,9 +539,7 @@ class EntryRestController extends WallabagRestController
{
$urls = json_decode($request->query->get('urls', '[]'));
$limit = $this->getParameter('wallabag.api_limit_mass_actions');
if (\count($urls) > $limit) {
if (\count($urls) > $this->apiLimitMassActions) {
throw new BadRequestHttpException('API limit reached');
}
@@ -1067,7 +1065,7 @@ class EntryRestController extends WallabagRestController
}
// if refreshing entry failed, don't save it
if ($this->getParameter('wallabag.fetching_error_message') === $entry->getContent()) {
if ($this->fetchingErrorMessage === $entry->getContent()) {
return new JsonResponse([], 304);
}

View File

@@ -28,6 +28,9 @@ class WallabagRestController extends AbstractFOSRestController
protected TokenStorageInterface $tokenStorage,
protected TranslatorInterface $translator,
protected bool $registrationEnabled,
protected string $version,
protected int $apiLimitMassActions,
protected string $fetchingErrorMessage,
) {
}
@@ -55,8 +58,7 @@ class WallabagRestController extends AbstractFOSRestController
#[Route(path: '/api/version.{_format}', name: 'api_get_version', methods: ['GET'], defaults: ['_format' => 'json'])]
public function getVersionAction()
{
$version = $this->getParameter('wallabag.version');
$json = $this->serializer->serialize($version, 'json');
$json = $this->serializer->serialize($this->version, 'json');
return (new JsonResponse())->setJson($json);
}
@@ -78,7 +80,7 @@ class WallabagRestController extends AbstractFOSRestController
public function getInfoAction(Config $craueConfig)
{
$info = new ApplicationInfo(
$this->getParameter('wallabag.version'),
$this->version,
$this->registrationEnabled && $craueConfig->get('api_user_registration'),
);

View File

@@ -43,6 +43,7 @@ class EntryController extends AbstractController
private readonly FilterBuilderUpdaterInterface $filterBuilderUpdater,
private readonly ContentProxy $contentProxy,
private readonly Security $security,
private readonly string $fetchingErrorMessage,
) {
}
@@ -411,7 +412,7 @@ class EntryController extends AbstractController
$this->updateEntry($entry, 'entry_reloaded');
// if refreshing entry failed, don't save it
if ($this->getParameter('wallabag.fetching_error_message') === $entry->getContent()) {
if ($this->fetchingErrorMessage === $entry->getContent()) {
$this->addFlash('notice', 'flashes.entry.notice.entry_reloaded_failed');
return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()]));

View File

@@ -22,6 +22,8 @@ class FeedController extends AbstractController
{
public function __construct(
private readonly EntryRepository $entryRepository,
private readonly int $feedLimit,
private readonly string $version,
) {
}
@@ -122,7 +124,7 @@ class FeedController extends AbstractController
$user
);
$perPage = $user->getConfig()->getFeedLimit() ?: $this->getParameter('wallabag.feed_limit');
$perPage = $user->getConfig()->getFeedLimit() ?: $this->feedLimit;
$entries->setMaxPerPage($perPage);
try {
@@ -140,7 +142,7 @@ class FeedController extends AbstractController
'url' => $url,
'entries' => $entries,
'user' => $user->getUsername(),
'version' => $this->getParameter('wallabag.version'),
'version' => $this->version,
'tag' => $tag->getSlug(),
'updated' => $this->prepareFeedUpdatedDate($entries, $sort),
],
@@ -186,7 +188,7 @@ class FeedController extends AbstractController
$pagerAdapter = new DoctrineORMAdapter($qb->getQuery(), true, false);
$entries = new Pagerfanta($pagerAdapter);
$perPage = $user->getConfig()->getFeedLimit() ?: $this->getParameter('wallabag.feed_limit');
$perPage = $user->getConfig()->getFeedLimit() ?: $this->feedLimit;
$entries->setMaxPerPage($perPage);
$url = $this->generateUrl(
@@ -211,7 +213,7 @@ class FeedController extends AbstractController
'url' => $url,
'entries' => $entries,
'user' => $user->getUsername(),
'version' => $this->getParameter('wallabag.version'),
'version' => $this->version,
'updated' => $this->prepareFeedUpdatedDate($entries),
], new Response('', 200, ['Content-Type' => 'application/atom+xml']));
}

View File

@@ -13,6 +13,12 @@ use Wallabag\Import\ImportInterface;
abstract class BrowserController extends AbstractController
{
public function __construct(
protected readonly array $allowMimetypes,
protected readonly string $resourceDir,
) {
}
/**
* @return Response
*/
@@ -31,9 +37,9 @@ abstract class BrowserController extends AbstractController
$markAsRead = $form->get('mark_as_read')->getData();
$name = $this->getUser()->getId() . '.json';
if (null !== $file && \in_array($file->getClientMimeType(), $this->getParameter('wallabag.allow_mimetypes'), true) && $file->move($this->getParameter('wallabag.resource_dir'), $name)) {
if (null !== $file && \in_array($file->getClientMimeType(), $this->allowMimetypes, true) && $file->move($this->resourceDir, $name)) {
$res = $wallabag
->setFilepath($this->getParameter('wallabag.resource_dir') . '/' . $name)
->setFilepath($this->resourceDir . '/' . $name)
->setMarkAsRead($markAsRead)
->import();
@@ -52,7 +58,7 @@ abstract class BrowserController extends AbstractController
]);
}
unlink($this->getParameter('wallabag.resource_dir') . '/' . $name);
unlink($this->resourceDir . '/' . $name);
}
$this->addFlash('notice', $message);

View File

@@ -18,7 +18,10 @@ class ChromeController extends BrowserController
private readonly Config $craueConfig,
private readonly RabbitMqProducer $rabbitMqProducer,
private readonly RedisProducer $redisProducer,
array $allowMimetypes,
string $resourceDir,
) {
parent::__construct($allowMimetypes, $resourceDir);
}
#[Route(path: '/import/chrome', name: 'import_chrome', methods: ['GET', 'POST'])]

View File

@@ -18,6 +18,8 @@ class DeliciousController extends AbstractController
public function __construct(
private readonly RabbitMqProducer $rabbitMqProducer,
private readonly RedisProducer $redisProducer,
private readonly array $allowMimetypes,
private readonly string $resourceDir,
) {
}
@@ -41,9 +43,9 @@ class DeliciousController extends AbstractController
$markAsRead = $form->get('mark_as_read')->getData();
$name = 'delicious_' . $this->getUser()->getId() . '.json';
if (null !== $file && \in_array($file->getClientMimeType(), $this->getParameter('wallabag.allow_mimetypes'), true) && $file->move($this->getParameter('wallabag.resource_dir'), $name)) {
if (null !== $file && \in_array($file->getClientMimeType(), $this->allowMimetypes, true) && $file->move($this->resourceDir, $name)) {
$res = $delicious
->setFilepath($this->getParameter('wallabag.resource_dir') . '/' . $name)
->setFilepath($this->resourceDir . '/' . $name)
->setMarkAsRead($markAsRead)
->import();
@@ -62,7 +64,7 @@ class DeliciousController extends AbstractController
]);
}
unlink($this->getParameter('wallabag.resource_dir') . '/' . $name);
unlink($this->resourceDir . '/' . $name);
}
$this->addFlash('notice', $message);

View File

@@ -18,7 +18,10 @@ class ElcuratorController extends WallabagController
private readonly Config $craueConfig,
private readonly RabbitMqProducer $rabbitMqProducer,
private readonly RedisProducer $redisProducer,
array $allowMimetypes,
string $resourceDir,
) {
parent::__construct($allowMimetypes, $resourceDir);
}
#[Route(path: '/import/elcurator', name: 'import_elcurator', methods: ['GET', 'POST'])]

View File

@@ -18,7 +18,10 @@ class FirefoxController extends BrowserController
private readonly Config $craueConfig,
private readonly RabbitMqProducer $rabbitMqProducer,
private readonly RedisProducer $redisProducer,
array $allowMimetypes,
string $resourceDir,
) {
parent::__construct($allowMimetypes, $resourceDir);
}
#[Route(path: '/import/firefox', name: 'import_firefox', methods: ['GET', 'POST'])]

View File

@@ -13,6 +13,12 @@ use Wallabag\Import\ImportInterface;
abstract class HtmlController extends AbstractController
{
public function __construct(
protected readonly array $allowMimetypes,
protected readonly string $resourceDir,
) {
}
/**
* @return Response
*/
@@ -31,9 +37,9 @@ abstract class HtmlController extends AbstractController
$markAsRead = $form->get('mark_as_read')->getData();
$name = $this->getUser()->getId() . '.html';
if (null !== $file && \in_array($file->getClientMimeType(), $this->getParameter('wallabag.allow_mimetypes'), true) && $file->move($this->getParameter('wallabag.resource_dir'), $name)) {
if (null !== $file && \in_array($file->getClientMimeType(), $this->allowMimetypes, true) && $file->move($this->resourceDir, $name)) {
$res = $wallabag
->setFilepath($this->getParameter('wallabag.resource_dir') . '/' . $name)
->setFilepath($this->resourceDir . '/' . $name)
->setMarkAsRead($markAsRead)
->import();
@@ -52,7 +58,7 @@ abstract class HtmlController extends AbstractController
]);
}
unlink($this->getParameter('wallabag.resource_dir') . '/' . $name);
unlink($this->resourceDir . '/' . $name);
}
$this->addFlash('notice', $message);

View File

@@ -18,6 +18,8 @@ class InstapaperController extends AbstractController
public function __construct(
private readonly RabbitMqProducer $rabbitMqProducer,
private readonly RedisProducer $redisProducer,
private readonly array $allowMimetypes,
private readonly string $resourceDir,
) {
}
@@ -41,9 +43,9 @@ class InstapaperController extends AbstractController
$markAsRead = $form->get('mark_as_read')->getData();
$name = 'instapaper_' . $this->getUser()->getId() . '.csv';
if (null !== $file && \in_array($file->getClientMimeType(), $this->getParameter('wallabag.allow_mimetypes'), true) && $file->move($this->getParameter('wallabag.resource_dir'), $name)) {
if (null !== $file && \in_array($file->getClientMimeType(), $this->allowMimetypes, true) && $file->move($this->resourceDir, $name)) {
$res = $instapaper
->setFilepath($this->getParameter('wallabag.resource_dir') . '/' . $name)
->setFilepath($this->resourceDir . '/' . $name)
->setMarkAsRead($markAsRead)
->import();
@@ -62,7 +64,7 @@ class InstapaperController extends AbstractController
]);
}
unlink($this->getParameter('wallabag.resource_dir') . '/' . $name);
unlink($this->resourceDir . '/' . $name);
}
$this->addFlash('notice', $message);

View File

@@ -18,6 +18,8 @@ class OmnivoreController extends AbstractController
public function __construct(
private readonly RabbitMqProducer $rabbitMqProducer,
private readonly RedisProducer $redisProducer,
private readonly array $allowMimetypes,
private readonly string $resourceDir,
) {
}
@@ -41,9 +43,9 @@ class OmnivoreController extends AbstractController
$markAsRead = $form->get('mark_as_read')->getData();
$name = 'omnivore_' . $this->getUser()->getId() . '.json';
if (null !== $file && \in_array($file->getClientMimeType(), $this->getParameter('wallabag.allow_mimetypes'), true) && $file->move($this->getParameter('wallabag.resource_dir'), $name)) {
if (null !== $file && \in_array($file->getClientMimeType(), $this->allowMimetypes, true) && $file->move($this->resourceDir, $name)) {
$res = $omnivore
->setFilepath($this->getParameter('wallabag.resource_dir') . '/' . $name)
->setFilepath($this->resourceDir . '/' . $name)
->setMarkAsRead($markAsRead)
->import();
@@ -62,7 +64,7 @@ class OmnivoreController extends AbstractController
]);
}
unlink($this->getParameter('wallabag.resource_dir') . '/' . $name);
unlink($this->resourceDir . '/' . $name);
}
$this->addFlash('notice', $message);

View File

@@ -18,6 +18,8 @@ class PinboardController extends AbstractController
public function __construct(
private readonly RabbitMqProducer $rabbitMqProducer,
private readonly RedisProducer $redisProducer,
private readonly array $allowMimetypes,
private readonly string $resourceDir,
) {
}
@@ -41,9 +43,9 @@ class PinboardController extends AbstractController
$markAsRead = $form->get('mark_as_read')->getData();
$name = 'pinboard_' . $this->getUser()->getId() . '.json';
if (null !== $file && \in_array($file->getClientMimeType(), $this->getParameter('wallabag.allow_mimetypes'), true) && $file->move($this->getParameter('wallabag.resource_dir'), $name)) {
if (null !== $file && \in_array($file->getClientMimeType(), $this->allowMimetypes, true) && $file->move($this->resourceDir, $name)) {
$res = $pinboard
->setFilepath($this->getParameter('wallabag.resource_dir') . '/' . $name)
->setFilepath($this->resourceDir . '/' . $name)
->setMarkAsRead($markAsRead)
->import();
@@ -62,7 +64,7 @@ class PinboardController extends AbstractController
]);
}
unlink($this->getParameter('wallabag.resource_dir') . '/' . $name);
unlink($this->resourceDir . '/' . $name);
}
$this->addFlash('notice', $message);

View File

@@ -20,6 +20,8 @@ class PocketCsvController extends AbstractController
private readonly Config $craueConfig,
private readonly RabbitMqProducer $rabbitMqProducer,
private readonly RedisProducer $redisProducer,
private readonly array $allowMimetypes,
private readonly string $resourceDir,
) {
}
@@ -43,9 +45,9 @@ class PocketCsvController extends AbstractController
$markAsRead = $form->get('mark_as_read')->getData();
$name = 'pocket_' . $this->getUser()->getId() . '.csv';
if (null !== $file && \in_array($file->getClientMimeType(), $this->getParameter('wallabag.allow_mimetypes'), true) && $file->move($this->getParameter('wallabag.resource_dir'), $name)) {
if (null !== $file && \in_array($file->getClientMimeType(), $this->allowMimetypes, true) && $file->move($this->resourceDir, $name)) {
$res = $this->pocketCsvImport
->setFilepath($this->getParameter('wallabag.resource_dir') . '/' . $name)
->setFilepath($this->resourceDir . '/' . $name)
->setMarkAsRead($markAsRead)
->import();
@@ -64,7 +66,7 @@ class PocketCsvController extends AbstractController
]);
}
unlink($this->getParameter('wallabag.resource_dir') . '/' . $name);
unlink($this->resourceDir . '/' . $name);
}
$this->addFlash('notice', $message);

View File

@@ -18,7 +18,10 @@ class PocketHtmlController extends HtmlController
private readonly Config $craueConfig,
private readonly RabbitMqProducer $rabbitMqProducer,
private readonly RedisProducer $redisProducer,
array $allowMimetypes,
string $resourceDir,
) {
parent::__construct($allowMimetypes, $resourceDir);
}
#[Route(path: '/import/pocket_html', name: 'import_pocket_html', methods: ['GET', 'POST'])]

View File

@@ -18,6 +18,8 @@ class ReadabilityController extends AbstractController
public function __construct(
private readonly RabbitMqProducer $rabbitMqProducer,
private readonly RedisProducer $redisProducer,
private readonly array $allowMimetypes,
private readonly string $resourceDir,
) {
}
@@ -41,9 +43,9 @@ class ReadabilityController extends AbstractController
$markAsRead = $form->get('mark_as_read')->getData();
$name = 'readability_' . $this->getUser()->getId() . '.json';
if (null !== $file && \in_array($file->getClientMimeType(), $this->getParameter('wallabag.allow_mimetypes'), true) && $file->move($this->getParameter('wallabag.resource_dir'), $name)) {
if (null !== $file && \in_array($file->getClientMimeType(), $this->allowMimetypes, true) && $file->move($this->resourceDir, $name)) {
$res = $readability
->setFilepath($this->getParameter('wallabag.resource_dir') . '/' . $name)
->setFilepath($this->resourceDir . '/' . $name)
->setMarkAsRead($markAsRead)
->import();
@@ -62,7 +64,7 @@ class ReadabilityController extends AbstractController
]);
}
unlink($this->getParameter('wallabag.resource_dir') . '/' . $name);
unlink($this->resourceDir . '/' . $name);
}
$this->addFlash('notice', $message);

View File

@@ -18,7 +18,10 @@ class ShaarliController extends HtmlController
private readonly Config $craueConfig,
private readonly RabbitMqProducer $rabbitMqProducer,
private readonly RedisProducer $redisProducer,
array $allowMimetypes,
string $resourceDir,
) {
parent::__construct($allowMimetypes, $resourceDir);
}
#[Route(path: '/import/shaarli', name: 'import_shaarli', methods: ['GET', 'POST'])]

View File

@@ -15,6 +15,12 @@ use Wallabag\Import\ImportInterface;
*/
abstract class WallabagController extends AbstractController
{
public function __construct(
protected readonly array $allowMimetypes,
protected readonly string $resourceDir,
) {
}
/**
* Handle import request.
*
@@ -33,9 +39,9 @@ abstract class WallabagController extends AbstractController
$markAsRead = $form->get('mark_as_read')->getData();
$name = $this->getUser()->getId() . '.json';
if (null !== $file && \in_array($file->getClientMimeType(), $this->getParameter('wallabag.allow_mimetypes'), true) && $file->move($this->getParameter('wallabag.resource_dir'), $name)) {
if (null !== $file && \in_array($file->getClientMimeType(), $this->allowMimetypes, true) && $file->move($this->resourceDir, $name)) {
$res = $wallabag
->setFilepath($this->getParameter('wallabag.resource_dir') . '/' . $name)
->setFilepath($this->resourceDir . '/' . $name)
->setMarkAsRead($markAsRead)
->import();
@@ -54,7 +60,7 @@ abstract class WallabagController extends AbstractController
]);
}
unlink($this->getParameter('wallabag.resource_dir') . '/' . $name);
unlink($this->resourceDir . '/' . $name);
}
$this->addFlash('notice', $message);

View File

@@ -18,7 +18,10 @@ class WallabagV1Controller extends WallabagController
private readonly Config $craueConfig,
private readonly RabbitMqProducer $rabbitMqProducer,
private readonly RedisProducer $redisProducer,
array $allowMimetypes,
string $resourceDir,
) {
parent::__construct($allowMimetypes, $resourceDir);
}
#[Route(path: '/import/wallabag-v1', name: 'import_wallabag_v1', methods: ['GET', 'POST'])]

View File

@@ -18,7 +18,10 @@ class WallabagV2Controller extends WallabagController
private readonly Config $craueConfig,
private readonly RabbitMqProducer $rabbitMqProducer,
private readonly RedisProducer $redisProducer,
array $allowMimetypes,
string $resourceDir,
) {
parent::__construct($allowMimetypes, $resourceDir);
}
#[Route(path: '/import/wallabag-v2', name: 'import_wallabag_v2', methods: ['GET', 'POST'])]

View File

@@ -7,16 +7,21 @@ use Symfony\Component\Routing\Annotation\Route;
class StaticController extends AbstractController
{
public function __construct(
private readonly array $addonsUrl,
private readonly string $version,
private readonly string $paypalUrl,
) {
}
#[Route(path: '/howto', name: 'howto', methods: ['GET'])]
#[IsGranted('IS_AUTHENTICATED_FULLY')]
public function howtoAction()
{
$addonsUrl = $this->getParameter('addons_url');
return $this->render(
'Static/howto.html.twig',
[
'addonsUrl' => $addonsUrl,
'addonsUrl' => $this->addonsUrl,
]
);
}
@@ -28,8 +33,8 @@ class StaticController extends AbstractController
return $this->render(
'Static/about.html.twig',
[
'version' => $this->getParameter('wallabag.version'),
'paypal_url' => $this->getParameter('wallabag.paypal_url'),
'version' => $this->version,
'paypal_url' => $this->paypalUrl,
]
);
}