From dbc32153f000d58090848f0f2cb5a6643ded2ed0 Mon Sep 17 00:00:00 2001 From: Benni Mack <benni@typo3.org> Date: Mon, 27 Mar 2017 16:27:48 +0200 Subject: [PATCH] [TASK] Cleanup Localization Charset code The protected property "AbstractXmlParser->charset" is set from the outside but never used anymore in either the abstract class nor in the subclasses. The protected method "getCharset()" is basically useless: a) it's never called or in use b) it has nothing to do with the XmlParser as it does not work with any properties / functionalities of the XmlParser itself. The protected method "initialize()" is called solely in the contructor which can be dealt with directly in the constructor (that's what a constructor is there for). The third parameter $charset within getParsedData() is now not needed anymore within the Parsers, as all expect UTF-8 for files. Resolves: #80486 Releases: master Change-Id: I929c3960fb5b94f5448a2d29f4a73fbb5d81a500 Reviewed-on: https://review.typo3.org/52185 Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl> Tested-by: Wouter Wolters <typo3@wouterwolters.nl> Tested-by: TYPO3com <no-reply@typo3.com> Reviewed-by: Jigal van Hemert <jigal.van.hemert@typo3.org> Tested-by: Jigal van Hemert <jigal.van.hemert@typo3.org> Reviewed-by: Benni Mack <benni@typo3.org> Tested-by: Benni Mack <benni@typo3.org> --- .../Localization/LocalizationFactory.php | 12 +------- .../Localization/Parser/AbstractXmlParser.php | 24 +-------------- .../Parser/LocalizationParserInterface.php | 2 +- .../Parser/LocallangXmlParser.php | 3 +- ...alizationParserInterface-getParsedData.rst | 30 +++++++++++++++++++ 5 files changed, 34 insertions(+), 37 deletions(-) create mode 100644 typo3/sysext/core/Documentation/Changelog/master/Deprecation-80486-SettingCharsetViaLocalizationParserInterface-getParsedData.rst diff --git a/typo3/sysext/core/Classes/Localization/LocalizationFactory.php b/typo3/sysext/core/Classes/Localization/LocalizationFactory.php index 03b908f6183f..07ca8afc34c7 100644 --- a/typo3/sysext/core/Classes/Localization/LocalizationFactory.php +++ b/typo3/sysext/core/Classes/Localization/LocalizationFactory.php @@ -42,16 +42,6 @@ class LocalizationFactory implements \TYPO3\CMS\Core\SingletonInterface * Class constructor */ public function __construct() - { - $this->initialize(); - } - - /** - * Initialize - * - * @return void - */ - protected function initialize() { $this->store = GeneralUtility::makeInstance(LanguageStore::class); $this->initializeCache(); @@ -142,7 +132,7 @@ class LocalizationFactory implements \TYPO3\CMS\Core\SingletonInterface /** @var $parser \TYPO3\CMS\Core\Localization\Parser\LocalizationParserInterface */ $parser = $this->store->getParserInstance($fileReference); // Get parsed data - $LOCAL_LANG = $parser->getParsedData($this->store->getAbsoluteFileReference($fileReference), $languageKey, $charset); + $LOCAL_LANG = $parser->getParsedData($this->store->getAbsoluteFileReference($fileReference), $languageKey); } catch (Exception\FileNotFoundException $exception) { // Source localization file not found, set empty data as there could be an override $this->store->setData($fileReference, $languageKey, []); diff --git a/typo3/sysext/core/Classes/Localization/Parser/AbstractXmlParser.php b/typo3/sysext/core/Classes/Localization/Parser/AbstractXmlParser.php index dffc270e0e63..4dba8e2c358a 100644 --- a/typo3/sysext/core/Classes/Localization/Parser/AbstractXmlParser.php +++ b/typo3/sysext/core/Classes/Localization/Parser/AbstractXmlParser.php @@ -14,7 +14,6 @@ namespace TYPO3\CMS\Core\Localization\Parser; * The TYPO3 project - inspiring people to share! */ -use TYPO3\CMS\Core\Charset\CharsetConverter; use TYPO3\CMS\Core\Localization\Exception\FileNotFoundException; use TYPO3\CMS\Core\Localization\Exception\InvalidXmlFileException; use TYPO3\CMS\Core\Utility\GeneralUtility; @@ -34,17 +33,12 @@ abstract class AbstractXmlParser implements LocalizationParserInterface */ protected $languageKey; - /** - * @var string - */ - protected $charset; - /** * Returns parsed representation of XML file. * * @param string $sourcePath Source file path * @param string $languageKey Language key - * @param string $charset File charset + * @param string $charset File charset, not in use anymore and deprecated since TYPO3 v8, will be removed in TYPO3 v9 as UTF-8 is expected for all language files * @return array * @throws \TYPO3\CMS\Core\Localization\Exception\FileNotFoundException */ @@ -52,7 +46,6 @@ abstract class AbstractXmlParser implements LocalizationParserInterface { $this->sourcePath = $sourcePath; $this->languageKey = $languageKey; - $this->charset = $this->getCharset($charset); if ($this->languageKey !== 'default') { $this->sourcePath = GeneralUtility::getFileAbsFileName(GeneralUtility::llXmlAutoFileName($this->sourcePath, $this->languageKey)); if (!@is_file($this->sourcePath)) { @@ -68,21 +61,6 @@ abstract class AbstractXmlParser implements LocalizationParserInterface return $LOCAL_LANG; } - /** - * Gets the character set to use. - * - * @param string $charset - * @return string - */ - protected function getCharset($charset = '') - { - if ($charset !== '') { - return GeneralUtility::makeInstance(CharsetConverter::class)->parse_charset($charset); - } else { - return 'utf-8'; - } - } - /** * Loads the current XML file before processing. * diff --git a/typo3/sysext/core/Classes/Localization/Parser/LocalizationParserInterface.php b/typo3/sysext/core/Classes/Localization/Parser/LocalizationParserInterface.php index 42abfe71fdd2..91bc3ded7016 100644 --- a/typo3/sysext/core/Classes/Localization/Parser/LocalizationParserInterface.php +++ b/typo3/sysext/core/Classes/Localization/Parser/LocalizationParserInterface.php @@ -24,7 +24,7 @@ interface LocalizationParserInterface * * @param string $sourcePath Source file path * @param string $languageKey Language key - * @param string $charset Charset + * @param string $charset Charset, not in use anymore since TYPO3 v8, will be removed in TYPO3 v9 as UTF-8 is expected for all language files * @return array */ public function getParsedData($sourcePath, $languageKey, $charset = ''); diff --git a/typo3/sysext/core/Classes/Localization/Parser/LocallangXmlParser.php b/typo3/sysext/core/Classes/Localization/Parser/LocallangXmlParser.php index 71971ddc7977..ff3a6780012e 100644 --- a/typo3/sysext/core/Classes/Localization/Parser/LocallangXmlParser.php +++ b/typo3/sysext/core/Classes/Localization/Parser/LocallangXmlParser.php @@ -36,14 +36,13 @@ class LocallangXmlParser extends AbstractXmlParser * * @param string $sourcePath Source file path * @param string $languageKey Language key - * @param string $charset Charset + * @param string $charset File charset, not in use anymore and deprecated since TYPO3 v8, will be removed in TYPO3 v9 as UTF-8 is expected for all language files * @return array */ public function getParsedData($sourcePath, $languageKey, $charset = '') { $this->sourcePath = $sourcePath; $this->languageKey = $languageKey; - $this->charset = $this->getCharset($charset); // Parse source $parsedSource = $this->parseXmlFile(); // Parse target diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-80486-SettingCharsetViaLocalizationParserInterface-getParsedData.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-80486-SettingCharsetViaLocalizationParserInterface-getParsedData.rst new file mode 100644 index 000000000000..d63b4db840e9 --- /dev/null +++ b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-80486-SettingCharsetViaLocalizationParserInterface-getParsedData.rst @@ -0,0 +1,30 @@ +.. include:: ../../Includes.txt + +====================================================================================== +Deprecation: #80486 - Setting charset via LocalizationParserInterface->getParsedData() +====================================================================================== + +See :issue:`80486` + +Description +=========== + +The `LocalizationParserInterface->getParsedData()` contains a third parameter to hand over a value +for the charset used. + +This third parameter has been marked as deprecated, as it is not in use anymore. + + +Affected Installations +====================== + +Any installation with an extension that extends the LocalizationParser functionality with a custom +PHP class implementing the `LocalizationParserInterface`. + + +Migration +========= + +If implementing the `LocalizationParserInterface`, be aware that this third parameter will be dropped in TYPO3 v9. + +.. index:: PHP-API \ No newline at end of file -- GitLab