‪TYPO3CMS  9.5
LanguageStore.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
21 
26 {
32  protected ‪$supportedExtensions;
33 
42  protected ‪$configuration;
43 
49  protected ‪$data;
50 
54  public function ‪__construct()
55  {
56  $this->‪initialize();
57  }
58 
62  public function ‪initialize()
63  {
64  if (isset(‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['format']['priority']) && trim(‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['format']['priority']) !== '') {
65  $this->supportedExtensions = GeneralUtility::trimExplode(',', ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['format']['priority']);
66  } else {
67  $this->supportedExtensions = ['xlf', 'xml'];
68  }
69  }
70 
78  public function ‪hasData($fileReference, $languageKey)
79  {
80  if (isset($this->data[$fileReference][$languageKey]) && is_array($this->data[$fileReference][$languageKey])) {
81  return true;
82  }
83  return false;
84  }
85 
94  public function ‪getData($fileReference)
95  {
96  return $this->data[$fileReference];
97  }
98 
107  public function ‪getDataByLanguage($fileReference, $languageKey)
108  {
109  return $this->data[$fileReference][$languageKey] ?? [];
110  }
111 
120  public function ‪setData($fileReference, $languageKey, ‪$data)
121  {
122  $this->data[$fileReference][$languageKey] = ‪$data;
123  return $this;
124  }
125 
132  public function ‪flushData($fileReference)
133  {
134  unset($this->data[$fileReference]);
135  return $this;
136  }
137 
147  public function ‪setConfiguration($fileReference, $languageKey)
148  {
149  $this->configuration[$fileReference] = [
150  'fileReference' => $fileReference,
151  'fileExtension' => false,
152  'parserClass' => null,
153  'languageKey' => $languageKey
154  ];
155  $fileWithoutExtension = GeneralUtility::getFileAbsFileName($this->‪getFileReferenceWithoutExtension($fileReference));
156  foreach ($this->supportedExtensions as $extension) {
157  if (@is_file($fileWithoutExtension . '.' . $extension)) {
158  $this->configuration[$fileReference]['fileReference'] = $fileWithoutExtension . '.' . $extension;
159  $this->configuration[$fileReference]['fileExtension'] = $extension;
160  break;
161  }
162  }
163  if ($this->configuration[$fileReference]['fileExtension'] === false) {
164  throw new ‪FileNotFoundException(sprintf('Source localization file (%s) not found', $fileReference), 1306410755);
165  }
166  $extension = $this->configuration[$fileReference]['fileExtension'];
167  if (isset(‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['parser'][$extension]) && trim(‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['parser'][$extension]) !== '') {
168  $this->configuration[$fileReference]['parserClass'] = ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['parser'][$extension];
169  } else {
170  throw new ‪InvalidParserException('TYPO3 Fatal Error: l10n parser for file extension "' . $extension . '" is not configured! Please check you configuration.', 1301579637);
171  }
172  if (!class_exists($this->configuration[$fileReference]['parserClass']) || trim($this->configuration[$fileReference]['parserClass']) === '') {
173  throw new ‪InvalidParserException('TYPO3 Fatal Error: l10n parser "' . $this->configuration[$fileReference]['parserClass'] . '" cannot be found or is an empty parser!', 1270853900);
174  }
175  return $this;
176  }
177 
184  public function ‪getFileReferenceWithoutExtension($fileReference)
185  {
186  if (!isset($this->configuration[$fileReference]['fileReferenceWithoutExtension'])) {
187  $this->configuration[$fileReference]['fileReferenceWithoutExtension'] = preg_replace('/\\.[a-z0-9]+$/i', '', $fileReference);
188  }
189  return $this->configuration[$fileReference]['fileReferenceWithoutExtension'];
190  }
191 
199  public function ‪getParserInstance($fileReference)
200  {
201  if (isset($this->configuration[$fileReference]['parserClass']) && trim($this->configuration[$fileReference]['parserClass']) !== '') {
202  return GeneralUtility::makeInstance((string)$this->configuration[$fileReference]['parserClass']);
203  }
204  throw new ‪InvalidParserException(sprintf('Invalid parser configuration for the current file (%s)', $fileReference), 1307293692);
205  }
206 
214  public function ‪getAbsoluteFileReference($fileReference)
215  {
216  if (isset($this->configuration[$fileReference]['fileReference']) && trim($this->configuration[$fileReference]['fileReference']) !== '') {
217  return (string)$this->configuration[$fileReference]['fileReference'];
218  }
219  throw new \InvalidArgumentException(sprintf('Invalid file reference configuration for the current file (%s)', $fileReference), 1307293693);
220  }
221 
227  public function ‪getSupportedExtensions()
228  {
230  }
231 }
‪TYPO3\CMS\Core\Localization\LanguageStore\setConfiguration
‪TYPO3 CMS Core Localization LanguageStore setConfiguration($fileReference, $languageKey)
Definition: LanguageStore.php:144
‪TYPO3\CMS\Core\Localization\LanguageStore\initialize
‪initialize()
Definition: LanguageStore.php:59
‪TYPO3\CMS\Core\Localization\LanguageStore\$supportedExtensions
‪array $supportedExtensions
Definition: LanguageStore.php:31
‪TYPO3\CMS\Core\Localization\Exception\FileNotFoundException
Definition: FileNotFoundException.php:21
‪TYPO3\CMS\Core\Localization\LanguageStore\getAbsoluteFileReference
‪string getAbsoluteFileReference($fileReference)
Definition: LanguageStore.php:211
‪TYPO3\CMS\Core\Localization\LanguageStore\getData
‪array getData($fileReference)
Definition: LanguageStore.php:91
‪TYPO3\CMS\Core\Localization\LanguageStore\getFileReferenceWithoutExtension
‪string getFileReferenceWithoutExtension($fileReference)
Definition: LanguageStore.php:181
‪TYPO3\CMS\Core\Localization
‪TYPO3\CMS\Core\Localization\LanguageStore\$configuration
‪array $configuration
Definition: LanguageStore.php:40
‪TYPO3\CMS\Core\Localization\LanguageStore
Definition: LanguageStore.php:26
‪TYPO3\CMS\Core\Localization\LanguageStore\getParserInstance
‪TYPO3 CMS Core Localization Parser LocalizationParserInterface getParserInstance($fileReference)
Definition: LanguageStore.php:196
‪TYPO3\CMS\Core\Localization\LanguageStore\getDataByLanguage
‪array getDataByLanguage($fileReference, $languageKey)
Definition: LanguageStore.php:104
‪TYPO3\CMS\Core\Localization\LanguageStore\getSupportedExtensions
‪array getSupportedExtensions()
Definition: LanguageStore.php:224
‪TYPO3\CMS\Core\Localization\LanguageStore\$data
‪array $data
Definition: LanguageStore.php:46
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:22
‪$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:75
‪TYPO3\CMS\Core\Localization\LanguageStore\flushData
‪TYPO3 CMS Core Localization LanguageStore flushData($fileReference)
Definition: LanguageStore.php:129
‪TYPO3\CMS\Core\Localization\Exception\InvalidParserException
Definition: InvalidParserException.php:21
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Localization\LanguageStore\setData
‪TYPO3 CMS Core Localization LanguageStore setData($fileReference, $languageKey, $data)
Definition: LanguageStore.php:117
‪TYPO3\CMS\Core\Localization\LanguageStore\__construct
‪__construct()
Definition: LanguageStore.php:51