‪TYPO3CMS  9.5
StaticValueMapper.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 
54 {
56 
60  protected ‪$settings;
61 
65  protected ‪$map;
66 
70  protected ‪$localeMap;
71 
76  public function ‪__construct(array ‪$settings)
77  {
78  ‪$map = ‪$settings['map'] ?? null;
79  ‪$localeMap = ‪$settings['localeMap'] ?? [];
80 
81  if (!is_array(‪$map)) {
82  throw new \InvalidArgumentException('map must be array', 1537277143);
83  }
84  if (!is_array(‪$localeMap)) {
85  throw new \InvalidArgumentException('localeMap must be array', 1537277144);
86  }
87 
88  $this->settings = ‪$settings;
89  $this->map = array_map('strval', ‪$map);
90  $this->localeMap = ‪$localeMap;
91  }
92 
96  public function ‪count(): int
97  {
98  return ‪count($this->‪retrieveLocaleMap() ?? $this->map);
99  }
100 
104  public function ‪generate(string $value): ?string
105  {
107  $index = array_search($value, ‪$map, true);
108  return $index !== false ? (string)$index : null;
109  }
110 
114  public function ‪resolve(string $value): ?string
115  {
117  return isset(‪$map[$value]) ? (string)‪$map[$value] : null;
118  }
119 
125  protected function ‪retrieveLocaleMap(): ?array
126  {
127  $locale = $this->siteLanguage->getLocale();
128  foreach ($this->localeMap as $item) {
129  $pattern = '#^' . $item['locale'] . '#i';
130  if (preg_match($pattern, $locale)) {
131  return array_map('strval', $item['map']);
132  }
133  }
134  return null;
135  }
136 }
‪TYPO3\CMS\Core\Routing\Aspect\StaticValueMapper\resolve
‪resolve(string $value)
Definition: StaticValueMapper.php:111
‪TYPO3\CMS\Core\Site\SiteLanguageAwareTrait
Definition: SiteLanguageAwareTrait.php:25
‪TYPO3\CMS\Core\Routing\Aspect\StaticValueMapper\generate
‪generate(string $value)
Definition: StaticValueMapper.php:101
‪TYPO3\CMS\Core\Site\SiteLanguageAwareInterface
Definition: SiteLanguageAwareInterface.php:23
‪TYPO3\CMS\Core\Routing\Aspect\StaticValueMapper\count
‪count()
Definition: StaticValueMapper.php:93
‪TYPO3\CMS\Core\Routing\Aspect\StaticValueMapper
Definition: StaticValueMapper.php:54
‪TYPO3\CMS\Core\Routing\Aspect\StaticValueMapper\$localeMap
‪array $localeMap
Definition: StaticValueMapper.php:67
‪TYPO3\CMS\Core\Routing\Aspect\StaticValueMapper\__construct
‪__construct(array $settings)
Definition: StaticValueMapper.php:73
‪TYPO3\CMS\Core\Routing\Aspect
Definition: AspectFactory.php:4
‪TYPO3\CMS\Core\Routing\Aspect\StaticMappableAspectInterface
Definition: StaticMappableAspectInterface.php:23
‪TYPO3\CMS\Core\Routing\Aspect\StaticValueMapper\$map
‪array $map
Definition: StaticValueMapper.php:63
‪TYPO3\CMS\Core\Routing\Aspect\StaticValueMapper\$settings
‪array $settings
Definition: StaticValueMapper.php:59
‪TYPO3\CMS\Core\Routing\Aspect\StaticValueMapper\retrieveLocaleMap
‪array null retrieveLocaleMap()
Definition: StaticValueMapper.php:122