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