‪TYPO3CMS  9.5
ModeRegistry.php
Go to the documentation of this file.
1 <?php
2 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 
22 
28 {
32  protected ‪$registeredModes = [];
33 
37  protected ‪$defaultMode;
38 
43  public static function ‪getInstance(): ‪ModeRegistry
44  {
45  return GeneralUtility::makeInstance(static::class);
46  }
47 
54  public function register(‪Mode $mode): ‪ModeRegistry
55  {
56  $this->registeredModes[$mode->getIdentifier()] = $mode;
57  if ($mode->isDefault()) {
58  $this->defaultMode = $mode;
59  }
60 
61  return $this;
62  }
63 
70  public function ‪unregister(string $identifier): ‪ModeRegistry
71  {
72  if (isset($this->registeredModes[$identifier])) {
73  unset($this->registeredModes[$identifier]);
74  }
75 
76  return $this;
77  }
78 
83  public function ‪isRegistered(string $identifier): bool
84  {
85  return isset($this->registeredModes[$identifier]);
86  }
87 
93  public function ‪getByIdentifier(string $identifier): ‪Mode
94  {
95  if ($this->‪isRegistered($identifier)) {
96  return $this->registeredModes[$identifier];
97  }
98 
99  throw new ‪InvalidModeException('Tried to get unregistered t3editor mode "' . $identifier . '"', 1499710202);
100  }
101 
107  public function ‪getByFormatCode(string $formatCode): ‪Mode
108  {
109  foreach ($this->registeredModes as $mode) {
110  if ($mode->getFormatCode() === $formatCode) {
111  return $mode;
112  }
113  }
114 
115  throw new ‪InvalidModeException('Tried to get unregistered t3editor mode by format code "' . $formatCode . '"', 1499710203);
116  }
117 
123  public function ‪getByFileExtension(string $fileExtension): ‪Mode
124  {
125  foreach ($this->registeredModes as $mode) {
126  if (in_array($fileExtension, $mode->getBoundFileExtensions(), true)) {
127  return $mode;
128  }
129  }
130 
131  throw new ‪InvalidModeException('Cannot find a registered mode for requested file extension "' . $fileExtension . '"', 1500306488);
132  }
133 
137  public function ‪getDefaultMode(): ‪Mode
138  {
139  return ‪$this->defaultMode;
140  }
141 }
‪TYPO3\CMS\T3editor\Registry\ModeRegistry\getByFormatCode
‪Mode getByFormatCode(string $formatCode)
Definition: ModeRegistry.php:105
‪TYPO3\CMS\T3editor\Registry\ModeRegistry\getByFileExtension
‪Mode getByFileExtension(string $fileExtension)
Definition: ModeRegistry.php:121
‪TYPO3\CMS\T3editor\Registry\ModeRegistry\$registeredModes
‪Mode[] $registeredModes
Definition: ModeRegistry.php:31
‪TYPO3\CMS\T3editor\Registry\ModeRegistry\unregister
‪self unregister(string $identifier)
Definition: ModeRegistry.php:68
‪TYPO3\CMS\T3editor\Registry\ModeRegistry\getByIdentifier
‪Mode getByIdentifier(string $identifier)
Definition: ModeRegistry.php:91
‪TYPO3\CMS\T3editor\Registry\ModeRegistry\isRegistered
‪bool isRegistered(string $identifier)
Definition: ModeRegistry.php:81
‪TYPO3\CMS\T3editor\Mode
Definition: Mode.php:23
‪TYPO3\CMS\T3editor\Registry\ModeRegistry\getDefaultMode
‪Mode getDefaultMode()
Definition: ModeRegistry.php:135
‪TYPO3\CMS\T3editor\Exception\InvalidModeException
Definition: InvalidModeException.php:25
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:22
‪TYPO3\CMS\T3editor\Registry
Definition: AddonRegistry.php:3
‪TYPO3\CMS\T3editor\Registry\ModeRegistry
Definition: ModeRegistry.php:28
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\T3editor\Registry\ModeRegistry\getInstance
‪static self getInstance()
Definition: ModeRegistry.php:41
‪TYPO3\CMS\T3editor\Registry\ModeRegistry\$defaultMode
‪Mode $defaultMode
Definition: ModeRegistry.php:35