TYPO3 CMS  TYPO3_6-2
LanguageStore.php
Go to the documentation of this file.
1 <?php
3 
22 
29 
38  protected $configuration;
39 
45  protected $data;
46 
50  public function __construct() {
51  $this->initialize();
52  }
53 
59  public function initialize() {
60  if (isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['format']['priority']) && trim($GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['format']['priority']) !== '') {
61  $this->supportedExtensions = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['format']['priority']);
62  } else {
63  $this->supportedExtensions = array('xlf', 'xml', 'php');
64  }
65  }
66 
74  public function hasData($fileReference, $languageKey) {
75  if (isset($this->data[$fileReference][$languageKey]) && is_array($this->data[$fileReference][$languageKey])) {
76  return TRUE;
77  }
78  return FALSE;
79  }
80 
89  public function getData($fileReference) {
90  return $this->data[$fileReference];
91  }
92 
101  public function getDataByLanguage($fileReference, $languageKey) {
102  return $this->data[$fileReference][$languageKey];
103  }
104 
113  public function setData($fileReference, $languageKey, $data) {
114  $this->data[$fileReference][$languageKey] = $data;
115  return $this;
116  }
117 
124  public function flushData($fileReference) {
125  unset($this->data[$fileReference]);
126  return $this;
127  }
128 
139  public function setConfiguration($fileReference, $languageKey, $charset) {
140  $this->configuration[$fileReference] = array(
141  'fileReference' => $fileReference,
142  'fileExtension' => FALSE,
143  'parserClass' => NULL,
144  'languageKey' => $languageKey,
145  'charset' => $charset
146  );
148  foreach ($this->supportedExtensions as $extension) {
149  if (@is_file(($fileWithoutExtension . '.' . $extension))) {
150  $this->configuration[$fileReference]['fileReference'] = $fileWithoutExtension . '.' . $extension;
151  $this->configuration[$fileReference]['fileExtension'] = $extension;
152  break;
153  }
154  }
155  if ($this->configuration[$fileReference]['fileExtension'] === FALSE) {
156  throw new \TYPO3\CMS\Core\Localization\Exception\FileNotFoundException(sprintf('Source localization file (%s) not found', $fileReference), 1306410755);
157  }
158  $extension = $this->configuration[$fileReference]['fileExtension'];
159  if (isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['parser'][$extension]) && trim($GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['parser'][$extension]) !== '') {
160  $this->configuration[$fileReference]['parserClass'] = $GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['parser'][$extension];
161  } else {
162  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);
163  }
164  if (!class_exists($this->configuration[$fileReference]['parserClass']) || trim($this->configuration[$fileReference]['parserClass']) === '') {
165  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);
166  }
167  return $this;
168  }
169 
176  public function getFileReferenceWithoutExtension($fileReference) {
177  if (!isset($this->configuration[$fileReference]['fileReferenceWithoutExtension'])) {
178  $this->configuration[$fileReference]['fileReferenceWithoutExtension'] = preg_replace('/\\.[a-z0-9]+$/i', '', $fileReference);
179  }
180  return $this->configuration[$fileReference]['fileReferenceWithoutExtension'];
181  }
182 
190  public function getParserInstance($fileReference) {
191  if (isset($this->configuration[$fileReference]['parserClass']) && trim($this->configuration[$fileReference]['parserClass']) !== '') {
192  return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance((string) $this->configuration[$fileReference]['parserClass']);
193  } else {
194  throw new \TYPO3\CMS\Core\Localization\Exception\InvalidParserException(sprintf('Invalid parser configuration for the current file (%s)', $fileReference), 1307293692);
195  }
196  }
197 
205  public function getAbsoluteFileReference($fileReference) {
206  if (isset($this->configuration[$fileReference]['fileReference']) && trim($this->configuration[$fileReference]['fileReference']) !== '') {
207  return (string) $this->configuration[$fileReference]['fileReference'];
208  } else {
209  throw new \InvalidArgumentException(sprintf('Invalid file reference configuration for the current file (%s)', $fileReference), 1307293693);
210  }
211  }
212 
218  public function getSupportedExtensions() {
220  }
221 
222 }
setData($fileReference, $languageKey, $data)
hasData($fileReference, $languageKey)
setConfiguration($fileReference, $languageKey, $charset)
static trimExplode($delim, $string, $removeEmptyValues=FALSE, $limit=0)
getDataByLanguage($fileReference, $languageKey)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
static getFileAbsFileName($filename, $onlyRelative=TRUE, $relToTYPO3_mainDir=FALSE)