Skip to content

Commit fbfbf46

Browse files
committed
[BUGFIX] Fallback to empty TS in request-less contexts
Prevents issues with attempts to read FlexForm data structures in contexts that don't carry a ServerRequest, e.g. CLI context. Falls back to an empty array.
1 parent 128c243 commit fbfbf46

3 files changed

Lines changed: 10 additions & 0 deletions

File tree

Classes/Service/TypoScriptService.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use TYPO3\CMS\Core\SingletonInterface;
1313
use TYPO3\CMS\Core\Utility\GeneralUtility;
1414
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
15+
use TYPO3\CMS\Extbase\Configuration\Exception\NoServerRequestGivenException;
1516

1617
class TypoScriptService implements SingletonInterface
1718
{
@@ -52,6 +53,10 @@ public function getTypoScriptByPath(string $path)
5253
$all = $this->configurationManager->getConfiguration(
5354
ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT
5455
);
56+
} catch (NoServerRequestGivenException $error) {
57+
// This case may happen when trying to read TypoScript from a CLI context. In this case, rather than just
58+
// giving up, we return an empty set of TypoScript.
59+
$all = [];
5560
} catch (\RuntimeException $exception) {
5661
if ($exception->getCode() !== 1700841298) {
5762
throw $exception;

phpstan-baseline.neon

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
parameters:
22
ignoreErrors:
3+
-
4+
message: "#^Dead catch - RuntimeException is never thrown in the try block\\.$#"
5+
count: 1
6+
path: Classes/Service/TypoScriptService.php
37
-
48
message: "#^Parameter \\#4 \\$_ of method TYPO3\\\\CMS\\\\Core\\\\DataHandling\\\\DataHandler\\:\\:log\\(\\) expects null, int given\\.$#"
59
count: 1

phpstan.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ parameters:
5252
- "#^Class TYPO3\\\\CMS\\\\Extbase\\\\Mvc\\\\Web\\\\Response not found\\.$#"
5353
- "#^Class TYPO3Fluid\\\\Fluid\\\\Component\\\\Argument\\\\ArgumentCollection not found\\.$#"
5454
- "#^Class TYPO3\\\\CMS\\\\Core\\\\View\\\\ViewFactoryData not found\\.$#"
55+
- "#TYPO3\\\\CMS\\\\Extbase\\\\Configuration\\\\Exception\\\\NoServerRequestGivenException not found\\.$#"
5556

5657
- "#TYPO3Fluid\\\\Fluid\\\\Component\\\\Argument\\\\ArgumentCollection#"
5758
- "#TYPO3Fluid\\\\Fluid\\\\Component\\\\Error\\\\ChildNotFoundException#"

0 commit comments

Comments
 (0)