replace old method of getting translator with injection of translatorInterface

This commit is contained in:
2023-10-26 15:20:19 +02:00
parent cdfb084fe4
commit c6deb21606
7 changed files with 47 additions and 64 deletions

View File

@@ -22,39 +22,22 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
* Class ReportController.
*/
class ReportController extends AbstractController
{
/**
* @var AuthorizationHelper
*/
protected $authorizationHelper;
/**
* @var EventDispatcherInterface
*/
protected $eventDispatcher;
/**
* @var PaginatorFactory
*/
protected $paginator;
/**
* ReportController constructor.
*/
public function __construct(
EventDispatcherInterface $eventDispatcher,
AuthorizationHelper $authorizationHelper,
PaginatorFactory $paginator
) {
$this->eventDispatcher = $eventDispatcher;
$this->authorizationHelper = $authorizationHelper;
$this->paginator = $paginator;
}
private readonly EventDispatcherInterface $eventDispatcher,
private readonly AuthorizationHelper $authorizationHelper,
private readonly PaginatorFactory $paginator,
private readonly TranslatorInterface $translator
) {}
/**
* Create a new report for a given person and of a given type.
@@ -98,7 +81,7 @@ class ReportController extends AbstractController
->getFlashBag()
->add(
'success',
$this->get('translator')
$this->translator
->trans('Success : report created!')
);
@@ -108,7 +91,7 @@ class ReportController extends AbstractController
$this->get('session')
->getFlashBag()->add(
'error',
$this->get('translator')
$this->translator
->trans('The form is not valid. The report has not been created !')
);
@@ -135,11 +118,11 @@ class ReportController extends AbstractController
$report = $em->getRepository('ChillReportBundle:Report')->find($report_id);
if (!$report) {
throw $this->createNotFoundException($this->get('translator')->trans('Unable to find this report.'));
throw $this->createNotFoundException($this->translator->trans('Unable to find this report.'));
}
if ((int) $person_id !== (int) $report->getPerson()->getId()) {
throw new \RuntimeException($this->get('translator')->trans('This is not the report of the person.'), 1);
throw new \RuntimeException($this->translator->trans('This is not the report of the person.'), 1);
}
$this->denyAccessUnlessGranted('CHILL_REPORT_UPDATE', $report);
@@ -418,7 +401,7 @@ class ReportController extends AbstractController
$report = $em->getRepository('ChillReportBundle:Report')->find($report_id);
if (!$report) {
throw $this->createNotFoundException($this->get('translator')->trans('Unable to find this report.'));
throw $this->createNotFoundException($this->translator->trans('Unable to find this report.'));
}
$this->denyAccessUnlessGranted('CHILL_REPORT_UPDATE', $report);
@@ -433,7 +416,7 @@ class ReportController extends AbstractController
->getFlashBag()
->add(
'success',
$this->get('translator')
$this->translator
->trans('Success : report updated!')
);
@@ -453,7 +436,7 @@ class ReportController extends AbstractController
->getFlashBag()
->add(
'error',
$this->get('translator')
$this->translator
->trans('The form is not valid. The report has not been updated !')
);
@@ -480,7 +463,7 @@ class ReportController extends AbstractController
$entity = $em->getRepository('ChillReportBundle:Report')->find($report_id);
if (!$entity || !$person) {
throw $this->createNotFoundException($this->get('translator')->trans('Unable to find this report.'));
throw $this->createNotFoundException($this->translator->trans('Unable to find this report.'));
}
$this->denyAccessUnlessGranted('CHILL_REPORT_SEE', $entity);