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
|
@ -21,8 +21,6 @@ class ExportController extends Controller
|
|||
/**
|
||||
* Gets one entry content.
|
||||
*
|
||||
* @param string $format
|
||||
*
|
||||
* @Route("/export/{id}.{format}", name="export_entry", requirements={
|
||||
* "format": "epub|mobi|pdf|json|xml|txt|csv",
|
||||
* "id": "\d+"
|
||||
|
@ -30,10 +28,10 @@ class ExportController extends Controller
|
|||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function downloadEntryAction(Entry $entry, $format)
|
||||
public function downloadEntryAction(Entry $entry, EntriesExport $entriesExport, string $format)
|
||||
{
|
||||
try {
|
||||
return $this->get(EntriesExport::class)
|
||||
return $entriesExport
|
||||
->setEntries($entry)
|
||||
->updateTitle('entry')
|
||||
->updateAuthor('entry')
|
||||
|
@ -46,9 +44,6 @@ class ExportController extends Controller
|
|||
/**
|
||||
* Export all entries for current user.
|
||||
*
|
||||
* @param string $format
|
||||
* @param string $category
|
||||
*
|
||||
* @Route("/export/{category}.{format}", name="export_entries", requirements={
|
||||
* "format": "epub|mobi|pdf|json|xml|txt|csv",
|
||||
* "category": "all|unread|starred|archive|tag_entries|untagged|search|annotated|same_domain"
|
||||
|
@ -56,17 +51,16 @@ class ExportController extends Controller
|
|||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function downloadEntriesAction(Request $request, $format, $category)
|
||||
public function downloadEntriesAction(Request $request, EntryRepository $entryRepository, TagRepository $tagRepository, EntriesExport $entriesExport, string $format, string $category)
|
||||
{
|
||||
$method = ucfirst($category);
|
||||
$methodBuilder = 'getBuilderFor' . $method . 'ByUser';
|
||||
$repository = $this->get(EntryRepository::class);
|
||||
$title = $method;
|
||||
|
||||
if ('tag_entries' === $category) {
|
||||
$tag = $this->get(TagRepository::class)->findOneBySlug($request->query->get('tag'));
|
||||
$tag = $tagRepository->findOneBySlug($request->query->get('tag'));
|
||||
|
||||
$entries = $repository->findAllByTagId(
|
||||
$entries = $entryRepository->findAllByTagId(
|
||||
$this->getUser()->getId(),
|
||||
$tag->getId()
|
||||
);
|
||||
|
@ -76,7 +70,7 @@ class ExportController extends Controller
|
|||
$searchTerm = (isset($request->get('search_entry')['term']) ? $request->get('search_entry')['term'] : '');
|
||||
$currentRoute = (null !== $request->query->get('currentRoute') ? $request->query->get('currentRoute') : '');
|
||||
|
||||
$entries = $repository->getBuilderForSearchByUser(
|
||||
$entries = $entryRepository->getBuilderForSearchByUser(
|
||||
$this->getUser()->getId(),
|
||||
$searchTerm,
|
||||
$currentRoute
|
||||
|
@ -85,21 +79,21 @@ class ExportController extends Controller
|
|||
|
||||
$title = 'Search ' . $searchTerm;
|
||||
} elseif ('annotated' === $category) {
|
||||
$entries = $repository->getBuilderForAnnotationsByUser(
|
||||
$entries = $entryRepository->getBuilderForAnnotationsByUser(
|
||||
$this->getUser()->getId()
|
||||
)->getQuery()
|
||||
->getResult();
|
||||
|
||||
$title = 'With annotations';
|
||||
} else {
|
||||
$entries = $repository
|
||||
$entries = $entryRepository
|
||||
->$methodBuilder($this->getUser()->getId())
|
||||
->getQuery()
|
||||
->getResult();
|
||||
}
|
||||
|
||||
try {
|
||||
return $this->get(EntriesExport::class)
|
||||
return $entriesExport
|
||||
->setEntries($entries)
|
||||
->updateTitle($title)
|
||||
->updateAuthor($method)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue