‪TYPO3CMS  ‪main
LinktypeRegistry.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 
27 {
28  private array ‪$linktypes = [];
29 
30  public function ‪__construct(iterable ‪$linktypes)
31  {
32  foreach (‪$linktypes as $linktype) {
33  if (!($linktype instanceof ‪LinktypeInterface)) {
34  continue;
35  }
36 
37  ‪$identifier = $linktype->getIdentifier();
38  if (‪$identifier === '') {
39  throw new \InvalidArgumentException('Identifier for linktype ' . get_class($linktype) . ' is empty.', 1644932383);
40  }
41  if (isset($this->linktypes[‪$identifier])) {
42  throw new \InvalidArgumentException('Linktype identifier ' . ‪$identifier . ' is already registered.', 1644932384);
43  }
44 
45  $this->linktypes[‪$identifier] = $linktype;
46  }
47  }
48 
50  {
51  return $this->linktypes[‪$identifier] ?? null;
52  }
53 
59  public function ‪getLinktypes(): array
60  {
61  return ‪$this->linktypes;
62  }
63 
69  public function ‪getIdentifiers(): array
70  {
71  return array_keys($this->linktypes);
72  }
73 }
‪TYPO3\CMS\Linkvalidator\Linktype\LinktypeInterface
Definition: LinktypeInterface.php:26
‪TYPO3\CMS\Linkvalidator\Linktype
Definition: AbstractLinktype.php:18
‪TYPO3\CMS\Linkvalidator\Linktype\LinktypeRegistry\__construct
‪__construct(iterable $linktypes)
Definition: LinktypeRegistry.php:30
‪TYPO3\CMS\Linkvalidator\Linktype\LinktypeRegistry\getLinktype
‪getLinktype(string $identifier)
Definition: LinktypeRegistry.php:49
‪TYPO3\CMS\Linkvalidator\Linktype\LinktypeRegistry\getLinktypes
‪LinktypeInterface[] getLinktypes()
Definition: LinktypeRegistry.php:59
‪TYPO3\CMS\Linkvalidator\Linktype\LinktypeRegistry\getIdentifiers
‪string[] getIdentifiers()
Definition: LinktypeRegistry.php:69
‪TYPO3\CMS\Linkvalidator\Linktype\LinktypeRegistry\$linktypes
‪array $linktypes
Definition: LinktypeRegistry.php:28
‪TYPO3\CMS\Linkvalidator\Linktype\LinktypeRegistry
Definition: LinktypeRegistry.php:27
‪TYPO3\CMS\Webhooks\Message\$identifier
‪identifier readonly string $identifier
Definition: FileAddedMessage.php:37