[TASK] Cleanup of TYPO3\CMS\Core\Localization and Charset 08/39508/4
authorStephan Großberndt <stephan@grossberndt.de>
Tue, 12 May 2015 20:38:28 +0000 (22:38 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Fri, 15 May 2015 18:50:43 +0000 (20:50 +0200)
* Make use of use-statements
* fix typos
* properly align comments
* fix PHPDoc
* fix bool signatures
* remove unused variables
* rename some cryptic variables
* check for equality using === and !== where possible
* use !empty() instead of count()

Resolves: #66924
Releases: master
Change-Id: I44675b3e8c8626591feaa017e53cae1426cd1da3
Reviewed-on: http://review.typo3.org/39508
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
typo3/sysext/core/Classes/Charset/CharsetConverter.php
typo3/sysext/core/Classes/Localization/LanguageStore.php
typo3/sysext/core/Classes/Localization/Locales.php
typo3/sysext/core/Classes/Localization/LocalizationFactory.php
typo3/sysext/core/Classes/Localization/Parser/AbstractXmlParser.php
typo3/sysext/core/Classes/Localization/Parser/LocallangArrayParser.php
typo3/sysext/core/Classes/Localization/Parser/LocallangXmlParser.php
typo3/sysext/core/Classes/Localization/Parser/XliffParser.php

index 77692c5..edefd51 100644 (file)
@@ -14,8 +14,9 @@ namespace TYPO3\CMS\Core\Charset;
  * The TYPO3 project - inspiring people to share!
  */
 
-use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Localization\Locales;
 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
  * Notes on UTF-8
@@ -102,8 +103,7 @@ class CharsetConverter {
         * @var array
         */
        public $fourByteSets = array(
-               'ucs-4' => 1,
-               // 4-byte Unicode
+               'ucs-4' => 1, // 4-byte Unicode
                'utf-32' => 1
        );
 
@@ -113,12 +113,9 @@ class CharsetConverter {
         * @var array
         */
        public $eucBasedSets = array(
-               'gb2312' => 1,
-               // Chinese, simplified.
-               'big5' => 1,
-               // Chinese, traditional.
-               'euc-kr' => 1,
-               // Korean
+               'gb2312' => 1, // Chinese, simplified.
+               'big5' => 1, // Chinese, traditional.
+               'euc-kr' => 1, // Korean
                'shift_jis' => 1
        );
 
@@ -209,7 +206,6 @@ class CharsetConverter {
                'utf8' => 'utf-8',
                'utf16' => 'utf-16',
                'utf32' => 'utf-32',
-               'utf8' => 'utf-8',
                'ucs2' => 'ucs-2',
                'ucs4' => 'ucs-4'
        );
@@ -221,207 +217,119 @@ class CharsetConverter {
         */
        public $lang_to_script = array(
                // iso-639-1 language codes, see http://www.loc.gov/standards/iso639-2/php/code_list.php
-               'af' => 'west_european',
-               //Afrikaans
+               'af' => 'west_european', // Afrikaans
                'ar' => 'arabic',
-               'bg' => 'cyrillic',
-               // Bulgarian
-               'bs' => 'east_european',
-               // Bosnian
-               'cs' => 'east_european',
-               // Czech
-               'da' => 'west_european',
-               // Danish
-               'de' => 'west_european',
-               // German
-               'es' => 'west_european',
-               // Spanish
+               'bg' => 'cyrillic', // Bulgarian
+               'bs' => 'east_european', // Bosnian
+               'cs' => 'east_european', // Czech
+               'da' => 'west_european', // Danish
+               'de' => 'west_european', // German
+               'es' => 'west_european', // Spanish
                'et' => 'estonian',
-               'eo' => 'unicode',
-               // Esperanto
-               'eu' => 'west_european',
-               // Basque
-               'fa' => 'arabic',
-               // Persian
-               'fi' => 'west_european',
-               // Finish
-               'fo' => 'west_european',
-               // Faroese
-               'fr' => 'west_european',
-               // French
-               'ga' => 'west_european',
-               // Irish
-               'gl' => 'west_european',
-               // Galician
+               'eo' => 'unicode', // Esperanto
+               'eu' => 'west_european', // Basque
+               'fa' => 'arabic', // Persian
+               'fi' => 'west_european', // Finish
+               'fo' => 'west_european', // Faroese
+               'fr' => 'west_european', // French
+               'ga' => 'west_european', // Irish
+               'gl' => 'west_european', // Galician
                'gr' => 'greek',
-               'he' => 'hebrew',
-               // Hebrew (since 1998)
-               'hi' => 'unicode',
-               // Hindi
-               'hr' => 'east_european',
-               // Croatian
-               'hu' => 'east_european',
-               // Hungarian
-               'iw' => 'hebrew',
-               // Hebrew (til 1998)
-               'is' => 'west_european',
-               // Icelandic
-               'it' => 'west_european',
-               // Italian
+               'he' => 'hebrew', // Hebrew (since 1998)
+               'hi' => 'unicode', // Hindi
+               'hr' => 'east_european', // Croatian
+               'hu' => 'east_european', // Hungarian
+               'iw' => 'hebrew', // Hebrew (til 1998)
+               'is' => 'west_european', // Icelandic
+               'it' => 'west_european', // Italian
                'ja' => 'japanese',
-               'ka' => 'unicode',
-               // Georgian
-               'kl' => 'west_european',
-               // Greenlandic
-               'km' => 'unicode',
-               // Khmer
+               'ka' => 'unicode', // Georgian
+               'kl' => 'west_european', // Greenlandic
+               'km' => 'unicode', // Khmer
                'ko' => 'korean',
                'lt' => 'lithuanian',
-               'lv' => 'west_european',
-               // Latvian/Lettish
-               'nl' => 'west_european',
-               // Dutch
-               'no' => 'west_european',
-               // Norwegian
-               'nb' => 'west_european',
-               // Norwegian Bokmal
-               'nn' => 'west_european',
-               // Norwegian Nynorsk
-               'pl' => 'east_european',
-               // Polish
-               'pt' => 'west_european',
-               // Portuguese
-               'ro' => 'east_european',
-               // Romanian
-               'ru' => 'cyrillic',
-               // Russian
-               'sk' => 'east_european',
-               // Slovak
-               'sl' => 'east_european',
-               // Slovenian
-               'sr' => 'cyrillic',
-               // Serbian
-               'sv' => 'west_european',
-               // Swedish
-               'sq' => 'albanian',
-               // Albanian
+               'lv' => 'west_european', // Latvian/Lettish
+               'nl' => 'west_european', // Dutch
+               'no' => 'west_european', // Norwegian
+               'nb' => 'west_european', // Norwegian Bokmal
+               'nn' => 'west_european', // Norwegian Nynorsk
+               'pl' => 'east_european', // Polish
+               'pt' => 'west_european', // Portuguese
+               'ro' => 'east_european', // Romanian
+               'ru' => 'cyrillic', // Russian
+               'sk' => 'east_european', // Slovak
+               'sl' => 'east_european', // Slovenian
+               'sr' => 'cyrillic', // Serbian
+               'sv' => 'west_european', // Swedish
+               'sq' => 'albanian', // Albanian
                'th' => 'thai',
-               'uk' => 'cyrillic',
-               // Ukranian
+               'uk' => 'cyrillic', // Ukranian
                'vi' => 'vietnamese',
                'zh' => 'chinese',
+
                // MS language codes, see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_language_strings.asp
                // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wceinternational5/html/wce50conLanguageIdentifiersandLocales.asp
-               'afk' => 'west_european',
-               // Afrikaans
+               'afk' => 'west_european', // Afrikaans
                'ara' => 'arabic',
-               'bgr' => 'cyrillic',
-               // Bulgarian
-               'cat' => 'west_european',
-               // Catalan
+               'bgr' => 'cyrillic', // Bulgarian
+               'cat' => 'west_european', // Catalan
                'chs' => 'simpl_chinese',
                'cht' => 'trad_chinese',
-               'csy' => 'east_european',
-               // Czech
-               'dan' => 'west_european',
-               // Danisch
-               'deu' => 'west_european',
-               // German
-               'dea' => 'west_european',
-               // German (Austrian)
-               'des' => 'west_european',
-               // German (Swiss)
-               'ena' => 'west_european',
-               // English (Australian)
-               'enc' => 'west_european',
-               // English (Canadian)
-               'eng' => 'west_european',
-               // English
-               'enz' => 'west_european',
-               // English (New Zealand)
-               'enu' => 'west_european',
-               // English (United States)
-               'euq' => 'west_european',
-               // Basque
-               'fos' => 'west_european',
-               // Faroese
-               'far' => 'arabic',
-               // Persian
-               'fin' => 'west_european',
-               // Finish
-               'fra' => 'west_european',
-               // French
-               'frb' => 'west_european',
-               // French (Belgian)
-               'frc' => 'west_european',
-               // French (Canadian)
-               'frs' => 'west_european',
-               // French (Swiss)
-               'geo' => 'unicode',
-               // Georgian
-               'glg' => 'west_european',
-               // Galician
+               'csy' => 'east_european', // Czech
+               'dan' => 'west_european', // Danish
+               'deu' => 'west_european', // German
+               'dea' => 'west_european', // German (Austrian)
+               'des' => 'west_european', // German (Swiss)
+               'ena' => 'west_european', // English (Australian)
+               'enc' => 'west_european', // English (Canadian)
+               'eng' => 'west_european', // English
+               'enz' => 'west_european', // English (New Zealand)
+               'enu' => 'west_european', // English (United States)
+               'euq' => 'west_european', // Basque
+               'fos' => 'west_european', // Faroese
+               'far' => 'arabic', // Persian
+               'fin' => 'west_european', // Finish
+               'fra' => 'west_european', // French
+               'frb' => 'west_european', // French (Belgian)
+               'frc' => 'west_european', // French (Canadian)
+               'frs' => 'west_european', // French (Swiss)
+               'geo' => 'unicode', // Georgian
+               'glg' => 'west_european', // Galician
                'ell' => 'greek',
                'heb' => 'hebrew',
-               'hin' => 'unicode',
-               // Hindi
-               'hun' => 'east_european',
-               // Hungarian
-               'isl' => 'west_european',
-               // Icelandic
-               'ita' => 'west_european',
-               // Italian
-               'its' => 'west_european',
-               // Italian (Swiss)
+               'hin' => 'unicode', // Hindi
+               'hun' => 'east_european', // Hungarian
+               'isl' => 'west_european', // Icelandic
+               'ita' => 'west_european', // Italian
+               'its' => 'west_european', // Italian (Swiss)
                'jpn' => 'japanese',
-               'khm' => 'unicode',
-               // Khmer
+               'khm' => 'unicode', // Khmer
                'kor' => 'korean',
                'lth' => 'lithuanian',
-               'lvi' => 'west_european',
-               // Latvian/Lettish
-               'msl' => 'west_european',
-               // Malay
-               'nlb' => 'west_european',
-               // Dutch (Belgian)
-               'nld' => 'west_european',
-               // Dutch
-               'nor' => 'west_european',
-               // Norwegian (bokmal)
-               'non' => 'west_european',
-               // Norwegian (nynorsk)
-               'plk' => 'east_european',
-               // Polish
-               'ptg' => 'west_european',
-               // Portuguese
-               'ptb' => 'west_european',
-               // Portuguese (Brazil)
-               'rom' => 'east_european',
-               // Romanian
-               'rus' => 'cyrillic',
-               // Russian
-               'slv' => 'east_european',
-               // Slovenian
-               'sky' => 'east_european',
-               // Slovak
-               'srl' => 'east_european',
-               // Serbian (Latin)
-               'srb' => 'cyrillic',
-               // Serbian (Cyrillic)
-               'esp' => 'west_european',
-               // Spanish (trad. sort)
-               'esm' => 'west_european',
-               // Spanish (Mexican)
-               'esn' => 'west_european',
-               // Spanish (internat. sort)
-               'sve' => 'west_european',
-               // Swedish
-               'sqi' => 'albanian',
-               // Albanian
+               'lvi' => 'west_european', // Latvian/Lettish
+               'msl' => 'west_european', // Malay
+               'nlb' => 'west_european', // Dutch (Belgian)
+               'nld' => 'west_european', // Dutch
+               'nor' => 'west_european', // Norwegian (bokmal)
+               'non' => 'west_european', // Norwegian (nynorsk)
+               'plk' => 'east_european', // Polish
+               'ptg' => 'west_european', // Portuguese
+               'ptb' => 'west_european', // Portuguese (Brazil)
+               'rom' => 'east_european', // Romanian
+               'rus' => 'cyrillic', // Russian
+               'slv' => 'east_european', // Slovenian
+               'sky' => 'east_european', // Slovak
+               'srl' => 'east_european', // Serbian (Latin)
+               'srb' => 'cyrillic', // Serbian (Cyrillic)
+               'esp' => 'west_european', // Spanish (trad. sort)
+               'esm' => 'west_european', // Spanish (Mexican)
+               'esn' => 'west_european', // Spanish (internat. sort)
+               'sve' => 'west_european', // Swedish
+               'sqi' => 'albanian', // Albanian
                'tha' => 'thai',
                'trk' => 'turkish',
-               'ukr' => 'cyrillic',
-               // Ukrainian
+               'ukr' => 'cyrillic', // Ukrainian
+
                // English language names
                'afrikaans' => 'west_european',
                'albanian' => 'albanian',
@@ -487,11 +395,9 @@ class CharsetConverter {
                'greek' => 'iso-8859-7',
                'hebrew' => 'iso-8859-8',
                'turkish' => 'iso-8859-9',
-               'thai' => 'iso-8859-11',
-               // = TIS-620
+               'thai' => 'iso-8859-11', // = TIS-620
                'lithuanian' => 'iso-8859-13',
-               'chinese' => 'gb2312',
-               // = euc-cn
+               'chinese' => 'gb2312', // = euc-cn
                'japanese' => 'euc-jp',
                'korean' => 'euc-kr',
                'simpl_chinese' => 'gb2312',
@@ -545,7 +451,7 @@ class CharsetConverter {
 
        /**
         * TYPO3 specific: Array with the system charsets used for each system language in TYPO3:
-        * Empty values means "iso-8859-1"
+        * Empty values means "utf-8"
         *
         * @var array
         */
@@ -619,10 +525,10 @@ class CharsetConverter {
        );
 
        /**
-        * Default constructor.
+        * Constructor
         */
        public function __construct() {
-               $this->locales = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Localization\Locales::class);
+               $this->locales = GeneralUtility::makeInstance(Locales::class);
        }
 
        /**
@@ -642,9 +548,9 @@ class CharsetConverter {
        /**
         * Get the charset of a locale.
         *
-        * ln                   language
-        * ln_CN                 language / country
-        * ln_CN.cs       language / country / charset
+        * ln      language
+        * ln_CN     language / country
+        * ln_CN.cs    language / country / charset
         * ln_CN.cs@mod  language / country / charset / modifier
         *
         * @param string $locale Locale string
@@ -668,7 +574,7 @@ class CharsetConverter {
                        return 'iso-8859-15';
                }
                // Get language
-               list($language, $country) = explode('_', $locale);
+               list($language, ) = explode('_', $locale);
                if (isset($this->lang_to_script[$language])) {
                        $script = $this->lang_to_script[$language];
                }
@@ -688,67 +594,67 @@ class CharsetConverter {
        /**
         * Convert from one charset to another charset.
         *
-        * @param string $str Input string
-        * @param string $fromCS From charset (the current charset of the string)
-        * @param string $toCS To charset (the output charset wanted)
+        * @param string $inputString Input string
+        * @param string $fromCharset From charset (the current charset of the string)
+        * @param string $toCharset To charset (the output charset wanted)
         * @param bool $useEntityForNoChar If set, then characters that are not available in the destination character set will be encoded as numeric entities
         * @return string Converted string
         * @see convArray()
         */
-       public function conv($str, $fromCS, $toCS, $useEntityForNoChar = 0) {
-               if ($fromCS == $toCS) {
-                       return $str;
+       public function conv($inputString, $fromCharset, $toCharset, $useEntityForNoChar = FALSE) {
+               if ($fromCharset === $toCharset) {
+                       return $inputString;
                }
                // PHP-libs don't support fallback to SGML entities, but UTF-8 handles everything
-               if ($toCS === 'utf-8' || !$useEntityForNoChar) {
+               if ($toCharset === 'utf-8' || !$useEntityForNoChar) {
                        switch ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_convMethod']) {
                                case 'mbstring':
-                                       $conv_str = mb_convert_encoding($str, $toCS, $fromCS);
-                                       if (FALSE !== $conv_str) {
-                                               return $conv_str;
+                                       $convertedString = mb_convert_encoding($inputString, $toCharset, $fromCharset);
+                                       if (FALSE !== $convertedString) {
+                                               return $convertedString;
                                        }
                                        // Returns FALSE for unsupported charsets
                                        break;
                                case 'iconv':
-                                       $conv_str = iconv($fromCS, $toCS . '//TRANSLIT', $str);
-                                       if (FALSE !== $conv_str) {
-                                               return $conv_str;
+                                       $convertedString = iconv($fromCharset, $toCharset . '//TRANSLIT', $inputString);
+                                       if (FALSE !== $convertedString) {
+                                               return $convertedString;
                                        }
                                        break;
                                case 'recode':
-                                       $conv_str = recode_string($fromCS . '..' . $toCS, $str);
-                                       if (FALSE !== $conv_str) {
-                                               return $conv_str;
+                                       $convertedString = recode_string($fromCharset . '..' . $toCharset, $inputString);
+                                       if (FALSE !== $convertedString) {
+                                               return $convertedString;
                                        }
                                        break;
                        }
                }
-               if ($fromCS !== 'utf-8') {
-                       $str = $this->utf8_encode($str, $fromCS);
+               if ($fromCharset !== 'utf-8') {
+                       $inputString = $this->utf8_encode($inputString, $fromCharset);
                }
-               if ($toCS !== 'utf-8') {
-                       $str = $this->utf8_decode($str, $toCS, $useEntityForNoChar);
+               if ($toCharset !== 'utf-8') {
+                       $inputString = $this->utf8_decode($inputString, $toCharset, $useEntityForNoChar);
                }
-               return $str;
+               return $inputString;
        }
 
        /**
         * Convert all elements in ARRAY with type string from one charset to another charset.
         * NOTICE: Array is passed by reference!
         *
-        * @param string $array Input array, possibly multidimensional
-        * @param string $fromCS From charset (the current charset of the string)
-        * @param string $toCS To charset (the output charset wanted)
+        * @param array $array Input array, possibly multidimensional
+        * @param string $fromCharset From charset (the current charset of the string)
+        * @param string $toCharset To charset (the output charset wanted)
         * @param bool $useEntityForNoChar If set, then characters that are not available in the destination character set will be encoded as numeric entities
         * @return void
         * @see conv()
         */
-       public function convArray(&$array, $fromCS, $toCS, $useEntityForNoChar = 0) {
+       public function convArray(&$array, $fromCharset, $toCharset, $useEntityForNoChar = FALSE) {
                foreach ($array as $key => $value) {
                        if (is_array($array[$key])) {
-                               $this->convArray($array[$key], $fromCS, $toCS, $useEntityForNoChar);
+                               $this->convArray($array[$key], $fromCharset, $toCharset, $useEntityForNoChar);
                        } elseif (is_string($array[$key])) {
-                               $array[$key] = $this->conv($array[$key], $fromCS, $toCS, $useEntityForNoChar);
+                               $array[$key] = $this->conv($array[$key], $fromCharset, $toCharset, $useEntityForNoChar);
                        }
                }
        }
@@ -819,7 +725,7 @@ class CharsetConverter {
         * @param bool $useEntityForNoChar If set, then characters that are not available in the destination character set will be encoded as numeric entities
         * @return string Output string, converted to local charset
         */
-       public function utf8_decode($str, $charset, $useEntityForNoChar = 0) {
+       public function utf8_decode($str, $charset, $useEntityForNoChar = FALSE) {
                if ($charset === 'utf-8') {
                        return $str;
                }
@@ -828,7 +734,6 @@ class CharsetConverter {
                if ($this->initCharset($charset)) {
                        $strLen = strlen($str);
                        $outStr = '';
-                       $buf = '';
                        // Traverse each char in UTF-8 string
                        for ($a = 0, $i = 0; $a < $strLen; $a++, $i++) {
                                $chr = substr($str, $a, 1);
@@ -888,7 +793,6 @@ class CharsetConverter {
        public function utf8_to_entities($str) {
                $strLen = strlen($str);
                $outStr = '';
-               $buf = '';
                // Traverse each char in UTF-8 string.
                for ($a = 0; $a < $strLen; $a++) {
                        $chr = substr($str, $a, 1);
@@ -971,7 +875,7 @@ class CharsetConverter {
         * @param bool $retChar If set, then instead of integer numbers the real UTF-8 char is returned.
         * @return array Output array with the char numbers
         */
-       public function utf8_to_numberarray($str, $convEntities = 0, $retChar = 0) {
+       public function utf8_to_numberarray($str, $convEntities = FALSE, $retChar = FALSE) {
                // If entities must be registered as well...:
                if ($convEntities) {
                        $str = $this->entities_to_utf8($str, 1);
@@ -979,7 +883,6 @@ class CharsetConverter {
                // Do conversion:
                $strLen = strlen($str);
                $outArr = array();
-               $buf = '';
                // Traverse each char in UTF-8 string.
                for ($a = 0; $a < $strLen; $a++) {
                        $chr = substr($str, $a, 1);
@@ -1023,59 +926,49 @@ class CharsetConverter {
         * and the number of high bits set in the lead byte announces the number of bytes in the multibyte sequence:
         *
         * bytes | bits | representation
-        * 1 |  7 | 0vvvvvvv
-        * 2 |   11 | 110vvvvv 10vvvvvv
-        * 3 |   16 | 1110vvvv 10vvvvvv 10vvvvvv
-        * 4 |   21 | 11110vvv 10vvvvvv 10vvvvvv 10vvvvvv
-        * 5 |   26 | 111110vv 10vvvvvv 10vvvvvv 10vvvvvv 10vvvvvv
-        * 6 |   31 | 1111110v 10vvvvvv 10vvvvvv 10vvvvvv 10vvvvvv 10vvvvvv
-        *
-        * @param int $cbyte UNICODE integer
+        *     1 |    7 | 0vvvvvvv
+        *     2 |   11 | 110vvvvv 10vvvvvv
+        *     3 |   16 | 1110vvvv 10vvvvvv 10vvvvvv
+        *     4 |   21 | 11110vvv 10vvvvvv 10vvvvvv 10vvvvvv
+        *     5 |   26 | 111110vv 10vvvvvv 10vvvvvv 10vvvvvv 10vvvvvv
+        *     6 |   31 | 1111110v 10vvvvvv 10vvvvvv 10vvvvvv 10vvvvvv 10vvvvvv
+        *
+        * @param int $unicodeInteger UNICODE integer
         * @return string UTF-8 multibyte character string
         * @see utf8CharToUnumber()
         */
-       public function UnumberToChar($cbyte) {
+       public function UnumberToChar($unicodeInteger) {
                $str = '';
-               if ($cbyte < 128) {
-                       $str .= chr($cbyte);
+               if ($unicodeInteger < 128) {
+                       $str .= chr($unicodeInteger);
+               } elseif ($unicodeInteger < 2048) {
+                       $str .= chr(192 | $unicodeInteger >> 6);
+                       $str .= chr(128 | $unicodeInteger & 63);
+               } elseif ($unicodeInteger < 65536) {
+                       $str .= chr(224 | $unicodeInteger >> 12);
+                       $str .= chr(128 | $unicodeInteger >> 6 & 63);
+                       $str .= chr(128 | $unicodeInteger & 63);
+               } elseif ($unicodeInteger < 2097152) {
+                       $str .= chr(240 | $unicodeInteger >> 18);
+                       $str .= chr(128 | $unicodeInteger >> 12 & 63);
+                       $str .= chr(128 | $unicodeInteger >> 6 & 63);
+                       $str .= chr(128 | $unicodeInteger & 63);
+               } elseif ($unicodeInteger < 67108864) {
+                       $str .= chr(248 | $unicodeInteger >> 24);
+                       $str .= chr(128 | $unicodeInteger >> 18 & 63);
+                       $str .= chr(128 | $unicodeInteger >> 12 & 63);
+                       $str .= chr(128 | $unicodeInteger >> 6 & 63);
+                       $str .= chr(128 | $unicodeInteger & 63);
+               } elseif ($unicodeInteger < 2147483648) {
+                       $str .= chr(252 | $unicodeInteger >> 30);
+                       $str .= chr(128 | $unicodeInteger >> 24 & 63);
+                       $str .= chr(128 | $unicodeInteger >> 18 & 63);
+                       $str .= chr(128 | $unicodeInteger >> 12 & 63);
+                       $str .= chr(128 | $unicodeInteger >> 6 & 63);
+                       $str .= chr(128 | $unicodeInteger & 63);
                } else {
-                       if ($cbyte < 2048) {
-                               $str .= chr(192 | $cbyte >> 6);
-                               $str .= chr(128 | $cbyte & 63);
-                       } else {
-                               if ($cbyte < 65536) {
-                                       $str .= chr(224 | $cbyte >> 12);
-                                       $str .= chr(128 | $cbyte >> 6 & 63);
-                                       $str .= chr(128 | $cbyte & 63);
-                               } else {
-                                       if ($cbyte < 2097152) {
-                                               $str .= chr(240 | $cbyte >> 18);
-                                               $str .= chr(128 | $cbyte >> 12 & 63);
-                                               $str .= chr(128 | $cbyte >> 6 & 63);
-                                               $str .= chr(128 | $cbyte & 63);
-                                       } else {
-                                               if ($cbyte < 67108864) {
-                                                       $str .= chr(248 | $cbyte >> 24);
-                                                       $str .= chr(128 | $cbyte >> 18 & 63);
-                                                       $str .= chr(128 | $cbyte >> 12 & 63);
-                                                       $str .= chr(128 | $cbyte >> 6 & 63);
-                                                       $str .= chr(128 | $cbyte & 63);
-                                               } else {
-                                                       if ($cbyte < 2147483648) {
-                                                               $str .= chr(252 | $cbyte >> 30);
-                                                               $str .= chr(128 | $cbyte >> 24 & 63);
-                                                               $str .= chr(128 | $cbyte >> 18 & 63);
-                                                               $str .= chr(128 | $cbyte >> 12 & 63);
-                                                               $str .= chr(128 | $cbyte >> 6 & 63);
-                                                               $str .= chr(128 | $cbyte & 63);
-                                                       } else {
-                                                               // Cannot express a 32-bit character in UTF-8
-                                                               $str .= chr($this->noCharByteVal);
-                                                       }
-                                               }
-                                       }
-                               }
-                       }
+                       // Cannot express a 32-bit character in UTF-8
+                       $str .= chr($this->noCharByteVal);
                }
                return $str;
        }
@@ -1089,11 +982,11 @@ class CharsetConverter {
         * @return int UNICODE integer
         * @see UnumberToChar()
         */
-       public function utf8CharToUnumber($str, $hex = 0) {
+       public function utf8CharToUnumber($str, $hex = FALSE) {
                // First char
                $ord = ord($str[0]);
-               // This verifyes that it IS a multi byte string
-               if (($ord & 192) == 192) {
+               // This verifies that it IS a multi byte string
+               if (($ord & 192) === 192) {
                        $binBuf = '';
                        // For each byte in multibyte string...
                        for ($b = 0; $b < 8; $b++) {
@@ -1125,9 +1018,9 @@ class CharsetConverter {
         *
         * PLEASE SEE: http://www.unicode.org/Public/MAPPINGS/
         *
-        * @param string The charset to be initialized. Use lowercase charset always (the charset must match exactly with a filename in csconvtbl/ folder ([charset].tbl)
+        * @param string $charset The charset to be initialized. Use lowercase charset always (the charset must match exactly with a filename in csconvtbl/ folder ([charset].tbl)
         * @return int Returns '1' if already loaded. Returns FALSE if charset conversion table was not found. Returns '2' if the charset conversion table was found and parsed.
-        * @acces private
+        * @access private
         */
        public function initCharset($charset) {
                // Only process if the charset is not yet loaded:
@@ -1249,7 +1142,7 @@ class CharsetConverter {
                while (!feof($fh)) {
                        $line = fgets($fh, 4096);
                        // Has a lot of info
-                       list($char, $name, $cat, , , $decomp, , , $num, , , , $upper, $lower, $title, ) = explode(';', rtrim($line));
+                       list($char, $name, $cat, , , $decomp, , , $num, , , , $upper, $lower, $title,) = explode(';', rtrim($line));
                        $ord = hexdec($char);
                        if ($ord > 65535) {
                                // Only process the BMP
@@ -1263,7 +1156,7 @@ class CharsetConverter {
                                $utf8CaseFolding['toLower'][$utf8_char] = $this->UnumberToChar(hexdec($lower));
                        }
                        // Store "title" only when different from "upper" (only a few)
-                       if ($title && $title != $upper) {
+                       if ($title && $title !== $upper) {
                                $utf8CaseFolding['toTitle'][$utf8_char] = $this->UnumberToChar(hexdec($title));
                        }
                        switch ($cat[0]) {
@@ -1273,7 +1166,7 @@ class CharsetConverter {
                                        break;
                                case 'N':
                                        // numeric value
-                                       if ($ord > 128 && $num != '') {
+                                       if ($ord > 128 && $num !== '') {
                                                $number['U+' . $char] = $num;
                                        }
                        }
@@ -1385,7 +1278,7 @@ class CharsetConverter {
                                        array_push($code_decomp, $code_value);
                                }
                        }
-                       if (count($code_decomp) || isset($omit[$from])) {
+                       if (!empty($code_decomp) || isset($omit[$from])) {
                                $decomposition[$from] = $code_decomp;
                        } else {
                                unset($decomposition[$from]);
@@ -1511,7 +1404,6 @@ class CharsetConverter {
                if (!$this->initUnicodeData('ascii')) {
                        return FALSE;
                }
-               $nochar = chr($this->noCharByteVal);
                foreach ($this->parsedCharsets[$charset]['local'] as $ci => $utf8) {
                        // Reconvert to charset (don't use chr() of numeric value, might be muli-byte)
                        $c = $this->utf8_decode($utf8, $charset);
@@ -1598,7 +1490,7 @@ class CharsetConverter {
                        return mb_strlen($string, $charset);
                } elseif ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] === 'iconv') {
                        return iconv_strlen($string, $charset);
-               } elseif ($charset == 'utf-8') {
+               } elseif ($charset === 'utf-8') {
                        return $this->utf8_strlen($string);
                } elseif ($this->eucBasedSets[$charset]) {
                        return $this->euc_strlen($string, $charset);
@@ -1651,7 +1543,7 @@ class CharsetConverter {
                if ((int)$len === 0) {
                        return $string;
                }
-               if ($charset == 'utf-8') {
+               if ($charset === 'utf-8') {
                        $i = $this->utf8_char2byte_pos($string, $len);
                } elseif ($this->eucBasedSets[$charset]) {
                        $i = $this->euc_char2byte_pos($string, $len, $charset);
@@ -1697,7 +1589,7 @@ class CharsetConverter {
                }
                if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] === 'mbstring') {
                        return mb_strcut($string, 0, $len, $charset);
-               } elseif ($charset == 'utf-8') {
+               } elseif ($charset === 'utf-8') {
                        return $this->utf8_strtrunc($string, $len);
                } elseif ($this->eucBasedSets[$charset]) {
                        return $this->euc_strtrunc($string, $len, $charset);
@@ -1822,7 +1714,7 @@ class CharsetConverter {
                                break;
                        }
                        // Strip the country code from the end
-                       list($preferredLanguage, $preferredCountry) = explode('-', $preferredLanguage);
+                       list($preferredLanguage, ) = explode('-', $preferredLanguage);
                        if (isset($allLanguageCodes[$preferredLanguage])) {
                                $selectedLanguage = $allLanguageCodes[$preferredLanguage];
                                break;
@@ -1903,8 +1795,6 @@ class CharsetConverter {
                        if ($start > 0) {
                                // $start outside string length
                                return FALSE;
-                       } else {
-                               $start = 0;
                        }
                }
                $str = substr($str, $byte_start);
@@ -1937,7 +1827,7 @@ class CharsetConverter {
                        // Single-byte (0xxxxxx)
                        if (!($c & 128)) {
                                $n++;
-                       } elseif (($c & 192) == 192) {
+                       } elseif (($c & 192) === 192) {
                                // Multi-byte starting byte (11xxxxxx)
                                $n++;
                        }
@@ -1980,7 +1870,7 @@ class CharsetConverter {
         *
         * @param string $haystack UTF-8 string to search in
         * @param string $needle UTF-8 string to search for
-        * @param int $offset Positition to start the search
+        * @param int $offset Position to start the search
         * @return int The character position
         * @see strpos()
         */
@@ -2050,7 +1940,7 @@ class CharsetConverter {
                        // single-byte (0xxxxxx)
                        if (!($c & 128)) {
                                $n++;
-                       } elseif (($c & 192) == 192) {
+                       } elseif (($c & 192) === 192) {
                                // Multi-byte starting byte (11xxxxxx)
                                $n++;
                        }
@@ -2087,7 +1977,7 @@ class CharsetConverter {
                        // single-byte (0xxxxxx)
                        if (!($c & 128)) {
                                $n++;
-                       } elseif (($c & 192) == 192) {
+                       } elseif (($c & 192) === 192) {
                                // Multi-byte starting byte (11xxxxxx)
                                $n++;
                        }
@@ -2128,7 +2018,7 @@ class CharsetConverter {
                        // single-byte (0xxxxxx)
                        if (!($c & 128)) {
                                $mbc = $str[$i];
-                       } elseif (($c & 192) == 192) {
+                       } elseif (($c & 192) === 192) {
                                // multi-byte starting byte (11xxxxxx)
                                for ($bc = 0; $c & 128; $c = $c << 1) {
                                        $bc++;
@@ -2167,10 +2057,10 @@ class CharsetConverter {
         * @see mb_strcut()
         */
        public function euc_strtrunc($str, $len, $charset) {
-               $sjis = $charset === 'shift_jis';
+               $shiftJis = $charset === 'shift_jis';
                for ($i = 0; isset($str[$i]) && $i < $len; $i++) {
                        $c = ord($str[$i]);
-                       if ($sjis) {
+                       if ($shiftJis) {
                                if ($c >= 128 && $c < 160 || $c >= 224) {
                                        $i++;
                                }
index 052bc78..a7d9071 100644 (file)
@@ -14,6 +14,10 @@ namespace TYPO3\CMS\Core\Localization;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Localization\Exception\FileNotFoundException;
+use TYPO3\CMS\Core\Localization\Exception\InvalidParserException;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+
 /**
  * Language store.
  *
@@ -59,7 +63,7 @@ class LanguageStore implements \TYPO3\CMS\Core\SingletonInterface {
         */
        public function initialize() {
                if (isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['format']['priority']) && trim($GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['format']['priority']) !== '') {
-                       $this->supportedExtensions = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['format']['priority']);
+                       $this->supportedExtensions = GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['format']['priority']);
                } else {
                        $this->supportedExtensions = array('xlf', 'xml', 'php');
                }
@@ -145,7 +149,7 @@ class LanguageStore implements \TYPO3\CMS\Core\SingletonInterface {
                        'languageKey' => $languageKey,
                        'charset' => $charset
                );
-               $fileWithoutExtension = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($this->getFileReferenceWithoutExtension($fileReference));
+               $fileWithoutExtension = GeneralUtility::getFileAbsFileName($this->getFileReferenceWithoutExtension($fileReference));
                foreach ($this->supportedExtensions as $extension) {
                        if (@is_file(($fileWithoutExtension . '.' . $extension))) {
                                $this->configuration[$fileReference]['fileReference'] = $fileWithoutExtension . '.' . $extension;
@@ -154,22 +158,22 @@ class LanguageStore implements \TYPO3\CMS\Core\SingletonInterface {
                        }
                }
                if ($this->configuration[$fileReference]['fileExtension'] === FALSE) {
-                       throw new \TYPO3\CMS\Core\Localization\Exception\FileNotFoundException(sprintf('Source localization file (%s) not found', $fileReference), 1306410755);
+                       throw new FileNotFoundException(sprintf('Source localization file (%s) not found', $fileReference), 1306410755);
                }
                $extension = $this->configuration[$fileReference]['fileExtension'];
                if (isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['parser'][$extension]) && trim($GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['parser'][$extension]) !== '') {
                        $this->configuration[$fileReference]['parserClass'] = $GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['parser'][$extension];
                } else {
-                       throw new \TYPO3\CMS\Core\Localization\Exception\InvalidParserException('TYPO3 Fatal Error: l10n parser for file extension "' . $extension . '" is not configured! Please check you configuration.', 1301579637);
+                       throw new InvalidParserException('TYPO3 Fatal Error: l10n parser for file extension "' . $extension . '" is not configured! Please check you configuration.', 1301579637);
                }
                if (!class_exists($this->configuration[$fileReference]['parserClass']) || trim($this->configuration[$fileReference]['parserClass']) === '') {
-                       throw new \TYPO3\CMS\Core\Localization\Exception\InvalidParserException('TYPO3 Fatal Error: l10n parser "' . $this->configuration[$fileReference]['parserClass'] . '" cannot be found or is an empty parser!', 1270853900);
+                       throw new InvalidParserException('TYPO3 Fatal Error: l10n parser "' . $this->configuration[$fileReference]['parserClass'] . '" cannot be found or is an empty parser!', 1270853900);
                }
                return $this;
        }
 
        /**
-        * Get the filereference without the extension
+        * Get the fileReference without the extension
         *
         * @param string $fileReference File reference
         * @return string
@@ -190,9 +194,9 @@ class LanguageStore implements \TYPO3\CMS\Core\SingletonInterface {
         */
        public function getParserInstance($fileReference) {
                if (isset($this->configuration[$fileReference]['parserClass']) && trim($this->configuration[$fileReference]['parserClass']) !== '') {
-                       return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance((string)$this->configuration[$fileReference]['parserClass']);
+                       return GeneralUtility::makeInstance((string)$this->configuration[$fileReference]['parserClass']);
                } else {
-                       throw new \TYPO3\CMS\Core\Localization\Exception\InvalidParserException(sprintf('Invalid parser configuration for the current file (%s)', $fileReference), 1307293692);
+                       throw new InvalidParserException(sprintf('Invalid parser configuration for the current file (%s)', $fileReference), 1307293692);
                }
        }
 
index bd00c1d..3d1aabc 100644 (file)
@@ -14,6 +14,9 @@ namespace TYPO3\CMS\Core\Localization;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Utility\ArrayUtility;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+
 /**
  * Locales.
  *
@@ -91,51 +94,35 @@ class Locales implements \TYPO3\CMS\Core\SingletonInterface {
        );
 
        /**
-        * Mapping with codes used by TYPO3 4.5 and below
+        * Reversed mapping with codes used by TYPO3 4.5 and below
         *
         * @var array
         */
        protected $isoReverseMapping = array(
-               'bs' => 'ba',
-               // Bosnian
-               'cs' => 'cz',
-               // Czech
-               'da' => 'dk',
-               // Danish
-               'el' => 'gr',
-               // Greek
-               'fr_CA' => 'qc',
-               // French (Canada)
-               'gl' => 'ga',
-               // Galician
-               'ja' => 'jp',
-               // Japanese
-               'ka' => 'ge',
-               // Georgian
-               'kl' => 'gl',
-               // Greenlandic
-               'ko' => 'kr',
-               // Korean
-               'ms' => 'my',
-               // Malay
-               'pt_BR' => 'br',
-               // Portuguese (Brazil)
-               'sl' => 'si',
-               // Slovenian
-               'sv' => 'se',
-               // Swedish
-               'uk' => 'ua',
-               // Ukrainian
-               'vi' => 'vn',
-               // Vietnamese
-               'zh' => 'hk',
-               // Chinese (China)
-               'zh_CN' => 'ch',
-               // Chinese (Simplified)
+               'bs' => 'ba', // Bosnian
+               'cs' => 'cz', // Czech
+               'da' => 'dk', // Danish
+               'el' => 'gr', // Greek
+               'fr_CA' => 'qc', // French (Canada)
+               'gl' => 'ga', // Galician
+               'ja' => 'jp', // Japanese
+               'ka' => 'ge', // Georgian
+               'kl' => 'gl', // Greenlandic
+               'ko' => 'kr', // Korean
+               'ms' => 'my', // Malay
+               'pt_BR' => 'br', // Portuguese (Brazil)
+               'sl' => 'si', // Slovenian
+               'sv' => 'se', // Swedish
+               'uk' => 'ua', // Ukrainian
+               'vi' => 'vn', // Vietnamese
+               'zh' => 'hk', // Chinese (China)
+               'zh_CN' => 'ch', // Chinese (Simplified)
                'zh_HK' => 'hk'
        );
 
        /**
+        * Mapping with codes used by TYPO3 4.5 and below
+        *
         * @var array
         */
        protected $isoMapping;
@@ -153,8 +140,8 @@ class Locales implements \TYPO3\CMS\Core\SingletonInterface {
         * @return void
         */
        static public function initialize() {
-               /** @var $instance \TYPO3\CMS\Core\Localization\Locales */
-               $instance = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Localization\Locales::class);
+               /** @var $instance Locales */
+               $instance = GeneralUtility::makeInstance(Locales::class);
                $instance->isoMapping = array_flip($instance->isoReverseMapping);
                // Allow user-defined locales
                if (isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['localization']['locales']['user']) && is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['localization']['locales']['user'])) {
@@ -167,13 +154,13 @@ class Locales implements \TYPO3\CMS\Core\SingletonInterface {
                // Initializes the locale dependencies with TYPO3 supported locales
                $instance->localeDependencies = array();
                foreach ($instance->languages as $locale => $name) {
-                       if (strlen($locale) == 5) {
+                       if (strlen($locale) === 5) {
                                $instance->localeDependencies[$locale] = array(substr($locale, 0, 2));
                        }
                }
                // Merge user-provided locale dependencies
                if (isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['localization']['locales']['dependencies']) && is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['localization']['locales']['dependencies'])) {
-                       \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($instance->localeDependencies, $GLOBALS['TYPO3_CONF_VARS']['SYS']['localization']['locales']['dependencies']);
+                       ArrayUtility::mergeRecursiveWithOverrule($instance->localeDependencies, $GLOBALS['TYPO3_CONF_VARS']['SYS']['localization']['locales']['dependencies']);
                }
        }
 
index 2a4386e..8f1a539 100644 (file)
@@ -14,6 +14,11 @@ namespace TYPO3\CMS\Core\Localization;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Cache\CacheManager;
+use TYPO3\CMS\Core\Localization\Exception\FileNotFoundException;
+use TYPO3\CMS\Core\Utility\ArrayUtility;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+
 /**
  * Provides a language parser factory.
  *
@@ -49,7 +54,7 @@ class LocalizationFactory implements \TYPO3\CMS\Core\SingletonInterface {
         * @return void
         */
        protected function initialize() {
-               $this->store = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Localization\LanguageStore::class);
+               $this->store = GeneralUtility::makeInstance(LanguageStore::class);
                $this->initializeCache();
        }
 
@@ -59,7 +64,7 @@ class LocalizationFactory implements \TYPO3\CMS\Core\SingletonInterface {
         * @return void
         */
        protected function initializeCache() {
-               $this->cacheInstance = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class)->getCache('l10n');
+               $this->cacheInstance = GeneralUtility::makeInstance(CacheManager::class)->getCache('l10n');
        }
 
        /**
@@ -105,7 +110,7 @@ class LocalizationFactory implements \TYPO3\CMS\Core\SingletonInterface {
                        $this->store->setData($fileReference, $languageKey, $LOCAL_LANG[$languageKey]);
                        // Cache processed data
                        $this->cacheInstance->set($hash, $this->store->getDataByLanguage($fileReference, $languageKey));
-               } catch (\TYPO3\CMS\Core\Localization\Exception\FileNotFoundException $exception) {
+               } catch (FileNotFoundException $exception) {
                        // Source localization file not found
                        $this->store->setData($fileReference, $languageKey, array());
                }
@@ -135,10 +140,10 @@ class LocalizationFactory implements \TYPO3\CMS\Core\SingletonInterface {
                                $overrides = array_merge($overrides, $locallangXMLOverride[$fileReferenceWithoutExtension . '.' . $extension]);
                        }
                }
-               if (count($overrides) > 0) {
+               if (!empty($overrides)) {
                        foreach ($overrides as $overrideFile) {
-                               $languageOverrideFileName = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($overrideFile);
-                               \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($LOCAL_LANG, $this->getParsedData($languageOverrideFileName, $languageKey, $charset, $errorMode, TRUE));
+                               $languageOverrideFileName = GeneralUtility::getFileAbsFileName($overrideFile);
+                               ArrayUtility::mergeRecursiveWithOverrule($LOCAL_LANG, $this->getParsedData($languageOverrideFileName, $languageKey, $charset, $errorMode, TRUE));
                        }
                }
        }
index 8d2c737..36d318e 100644 (file)
@@ -14,6 +14,11 @@ 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;
+
 /**
  * Abstract class for XML based parser.
  *
@@ -50,13 +55,13 @@ abstract class AbstractXmlParser implements \TYPO3\CMS\Core\Localization\Parser\
                $this->languageKey = $languageKey;
                $this->charset = $this->getCharset($languageKey, $charset);
                if ($this->languageKey !== 'default') {
-                       $this->sourcePath = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName(\TYPO3\CMS\Core\Utility\GeneralUtility::llXmlAutoFileName($this->sourcePath, $this->languageKey));
+                       $this->sourcePath = GeneralUtility::getFileAbsFileName(GeneralUtility::llXmlAutoFileName($this->sourcePath, $this->languageKey));
                        if (!@is_file($this->sourcePath)) {
                                // Global localization is not available, try split localization file
-                               $this->sourcePath = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName(\TYPO3\CMS\Core\Utility\GeneralUtility::llXmlAutoFileName($sourcePath, $languageKey, TRUE));
+                               $this->sourcePath = GeneralUtility::getFileAbsFileName(GeneralUtility::llXmlAutoFileName($sourcePath, $languageKey, TRUE));
                        }
                        if (!@is_file($this->sourcePath)) {
-                               throw new \TYPO3\CMS\Core\Localization\Exception\FileNotFoundException('Localization file does not exist', 1306332397);
+                               throw new FileNotFoundException('Localization file does not exist', 1306332397);
                        }
                }
                $LOCAL_LANG = array();
@@ -72,16 +77,16 @@ abstract class AbstractXmlParser implements \TYPO3\CMS\Core\Localization\Parser\
         * @return string
         */
        protected function getCharset($languageKey, $charset = '') {
-               /** @var $csConvObj \TYPO3\CMS\Core\Charset\CharsetConverter */
+               /** @var $charsetConverter CharsetConverter */
                if (is_object($GLOBALS['LANG'])) {
-                       $csConvObj = $GLOBALS['LANG']->csConvObj;
+                       $charsetConverter = $GLOBALS['LANG']->csConvObj;
                } elseif (is_object($GLOBALS['TSFE'])) {
-                       $csConvObj = $GLOBALS['TSFE']->csConvObj;
+                       $charsetConverter = $GLOBALS['TSFE']->csConvObj;
                } else {
-                       $csConvObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Charset\CharsetConverter::class);
+                       $charsetConverter = GeneralUtility::makeInstance(CharsetConverter::class);
                }
                if ($charset !== '') {
-                       $targetCharset = $csConvObj->parse_charset($charset);
+                       $targetCharset = $charsetConverter->parse_charset($charset);
                } else {
                        $targetCharset = 'utf-8';
                }
@@ -97,7 +102,7 @@ abstract class AbstractXmlParser implements \TYPO3\CMS\Core\Localization\Parser\
        protected function parseXmlFile() {
                $rootXmlNode = simplexml_load_file($this->sourcePath, 'SimpleXmlElement', \LIBXML_NOWARNING);
                if (!isset($rootXmlNode) || $rootXmlNode === FALSE) {
-                       throw new \TYPO3\CMS\Core\Localization\Exception\InvalidXmlFileException('The path provided does not point to existing and accessible well-formed XML file.', 1278155988);
+                       throw new InvalidXmlFileException('The path provided does not point to existing and accessible well-formed XML file.', 1278155988);
                }
                return $this->doParsingFromRoot($rootXmlNode);
        }
@@ -105,7 +110,7 @@ abstract class AbstractXmlParser implements \TYPO3\CMS\Core\Localization\Parser\
        /**
         * Returns array representation of XML data, starting from a root node.
         *
-        * @param SimpleXMLElement $root A root node
+        * @param \SimpleXMLElement $root A root node
         * @return array An array representing the parsed XML file
         */
        abstract protected function doParsingFromRoot(\SimpleXMLElement $root);
index 096e196..2349cff 100644 (file)
@@ -14,6 +14,10 @@ namespace TYPO3\CMS\Core\Localization\Parser;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Utility\PathUtility;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Charset\CharsetConverter;
+
 /**
  * Parser for PHP locallang array.
  *
@@ -54,10 +58,9 @@ class LocallangArrayParser implements LocalizationParserInterface {
         * Initializes the parser.
         *
         * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8. Use xlf format for parsing translations
-        * @return void
         */
        public function __construct() {
-               \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
+               GeneralUtility::logDeprecatedFunction();
                $this->createCsConvObject();
        }
 
@@ -114,7 +117,7 @@ class LocallangArrayParser implements LocalizationParserInterface {
                } elseif (is_object($GLOBALS['TSFE'])) {
                        $this->csConvObj = $GLOBALS['TSFE']->csConvObj;
                } else {
-                       $this->csConvObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Charset\CharsetConverter::class);
+                       $this->csConvObj = GeneralUtility::makeInstance(CharsetConverter::class);
                }
        }
 
@@ -131,7 +134,7 @@ class LocallangArrayParser implements LocalizationParserInterface {
                // Get PHP data
                include $sourcePath;
                if (!is_array($LOCAL_LANG)) {
-                       $fileName = \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($sourcePath);
+                       $fileName = PathUtility::stripPathSitePrefix($sourcePath);
                        throw new \RuntimeException('TYPO3 Fatal Error: "' . $fileName . '" is no TYPO3 language file!', 1308898491);
                }
                // Converting the default language (English)
@@ -142,7 +145,7 @@ class LocallangArrayParser implements LocalizationParserInterface {
                        }
                        unset($labelValue);
                }
-               if ($languageKey !== 'default' && is_array($LOCAL_LANG[$languageKey]) && $this->sourceCharset != $this->targetCharset) {
+               if ($languageKey !== 'default' && is_array($LOCAL_LANG[$languageKey]) && $this->sourceCharset !== $this->targetCharset) {
                        foreach ($LOCAL_LANG[$languageKey] as &$labelValue) {
                                $labelValue = $this->csConvObj->conv($labelValue, $this->sourceCharset, $this->targetCharset);
                        }
@@ -154,7 +157,7 @@ class LocallangArrayParser implements LocalizationParserInterface {
                } else {
                        $serContent = array('origFile' => $this->hashSource, 'LOCAL_LANG' => array('default' => $LOCAL_LANG['default']));
                }
-               $res = \TYPO3\CMS\Core\Utility\GeneralUtility::writeFileToTypo3tempDir($this->cacheFileName, serialize($serContent));
+               $res = GeneralUtility::writeFileToTypo3tempDir($this->cacheFileName, serialize($serContent));
                if ($res) {
                        throw new \RuntimeException('TYPO3 Fatal Error: "' . $res, 1308898501);
                }
@@ -169,8 +172,8 @@ class LocallangArrayParser implements LocalizationParserInterface {
         * @return void
         */
        protected function generateCacheFileName($sourcePath, $languageKey) {
-               $this->hashSource = \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($sourcePath) . '|' . date('d-m-Y H:i:s', filemtime($sourcePath)) . '|version=2.3';
-               $this->cacheFileName = PATH_site . 'typo3temp/llxml/' . substr(basename($sourcePath), 10, 15) . '_' . \TYPO3\CMS\Core\Utility\GeneralUtility::shortMD5($this->hashSource) . '.' . $languageKey . '.' . $this->targetCharset . '.cache';
+               $this->hashSource = PathUtility::stripPathSitePrefix($sourcePath) . '|' . date('d-m-Y H:i:s', filemtime($sourcePath)) . '|version=2.3';
+               $this->cacheFileName = PATH_site . 'typo3temp/llxml/' . substr(basename($sourcePath), 10, 15) . '_' . GeneralUtility::shortMD5($this->hashSource) . '.' . $languageKey . '.' . $this->targetCharset . '.cache';
        }
 
        /**
@@ -191,7 +194,7 @@ class LocallangArrayParser implements LocalizationParserInterface {
         * @return bool
         */
        protected function isWithinWebRoot($fileName) {
-               return (bool)\TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($fileName);
+               return (bool)GeneralUtility::getFileAbsFileName($fileName);
        }
 
        /**
index 2d5cff5..d192413 100644 (file)
@@ -14,6 +14,10 @@ namespace TYPO3\CMS\Core\Localization\Parser;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Utility\ArrayUtility;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Localization\Exception\InvalidXmlFileException;
+
 /**
  * Parser for XML locallang file.
  *
@@ -43,23 +47,23 @@ class LocallangXmlParser extends AbstractXmlParser {
                // Parse source
                $parsedSource = $this->parseXmlFile();
                // Parse target
-               $localizedTargetPath = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName(\TYPO3\CMS\Core\Utility\GeneralUtility::llXmlAutoFileName($this->sourcePath, $this->languageKey));
+               $localizedTargetPath = GeneralUtility::getFileAbsFileName(GeneralUtility::llXmlAutoFileName($this->sourcePath, $this->languageKey));
                $targetPath = $this->languageKey !== 'default' && @is_file($localizedTargetPath) ? $localizedTargetPath : $this->sourcePath;
                try {
                        $parsedTarget = $this->getParsedTargetData($targetPath);
-               } catch (\TYPO3\CMS\Core\Localization\Exception\InvalidXmlFileException $e) {
+               } catch (InvalidXmlFileException $e) {
                        $parsedTarget = $this->getParsedTargetData($this->sourcePath);
                }
                $LOCAL_LANG = array();
                $LOCAL_LANG[$languageKey] = $parsedSource;
-               \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($LOCAL_LANG[$languageKey], $parsedTarget);
+               ArrayUtility::mergeRecursiveWithOverrule($LOCAL_LANG[$languageKey], $parsedTarget);
                return $LOCAL_LANG;
        }
 
        /**
         * Returns array representation of XLIFF data, starting from a root node.
         *
-        * @param SimpleXMLElement $root XML root element
+        * @param \SimpleXMLElement $root XML root element
         * @param string $element Target or Source
         * @return array
         */
@@ -94,18 +98,17 @@ class LocallangXmlParser extends AbstractXmlParser {
        protected function getParsedDataForElement(\SimpleXMLElement $bodyOfFileTag, $element) {
                $parsedData = array();
                $children = $bodyOfFileTag->children();
-               if ($children->count() == 0) {
+               if ($children->count() === 0) {
                        // Check for externally-referenced resource:
                        // <languageKey index="fr">EXT:yourext/path/to/localized/locallang.xml</languageKey>
                        $reference = sprintf('%s', $bodyOfFileTag);
                        if (substr($reference, -4) === '.xml') {
-                               return $this->getParsedTargetData(\TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($reference));
+                               return $this->getParsedTargetData(GeneralUtility::getFileAbsFileName($reference));
                        }
                }
                /** @var \SimpleXMLElement $translationElement */
                foreach ($children as $translationElement) {
                        if ($translationElement->getName() === 'label') {
-                               // If restype would be set, it could be metadata from Gettext to XLIFF conversion (and we don't need this data)
                                $parsedData[(string)$translationElement['index']][0] = array(
                                        $element => (string)$translationElement
                                );
@@ -162,7 +165,7 @@ class LocallangXmlParser extends AbstractXmlParser {
                        $rootXmlNode = simplexml_load_file($targetPath, 'SimpleXmlElement', \LIBXML_NOWARNING);
                }
                if (!isset($rootXmlNode) || $rootXmlNode === FALSE) {
-                       throw new \TYPO3\CMS\Core\Localization\Exception\InvalidXmlFileException('The path provided does not point to existing and accessible well-formed XML file (' . $targetPath . ').', 1278155987);
+                       throw new InvalidXmlFileException('The path provided does not point to existing and accessible well-formed XML file (' . $targetPath . ').', 1278155987);
                }
                return $this->doParsingTargetFromRoot($rootXmlNode);
        }
index 4c057c0..41b8892 100644 (file)
@@ -24,7 +24,7 @@ class XliffParser extends AbstractXmlParser {
        /**
         * Returns array representation of XML data, starting from a root node.
         *
-        * @param SimpleXMLElement $root A root node
+        * @param \SimpleXMLElement $root A root node
         * @return array An array representing the parsed XML file
         */
        protected function doParsingFromRoot(\SimpleXMLElement $root) {
@@ -32,6 +32,7 @@ class XliffParser extends AbstractXmlParser {
                $bodyOfFileTag = $root->file->body;
                if ($bodyOfFileTag instanceof \SimpleXMLElement) {
                        foreach ($bodyOfFileTag->children() as $translationElement) {
+                               /** @var \SimpleXMLElement $translationElement */
                                if ($translationElement->getName() === 'trans-unit' && !isset($translationElement['restype'])) {
                                        // If restype would be set, it could be metadata from Gettext to XLIFF conversion (and we don't need this data)
                                        if ($this->languageKey === 'default') {
@@ -51,6 +52,7 @@ class XliffParser extends AbstractXmlParser {
                                        // This is a translation with plural forms
                                        $parsedTranslationElement = array();
                                        foreach ($translationElement->children() as $translationPluralForm) {
+                                               /** @var \SimpleXMLElement $translationPluralForm */
                                                if ($translationPluralForm->getName() === 'trans-unit') {
                                                        // When using plural forms, ID looks like this: 1[0], 1[1] etc
                                                        $formIndex = substr((string)$translationPluralForm['id'], strpos((string)$translationPluralForm['id'], '[') + 1, -1);