‪TYPO3CMS  9.5
LocaleModifier.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
5 
6 /*
7  * This file is part of the TYPO3 CMS project.
8  *
9  * It is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License, either version 2
11  * of the License, or any later version.
12  *
13  * For the full copyright and license information, please read the
14  * LICENSE.txt file that was distributed with this source code.
15  *
16  * The TYPO3 project - inspiring people to share!
17  */
18 
21 
49 {
51 
55  protected ‪$settings;
56 
60  protected ‪$localeMap;
61 
65  protected ‪$default;
66 
71  public function ‪__construct(array ‪$settings)
72  {
73  ‪$localeMap = ‪$settings['localeMap'] ?? null;
74  ‪$default = ‪$settings['default'] ?? null;
75 
76  if (!is_array(‪$localeMap)) {
77  throw new \InvalidArgumentException('localeMap must be array', 1537277153);
78  }
79  if (!is_string(‪$default ?? '')) {
80  throw new \InvalidArgumentException('default must be string', 1537277154);
81  }
82 
83  $this->settings = ‪$settings;
84  $this->localeMap = ‪$localeMap;
85  $this->default = ‪$default;
86  }
87 
91  public function ‪modify(): ?string
92  {
93  $locale = $this->siteLanguage->getLocale();
94  foreach ($this->localeMap as $item) {
95  $pattern = '#^' . $item['locale'] . '#i';
96  if (preg_match($pattern, $locale)) {
97  return (string)$item['value'];
98  }
99  }
100  return ‪$this->default;
101  }
102 }
‪TYPO3\CMS\Core\Site\SiteLanguageAwareTrait
Definition: SiteLanguageAwareTrait.php:25
‪TYPO3\CMS\Core\Site\SiteLanguageAwareInterface
Definition: SiteLanguageAwareInterface.php:23
‪TYPO3\CMS\Core\Routing\Aspect\LocaleModifier\__construct
‪__construct(array $settings)
Definition: LocaleModifier.php:68
‪TYPO3\CMS\Core\Routing\Aspect
Definition: AspectFactory.php:4
‪TYPO3\CMS\Core\Routing\Aspect\LocaleModifier\$settings
‪array $settings
Definition: LocaleModifier.php:54
‪TYPO3\CMS\Core\Routing\Aspect\LocaleModifier\modify
‪modify()
Definition: LocaleModifier.php:88
‪TYPO3\CMS\Core\Routing\Aspect\ModifiableAspectInterface
Definition: ModifiableAspectInterface.php:24
‪TYPO3\CMS\Core\Routing\Aspect\LocaleModifier\$localeMap
‪array $localeMap
Definition: LocaleModifier.php:58
‪TYPO3\CMS\Core\Routing\Aspect\LocaleModifier\$default
‪string $default
Definition: LocaleModifier.php:62
‪TYPO3\CMS\Core\Routing\Aspect\LocaleModifier
Definition: LocaleModifier.php:49