TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
LanguageStore.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Core\Localization;
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 
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 
95  public function getData($fileReference)
96  {
97  return $this->data[$fileReference];
98  }
99 
108  public function getDataByLanguage($fileReference, $languageKey)
109  {
110  return $this->data[$fileReference][$languageKey];
111  }
112 
121  public function setData($fileReference, $languageKey, $data)
122  {
123  $this->data[$fileReference][$languageKey] = $data;
124  return $this;
125  }
126 
133  public function flushData($fileReference)
134  {
135  unset($this->data[$fileReference]);
136  return $this;
137  }
138 
149  public function setConfiguration($fileReference, $languageKey, $charset)
150  {
151  $this->configuration[$fileReference] = [
152  'fileReference' => $fileReference,
153  'fileExtension' => false,
154  'parserClass' => null,
155  'languageKey' => $languageKey,
156  'charset' => $charset
157  ];
158  $fileWithoutExtension = GeneralUtility::getFileAbsFileName($this->getFileReferenceWithoutExtension($fileReference));
159  foreach ($this->supportedExtensions as $extension) {
160  if (@is_file(($fileWithoutExtension . '.' . $extension))) {
161  $this->configuration[$fileReference]['fileReference'] = $fileWithoutExtension . '.' . $extension;
162  $this->configuration[$fileReference]['fileExtension'] = $extension;
163  break;
164  }
165  }
166  if ($this->configuration[$fileReference]['fileExtension'] === false) {
167  throw new FileNotFoundException(sprintf('Source localization file (%s) not found', $fileReference), 1306410755);
168  }
169  $extension = $this->configuration[$fileReference]['fileExtension'];
170  if (isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['parser'][$extension]) && trim($GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['parser'][$extension]) !== '') {
171  $this->configuration[$fileReference]['parserClass'] = $GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['parser'][$extension];
172  } else {
173  throw new InvalidParserException('TYPO3 Fatal Error: l10n parser for file extension "' . $extension . '" is not configured! Please check you configuration.', 1301579637);
174  }
175  if (!class_exists($this->configuration[$fileReference]['parserClass']) || trim($this->configuration[$fileReference]['parserClass']) === '') {
176  throw new InvalidParserException('TYPO3 Fatal Error: l10n parser "' . $this->configuration[$fileReference]['parserClass'] . '" cannot be found or is an empty parser!', 1270853900);
177  }
178  return $this;
179  }
180 
187  public function getFileReferenceWithoutExtension($fileReference)
188  {
189  if (!isset($this->configuration[$fileReference]['fileReferenceWithoutExtension'])) {
190  $this->configuration[$fileReference]['fileReferenceWithoutExtension'] = preg_replace('/\\.[a-z0-9]+$/i', '', $fileReference);
191  }
192  return $this->configuration[$fileReference]['fileReferenceWithoutExtension'];
193  }
194 
202  public function getParserInstance($fileReference)
203  {
204  if (isset($this->configuration[$fileReference]['parserClass']) && trim($this->configuration[$fileReference]['parserClass']) !== '') {
205  return GeneralUtility::makeInstance((string)$this->configuration[$fileReference]['parserClass']);
206  } else {
207  throw new InvalidParserException(sprintf('Invalid parser configuration for the current file (%s)', $fileReference), 1307293692);
208  }
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  } else {
223  throw new \InvalidArgumentException(sprintf('Invalid file reference configuration for the current file (%s)', $fileReference), 1307293693);
224  }
225  }
226 
232  public function getSupportedExtensions()
233  {
235  }
236 }
setConfiguration($fileReference, $languageKey, $charset)
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
getDataByLanguage($fileReference, $languageKey)
if(TYPO3_MODE=== 'BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static makeInstance($className,...$constructorArguments)
static getFileAbsFileName($filename, $_=null, $_2=null)
setData($fileReference, $languageKey, $data)
hasData($fileReference, $languageKey)