Skip to content

Commit

Permalink
Added Translator interface to abstract controller.
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentmuller committed Jun 7, 2022
1 parent d9abb97 commit d50bfab
Show file tree
Hide file tree
Showing 82 changed files with 327 additions and 398 deletions.
2 changes: 1 addition & 1 deletion all_batch.bat
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ php bin/console lint:xliff translations
php bin/console lint:container && ^
php bin/console doctrine:schema:validate --skip-sync --no-interaction && ^
ECHO -------------------------------------- PHP-CS-FIXER -------------------------------------- && ^
.\vendor-bin\php-cs-fixer\vendor\bin\php-cs-fixer.bat fix --diff --dry-run --quiet && ^
.\vendor-bin\php-cs-fixer\vendor\bin\php-cs-fixer.bat fix --diff --dry-run && ^
ECHO -------------------------------------- PHP-PSALM ----------------------------------------- && ^
.\vendor-bin\psalm\vendor\bin\psalm.bat --no-progress src && ^
ECHO -------------------------------------- PHP-STAN ------------------------------------------ && ^
Expand Down
28 changes: 14 additions & 14 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions public/css/colums.css
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,18 @@
.thead-light th.text-border {
border-left-color: #e9ecef !important;
}

.f-100 {
width: 100px;
}

.f-200 {
width: 200px;
}

.f-300 {
width: 200px;
}
.f-400 {
width: 400px;
}
2 changes: 2 additions & 0 deletions public/js/test/recaptcha.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ grecaptcha.ready(function () {
const $form = $('#edit-form');
const key = $form.data('key');
const action = $form.data('action');


grecaptcha.execute(key, {
action: action
}).then(function (token) {
Expand Down
2 changes: 1 addition & 1 deletion src/Captcha/AbstractAlphaCaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ abstract class AbstractAlphaCaptcha implements AlphaCaptchaInterface
*/
public function __construct(protected DictionaryService $dictionary, TranslatorInterface $translator)
{
$this->setTranslator($translator);
$this->translator = $translator;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Chart/BaseChart.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class BaseChart extends Highchart
public function __construct(protected ApplicationService $application, ThemeService $service, TranslatorInterface $translator)
{
parent::__construct();
$this->setTranslator($translator);
$this->translator = $translator;
$this->darkTheme = $service->isDarkTheme();

$this->hideCredits()
Expand Down
4 changes: 3 additions & 1 deletion src/Controller/AboutController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\Intl\Locales;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;

/**
* Controller for application information.
Expand All @@ -44,8 +45,9 @@ class AboutController extends AbstractController
*
* @param string $appMode the application mode
*/
public function __construct(private readonly string $appMode)
public function __construct(TranslatorInterface $translator, private readonly string $appMode)
{
parent::__construct($translator);
}

/**
Expand Down
30 changes: 9 additions & 21 deletions src/Controller/AbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
use App\Spreadsheet\SpreadsheetDocument;
use App\Traits\TranslatorFlashMessageTrait;
use App\Util\Utils;
use Psr\Container\ContainerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController as BaseController;
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\FormInterface;
Expand Down Expand Up @@ -70,6 +69,14 @@ abstract class AbstractController extends BaseController
*/
protected ?UserService $userService = null;

/**
* Constructor.
*/
public function __construct(TranslatorInterface $translator)
{
$this->translator = $translator;
}

/**
* Gets the address from (email and name) used to send email.
*/
Expand Down Expand Up @@ -158,10 +165,6 @@ public static function getSubscribedServices(): array
*/
public function getTranslator(): TranslatorInterface
{
if (null === $this->translator) {
$this->translator = $this->getService(TranslatorInterface::class);
}

return $this->translator;
}

Expand Down Expand Up @@ -233,19 +236,6 @@ public function redirectToHomePage(): RedirectResponse
return $this->redirectToRoute(self::HOME_PAGE);
}

/**
* {@inheritDoc}
*/
public function setContainer(ContainerInterface $container): ?ContainerInterface
{
$previous = parent::setContainer($container);
if (null === $this->translator) {
$this->setTranslator($this->getService(TranslatorInterface::class));
}

return $previous;
}

/**
* {@inheritDoc} Override the parent function to allow to use the default type like defined in the <code>FormFactoryInterface</code>.
*
Expand Down Expand Up @@ -333,9 +323,6 @@ protected function getRequestString(Request $request, string $key, string $defau
* @template T
* @psalm-param class-string<T> $id
* @psalm-return T
*
* @throws \Psr\Container\NotFoundExceptionInterface no entry was found for the identifier
* @throws \Psr\Container\ContainerExceptionInterface error while retrieving the entry
*/
protected function getService(string $id): mixed
{
Expand Down Expand Up @@ -445,6 +432,7 @@ protected function renderPdfDocument(PdfDocument $doc, bool $inline = true, stri
* @param string $name the name of the Spreadsheet file or null to use default ('document.xlsx')
*
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException if the report can not be rendered
* @throws \PhpOffice\PhpSpreadsheet\Exception
*/
protected function renderSpreadsheetDocument(SpreadsheetDocument $doc, bool $inline = true, string $name = ''): SpreadsheetResponse
{
Expand Down
4 changes: 3 additions & 1 deletion src/Controller/AbstractEntityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Contracts\Translation\TranslatorInterface;

/**
* Abstract controller for entities management.
Expand All @@ -52,8 +53,9 @@ abstract class AbstractEntityController extends AbstractController
*
* @param AbstractRepository<T> $repository
*/
public function __construct(protected AbstractRepository $repository)
public function __construct(TranslatorInterface $translator, protected AbstractRepository $repository)
{
parent::__construct($translator);
$this->className = $repository->getClassName();
$this->lowerName = \strtolower(Utils::getShortName($this->className));
}
Expand Down
5 changes: 3 additions & 2 deletions src/Controller/CalculationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

/**
* Controller for calculation entities.
Expand All @@ -50,9 +51,9 @@ class CalculationController extends AbstractEntityController
/**
* Constructor.
*/
public function __construct(CalculationRepository $repository, private readonly CalculationService $service, private readonly TaskRepository $taskRepository)
public function __construct(TranslatorInterface $translator, CalculationRepository $repository, private readonly CalculationService $service, private readonly TaskRepository $taskRepository)
{
parent::__construct($repository);
parent::__construct($translator, $repository);
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/Controller/CalculationStateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;

/**
* Controller for calculation state entities.
Expand All @@ -43,9 +44,9 @@ class CalculationStateController extends AbstractEntityController
/**
* Constructor.
*/
public function __construct(CalculationStateRepository $repository)
public function __construct(TranslatorInterface $translator, CalculationStateRepository $repository)
{
parent::__construct($repository);
parent::__construct($translator, $repository);
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/Controller/CategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;

/**
* The controller for category entities.
Expand All @@ -45,9 +46,9 @@ class CategoryController extends AbstractEntityController
/**
* Constructor.
*/
public function __construct(CategoryRepository $repository)
public function __construct(TranslatorInterface $translator, CategoryRepository $repository)
{
parent::__construct($repository);
parent::__construct($translator, $repository);
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/Controller/CustomerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;

/**
* The controller for customer entities.
Expand All @@ -43,9 +44,9 @@ class CustomerController extends AbstractEntityController
/**
* Constructor.
*/
public function __construct(CustomerRepository $repository)
public function __construct(TranslatorInterface $translator, CustomerRepository $repository)
{
parent::__construct($repository);
parent::__construct($translator, $repository);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/Controller/ExchangeRateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;

/**
* Controller for the exchange rate service.
Expand All @@ -32,8 +33,9 @@ class ExchangeRateController extends AbstractController
/**
* Constructor.
*/
public function __construct(private readonly ExchangeRateService $service)
public function __construct(TranslatorInterface $translator, private readonly ExchangeRateService $service)
{
parent::__construct($translator);
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/Controller/GlobalMarginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;

/**
* The controller for global margins entities.
Expand All @@ -41,9 +42,9 @@ class GlobalMarginController extends AbstractEntityController
/**
* Constructor.
*/
public function __construct(GlobalMarginRepository $repository)
public function __construct(TranslatorInterface $translator, GlobalMarginRepository $repository)
{
parent::__construct($repository);
parent::__construct($translator, $repository);
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/Controller/GroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;

/**
* The controller for group entities.
Expand All @@ -43,9 +44,9 @@ class GroupController extends AbstractEntityController
/**
* Constructor.
*/
public function __construct(GroupRepository $repository)
public function __construct(TranslatorInterface $translator, GroupRepository $repository)
{
parent::__construct($repository);
parent::__construct($translator, $repository);
}

/**
Expand Down
Loading

0 comments on commit d50bfab

Please sign in to comment.