Skip to content

Commit

Permalink
[TASK] Enable request object (e.g. for workflows)
Browse files Browse the repository at this point in the history
  • Loading branch information
einpraegsam committed Nov 12, 2024
1 parent 0078169 commit a075ed1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
12 changes: 2 additions & 10 deletions Classes/Utility/EnvironmentUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,18 @@

class EnvironmentUtility
{
/**
* @return bool
* @SuppressWarnings(PHPMD.Superglobals)
*/
public static function isFrontend(): bool
{
if (isset($GLOBALS['TYPO3_REQUEST']) === false) {
if (ObjectUtility::getRequest() === null) {
// E.g. when called from CLI
return false;
}
return ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isFrontend();
}

/**
* @return bool
* @SuppressWarnings(PHPMD.Superglobals)
*/
public static function isBackend(): bool
{
if (isset($GLOBALS['TYPO3_REQUEST']) === false) {
if (ObjectUtility::getRequest() === null) {
// E.g. when called from CLI
return false;
}
Expand Down
10 changes: 10 additions & 0 deletions Classes/Utility/ObjectUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use DateTime;
use In2code\Lux\Domain\Model\Transfer\FilterDto;
use In2code\Lux\Domain\Service\ConfigurationService;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
Expand Down Expand Up @@ -45,4 +46,13 @@ public static function getFilterWithLimit(int $limit = 10): FilterDto
{
return GeneralUtility::makeInstance(FilterDto::class)->setLimit(10);
}

/**
* @return ServerRequestInterface|null
* @SuppressWarnings(PHPMD.Superglobals)
*/
public static function getRequest(): ?ServerRequestInterface
{
return $GLOBALS['TYPO3_REQUEST'] ?? null;
}
}

0 comments on commit a075ed1

Please sign in to comment.