diff --git a/typo3/sysext/core/Classes/Configuration/Loader/Exception/YamlFileLoadingException.php b/typo3/sysext/core/Classes/Configuration/Loader/Exception/YamlFileLoadingException.php new file mode 100644 index 0000000000000000000000000000000000000000..98b7ac42568a139b972892d1a58c386ffc597e1f --- /dev/null +++ b/typo3/sysext/core/Classes/Configuration/Loader/Exception/YamlFileLoadingException.php @@ -0,0 +1,21 @@ +<?php +declare(strict_types = 1); + +namespace TYPO3\CMS\Core\Configuration\Loader\Exception; + +/* + * This file is part of the TYPO3 CMS project. + * + * It is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License, either version 2 + * of the License, or any later version. + * + * For the full copyright and license information, please read the + * LICENSE.txt file that was distributed with this source code. + * + * The TYPO3 project - inspiring people to share! + */ + +class YamlFileLoadingException extends \RuntimeException +{ +} diff --git a/typo3/sysext/core/Classes/Configuration/Loader/Exception/YamlParseException.php b/typo3/sysext/core/Classes/Configuration/Loader/Exception/YamlParseException.php new file mode 100644 index 0000000000000000000000000000000000000000..62da0845d75a7c5bff87380ec538185b78d452f3 --- /dev/null +++ b/typo3/sysext/core/Classes/Configuration/Loader/Exception/YamlParseException.php @@ -0,0 +1,21 @@ +<?php +declare(strict_types = 1); + +namespace TYPO3\CMS\Core\Configuration\Loader\Exception; + +/* + * This file is part of the TYPO3 CMS project. + * + * It is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License, either version 2 + * of the License, or any later version. + * + * For the full copyright and license information, please read the + * LICENSE.txt file that was distributed with this source code. + * + * The TYPO3 project - inspiring people to share! + */ + +class YamlParseException extends \RuntimeException +{ +} diff --git a/typo3/sysext/core/Classes/Configuration/Loader/YamlFileLoader.php b/typo3/sysext/core/Classes/Configuration/Loader/YamlFileLoader.php index bb320e53530a6608ab1490d01f649728c7dad249..d03639b9e948f19e9d9008d5ed15eff3a16fd3d4 100644 --- a/typo3/sysext/core/Classes/Configuration/Loader/YamlFileLoader.php +++ b/typo3/sysext/core/Classes/Configuration/Loader/YamlFileLoader.php @@ -14,7 +14,12 @@ namespace TYPO3\CMS\Core\Configuration\Loader; * The TYPO3 project - inspiring people to share! */ +use Psr\Log\LoggerAwareInterface; +use Psr\Log\LoggerAwareTrait; +use Symfony\Component\Yaml\Exception\ParseException; use Symfony\Component\Yaml\Yaml; +use TYPO3\CMS\Core\Configuration\Loader\Exception\YamlFileLoadingException; +use TYPO3\CMS\Core\Configuration\Loader\Exception\YamlParseException; use TYPO3\CMS\Core\Configuration\Processor\PlaceholderProcessorList; use TYPO3\CMS\Core\Utility\ArrayUtility; use TYPO3\CMS\Core\Utility\GeneralUtility; @@ -37,8 +42,10 @@ use TYPO3\CMS\Core\Utility\PathUtility; * * - Environment placeholder values set via %env(option)% will be replaced by env variables of the same name */ -class YamlFileLoader +class YamlFileLoader implements LoggerAwareInterface { + use LoggerAwareTrait; + public const PROCESS_PLACEHOLDERS = 1; public const PROCESS_IMPORTS = 2; @@ -74,7 +81,7 @@ class YamlFileLoader $content = Yaml::parse($content); if (!is_array($content)) { - throw new \RuntimeException( + throw new YamlParseException( 'YAML file "' . $fileName . '" could not be parsed into valid syntax, probably empty?', 1497332874 ); @@ -107,7 +114,7 @@ class YamlFileLoader * @param string $fileName either relative to TYPO3's base project folder or prefixed with EXT:... * @param string|null $currentFileName when called recursively this contains the absolute file name of the file that included this file * @return string the contents of the file - * @throws \RuntimeException when the file was not accessible + * @throws YamlFileLoadingException when the file was not accessible */ protected function getStreamlinedFileName(string $fileName, ?string $currentFileName): string { @@ -121,7 +128,7 @@ class YamlFileLoader $fileName ); if (!GeneralUtility::isAllowedAbsPath($streamlinedFileName)) { - throw new \RuntimeException( + throw new YamlFileLoadingException( 'Referencing a file which is outside of TYPO3s main folder', 1560319866 ); @@ -131,7 +138,7 @@ class YamlFileLoader $streamlinedFileName = GeneralUtility::getFileAbsFileName($fileName); } if (!$streamlinedFileName) { - throw new \RuntimeException('YAML File "' . $fileName . '" could not be loaded', 1485784246); + throw new YamlFileLoadingException('YAML File "' . $fileName . '" could not be loaded', 1485784246); } return $streamlinedFileName; } @@ -147,10 +154,14 @@ class YamlFileLoader { if (isset($content['imports']) && is_array($content['imports'])) { foreach ($content['imports'] as $import) { - $import = $this->processPlaceholders($import, $import); - $importedContent = $this->loadAndParse($import['resource'], $fileName); - // override the imported content with the one from the current file - $content = ArrayUtility::replaceAndAppendScalarValuesRecursive($importedContent, $content); + try { + $import = $this->processPlaceholders($import, $import); + $importedContent = $this->loadAndParse($import['resource'], $fileName); + // override the imported content with the one from the current file + $content = ArrayUtility::replaceAndAppendScalarValuesRecursive($importedContent, $content); + } catch (ParseException|YamlParseException|YamlFileLoadingException $exception) { + $this->logger->error($exception->getMessage(), ['exception' => $exception]); + } } unset($content['imports']); } diff --git a/typo3/sysext/form/Tests/Unit/Mvc/Configuration/YamlSourceTest.php b/typo3/sysext/form/Tests/Unit/Mvc/Configuration/YamlSourceTest.php index 471ae0c943b80e0dcf84119863777f020e61a20b..1a3fb8f7800b4679734d8435a7875bf722468e6b 100644 --- a/typo3/sysext/form/Tests/Unit/Mvc/Configuration/YamlSourceTest.php +++ b/typo3/sysext/form/Tests/Unit/Mvc/Configuration/YamlSourceTest.php @@ -24,6 +24,7 @@ use TYPO3\TestingFramework\Core\Unit\UnitTestCase; */ class YamlSourceTest extends UnitTestCase { + protected $resetSingletonInstances = true; /** * @test