‪TYPO3CMS  10.4
LanguageStore.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
22 
27 {
33  protected ‪$supportedExtensions;
34 
43  protected ‪$configuration;
44 
50  protected $data;
51 
55  public function __construct()
56  {
57  $this->‪initialize();
58  }
59 
63  public function ‪initialize()
64  {
65  if (isset(‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['format']['priority']) && trim(‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['format']['priority']) !== '') {
66  $this->supportedExtensions = ‪GeneralUtility::trimExplode(',', ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['format']['priority']);
67  } else {
68  $this->supportedExtensions = ['xlf', 'xml'];
69  }
70  }
71 
79  public function ‪hasData($fileReference, $languageKey)
80  {
81  if (isset($this->‪data[$fileReference][$languageKey]) && is_array($this->‪data[$fileReference][$languageKey])) {
82  return true;
83  }
84  return false;
85  }
86 
96  public function getData($fileReference)
97  {
98  return $this->‪data[$fileReference];
99  }
100 
111  public function getDataByLanguage($fileReference, $languageKey)
112  {
113  return $this->‪data[$fileReference][$languageKey] ?? [];
114  }
115 
124  public function ‪setData($fileReference, $languageKey, $data)
125  {
126  $this->‪data[$fileReference][$languageKey] = $data;
127  return $this;
128  }
129 
136  public function ‪flushData($fileReference)
137  {
138  unset($this->‪data[$fileReference]);
139  return $this;
140  }
141 
151  public function ‪setConfiguration($fileReference, $languageKey)
152  {
153  $this->configuration[$fileReference] = [
154  'fileReference' => $fileReference,
155  'fileExtension' => false,
156  'parserClass' => null,
157  'languageKey' => $languageKey
158  ];
159  $fileWithoutExtension = GeneralUtility::getFileAbsFileName($this->‪getFileReferenceWithoutExtension($fileReference));
160  foreach ($this->supportedExtensions as $extension) {
161  if (@is_file($fileWithoutExtension . '.' . $extension)) {
162  $this->configuration[$fileReference]['fileReference'] = $fileWithoutExtension . '.' . $extension;
163  $this->configuration[$fileReference]['fileExtension'] = $extension;
164  break;
165  }
166  }
167  if ($this->configuration[$fileReference]['fileExtension'] === false) {
168  throw new ‪FileNotFoundException(sprintf('Source localization file (%s) not found', $fileReference), 1306410755);
169  }
170  $extension = $this->configuration[$fileReference]['fileExtension'];
171  if (isset(‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['parser'][$extension]) && trim(‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['parser'][$extension]) !== '') {
172  $this->configuration[$fileReference]['parserClass'] = ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['parser'][$extension];
173  } else {
174  throw new ‪InvalidParserException('TYPO3 Fatal Error: l10n parser for file extension "' . $extension . '" is not configured! Please check you configuration.', 1301579637);
175  }
176  if (!class_exists($this->configuration[$fileReference]['parserClass']) || trim($this->configuration[$fileReference]['parserClass']) === '') {
177  throw new ‪InvalidParserException('TYPO3 Fatal Error: l10n parser "' . $this->configuration[$fileReference]['parserClass'] . '" cannot be found or is an empty parser!', 1270853900);
178  }
179  return $this;
180  }
181 
188  public function ‪getFileReferenceWithoutExtension($fileReference)
189  {
190  if (!isset($this->configuration[$fileReference]['fileReferenceWithoutExtension'])) {
191  $this->configuration[$fileReference]['fileReferenceWithoutExtension'] = preg_replace('/\\.[a-z0-9]+$/i', '', $fileReference);
192  }
193  return $this->configuration[$fileReference]['fileReferenceWithoutExtension'];
194  }
195 
203  public function ‪getParserInstance($fileReference)
204  {
205  if (isset($this->configuration[$fileReference]['parserClass']) && trim($this->configuration[$fileReference]['parserClass']) !== '') {
206  return GeneralUtility::makeInstance((string)$this->configuration[$fileReference]['parserClass']);
207  }
208  throw new ‪InvalidParserException(sprintf('Invalid parser configuration for the current file (%s)', $fileReference), 1307293692);
209  }
210 
218  public function ‪getAbsoluteFileReference($fileReference)
219  {
220  if (isset($this->configuration[$fileReference]['fileReference']) && trim($this->configuration[$fileReference]['fileReference']) !== '') {
221  return (string)$this->configuration[$fileReference]['fileReference'];
222  }
223  throw new \InvalidArgumentException(sprintf('Invalid file reference configuration for the current file (%s)', $fileReference), 1307293693);
224  }
225 
231  public function ‪getSupportedExtensions()
232  {
234  }
235 }
‪TYPO3\CMS\Core\Localization\LanguageStore\setConfiguration
‪TYPO3 CMS Core Localization LanguageStore setConfiguration($fileReference, $languageKey)
Definition: LanguageStore.php:148
‪TYPO3\CMS\Core\Localization\LanguageStore\initialize
‪initialize()
Definition: LanguageStore.php:60
‪TYPO3\CMS\Core\Localization\LanguageStore\$supportedExtensions
‪array $supportedExtensions
Definition: LanguageStore.php:32
‪TYPO3\CMS\Core\Localization\Exception\FileNotFoundException
Definition: FileNotFoundException.php:22
‪TYPO3\CMS\Core\Localization\LanguageStore\getAbsoluteFileReference
‪string getAbsoluteFileReference($fileReference)
Definition: LanguageStore.php:215
‪TYPO3\CMS\Core\Localization\LanguageStore\getFileReferenceWithoutExtension
‪string getFileReferenceWithoutExtension($fileReference)
Definition: LanguageStore.php:185
‪TYPO3\CMS\Core\Localization
‪TYPO3\CMS\Core\Localization\LanguageStore\$configuration
‪array $configuration
Definition: LanguageStore.php:41
‪TYPO3\CMS\Core\Localization\LanguageStore
Definition: LanguageStore.php:27
‪TYPO3\CMS\Core\Localization\LanguageStore\getParserInstance
‪TYPO3 CMS Core Localization Parser LocalizationParserInterface getParserInstance($fileReference)
Definition: LanguageStore.php:200
‪TYPO3\CMS\Core\Localization\LanguageStore\data
‪array< string, function getData( $fileReference) { return $this-> data[$fileReference]
Definition: LanguageStore.php:95
‪TYPO3\CMS\Core\Localization\LanguageStore\getSupportedExtensions
‪array getSupportedExtensions()
Definition: LanguageStore.php:228
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static string[] trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
Definition: GeneralUtility.php:1059
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:23
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Localization\LanguageStore\hasData
‪bool hasData($fileReference, $languageKey)
Definition: LanguageStore.php:76
‪TYPO3\CMS\Core\Localization\LanguageStore\flushData
‪TYPO3 CMS Core Localization LanguageStore flushData($fileReference)
Definition: LanguageStore.php:133
‪TYPO3\CMS\Core\Localization\Exception\InvalidParserException
Definition: InvalidParserException.php:22
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Localization\LanguageStore\setData
‪TYPO3 CMS Core Localization LanguageStore setData($fileReference, $languageKey, $data)
Definition: LanguageStore.php:121
‪TYPO3\CMS\Core\Localization\LanguageStore\initialize
‪array< string, $data;public __construct() { $this-> initialize()