Skip to content

Commit

Permalink
Reduce usage of GLOBALS
Browse files Browse the repository at this point in the history
  • Loading branch information
okmiim committed Nov 19, 2023
1 parent 5d5af5a commit 02ac119
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Classes/Controller/AbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ protected function isDateOutOfTypoScriptConfiguration(\DateTime $dateTime): bool
protected function return404Page(): ResponseInterface
{
return GeneralUtility::makeInstance(ErrorController::class)->pageNotFoundAction(
$GLOBALS['TYPO3_REQUEST'],
$this->request,
'The requested page does not exist',
['code' => PageAccessFailureReasons::PAGE_NOT_FOUND]
);
Expand Down
16 changes: 8 additions & 8 deletions Classes/Controller/BackendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Localization\LanguageServiceFactory;
use TYPO3\CMS\Core\Pagination\ArrayPaginator;
use TYPO3\CMS\Core\Pagination\SimplePagination;
use TYPO3\CMS\Extbase\Pagination\QueryResultPaginator;
Expand All @@ -23,13 +24,17 @@
#[Controller]
class BackendController extends AbstractController
{
protected LanguageService $languageService;

private const PATH_CORE_LOCALLANG = 'LLL:EXT:core/Resources/Private/Language/locallang_common.xlf';

public const OPTIONS_KEY = 'calendarize_be';

public function __construct(
protected readonly ModuleTemplateFactory $moduleTemplateFactory
protected readonly ModuleTemplateFactory $moduleTemplateFactory,
protected readonly LanguageServiceFactory $languageServiceFactory,
) {
$this->languageService = $this->languageServiceFactory->createFromUserPreferences($this->getBackendUser());
}

public function initializeListAction(): void
Expand Down Expand Up @@ -85,8 +90,8 @@ public function listAction(OptionRequest $options = null, int $currentPage = 1):
'pagination' => $pagination,
'totalAmount' => \count($indices),
'filterOptions' => [
'asc' => $this->getLanguageService()->sL(self::PATH_CORE_LOCALLANG . ':ascending') ?: 'ascending',
'desc' => $this->getLanguageService()->sL(self::PATH_CORE_LOCALLANG . ':descending') ?: 'descending',
'asc' => $this->languageService->sL(self::PATH_CORE_LOCALLANG . ':ascending') ?: 'ascending',
'desc' => $this->languageService->sL(self::PATH_CORE_LOCALLANG . ':descending') ?: 'descending',
],
]);

Expand Down Expand Up @@ -223,9 +228,4 @@ protected function getBackendUser(): ?BackendUserAuthentication
{
return $GLOBALS['BE_USER'];
}

protected function getLanguageService(): ?LanguageService
{
return $GLOBALS['LANG'] ?? null;
}
}
4 changes: 1 addition & 3 deletions Classes/Controller/CalendarController.php
Original file line number Diff line number Diff line change
Expand Up @@ -865,9 +865,7 @@ protected function getCurrentConfigurations(): array

protected function getBaseUri(): string
{
$request = $GLOBALS['TYPO3_REQUEST'];

return $request->getAttribute('normalizedParams')->getSiteUrl();
return $this->request->getAttribute('normalizedParams')->getSiteUrl();
}

protected function getTypoScriptFrontendController(): TypoScriptFrontendController
Expand Down
10 changes: 2 additions & 8 deletions Classes/DataProcessing/DisableLanguageMenuProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function process(
if (!$processorConfiguration['menus']) {
return $processedData;
}
$indexId = $this->getIndexId();
$indexId = $this->getIndexId($cObj->getRequest());
if (0 === $indexId) {
return $processedData;
}
Expand Down Expand Up @@ -138,10 +138,9 @@ protected function handleMenu(array &$menu, array $availableLanguages): void
}
}

protected function getIndexId(): int
protected function getIndexId(ServerRequestInterface $request): int
{
$indexId = 0;
$request = $this->getRequest();
/** @var PageArguments $pageArguments */
$pageArguments = $request->getAttribute('routing');
if (isset($pageArguments->getRouteArguments()['tx_calendarize_calendar']['index'])) {
Expand All @@ -152,9 +151,4 @@ protected function getIndexId(): int

return $indexId;
}

protected function getRequest(): ServerRequestInterface
{
return $GLOBALS['TYPO3_REQUEST'];
}
}
6 changes: 5 additions & 1 deletion Classes/ViewHelpers/LanguageViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContext;

/**
* LanguageViewHelper.
Expand All @@ -25,6 +26,9 @@ public function render(): string

protected function getRequest(): ServerRequestInterface
{
return $GLOBALS['TYPO3_REQUEST'];
/** @var RenderingContext $renderingContext */
$renderingContext = $this->renderingContext;

return $renderingContext->getRequest();
}
}

0 comments on commit 02ac119

Please sign in to comment.