TYPO3 CMS  TYPO3_8-7
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 
20 
25 {
32 
41  protected $configuration;
42 
48  protected $data;
49 
53  public function __construct()
54  {
55  $this->initialize();
56  }
57 
61  public function initialize()
62  {
63  if (isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['format']['priority']) && trim($GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['format']['priority']) !== '') {
64  $this->supportedExtensions = GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['format']['priority']);
65  } else {
66  $this->supportedExtensions = ['xlf', 'xml'];
67  }
68  }
69 
77  public function hasData($fileReference, $languageKey)
78  {
79  if (isset($this->data[$fileReference][$languageKey]) && is_array($this->data[$fileReference][$languageKey])) {
80  return true;
81  }
82  return false;
83  }
84 
93  public function getData($fileReference)
94  {
95  return $this->data[$fileReference];
96  }
97 
106  public function getDataByLanguage($fileReference, $languageKey)
107  {
108  return $this->data[$fileReference][$languageKey] ?? [];
109  }
110 
119  public function setData($fileReference, $languageKey, $data)
120  {
121  $this->data[$fileReference][$languageKey] = $data;
122  return $this;
123  }
124 
131  public function flushData($fileReference)
132  {
133  unset($this->data[$fileReference]);
134  return $this;
135  }
136 
147  public function setConfiguration($fileReference, $languageKey, $charset)
148  {
149  $this->configuration[$fileReference] = [
150  'fileReference' => $fileReference,
151  'fileExtension' => false,
152  'parserClass' => null,
153  'languageKey' => $languageKey,
154  'charset' => $charset
155  ];
156  $fileWithoutExtension = GeneralUtility::getFileAbsFileName($this->getFileReferenceWithoutExtension($fileReference));
157  foreach ($this->supportedExtensions as $extension) {
158  if (@is_file($fileWithoutExtension . '.' . $extension)) {
159  $this->configuration[$fileReference]['fileReference'] = $fileWithoutExtension . '.' . $extension;
160  $this->configuration[$fileReference]['fileExtension'] = $extension;
161  break;
162  }
163  }
164  if ($this->configuration[$fileReference]['fileExtension'] === false) {
165  throw new FileNotFoundException(sprintf('Source localization file (%s) not found', $fileReference), 1306410755);
166  }
167  $extension = $this->configuration[$fileReference]['fileExtension'];
168  if (isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['parser'][$extension]) && trim($GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['parser'][$extension]) !== '') {
169  $this->configuration[$fileReference]['parserClass'] = $GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['parser'][$extension];
170  } else {
171  throw new InvalidParserException('TYPO3 Fatal Error: l10n parser for file extension "' . $extension . '" is not configured! Please check you configuration.', 1301579637);
172  }
173  if (!class_exists($this->configuration[$fileReference]['parserClass']) || trim($this->configuration[$fileReference]['parserClass']) === '') {
174  throw new InvalidParserException('TYPO3 Fatal Error: l10n parser "' . $this->configuration[$fileReference]['parserClass'] . '" cannot be found or is an empty parser!', 1270853900);
175  }
176  return $this;
177  }
178 
185  public function getFileReferenceWithoutExtension($fileReference)
186  {
187  if (!isset($this->configuration[$fileReference]['fileReferenceWithoutExtension'])) {
188  $this->configuration[$fileReference]['fileReferenceWithoutExtension'] = preg_replace('/\\.[a-z0-9]+$/i', '', $fileReference);
189  }
190  return $this->configuration[$fileReference]['fileReferenceWithoutExtension'];
191  }
192 
200  public function getParserInstance($fileReference)
201  {
202  if (isset($this->configuration[$fileReference]['parserClass']) && trim($this->configuration[$fileReference]['parserClass']) !== '') {
203  return GeneralUtility::makeInstance((string)$this->configuration[$fileReference]['parserClass']);
204  }
205  throw new InvalidParserException(sprintf('Invalid parser configuration for the current file (%s)', $fileReference), 1307293692);
206  }
207 
215  public function getAbsoluteFileReference($fileReference)
216  {
217  if (isset($this->configuration[$fileReference]['fileReference']) && trim($this->configuration[$fileReference]['fileReference']) !== '') {
218  return (string)$this->configuration[$fileReference]['fileReference'];
219  }
220  throw new \InvalidArgumentException(sprintf('Invalid file reference configuration for the current file (%s)', $fileReference), 1307293693);
221  }
222 
228  public function getSupportedExtensions()
229  {
231  }
232 }
setData($fileReference, $languageKey, $data)
hasData($fileReference, $languageKey)
setConfiguration($fileReference, $languageKey, $charset)
static getFileAbsFileName($filename, $_=null, $_2=null)
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
static makeInstance($className,... $constructorArguments)
getDataByLanguage($fileReference, $languageKey)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']