‪TYPO3CMS  9.5
MetaTagManagerRegistry.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 
22 
27 {
28  protected ‪$registry = [];
29  private ‪$instances = [];
30  private ‪$managers;
31 
32  public function ‪__construct()
33  {
34  $this->registry['generic'] = [
35  'module' => GenericMetaTagManager::class
36  ];
37  }
38 
47  public function ‪registerManager(string $name, string $className, array $before = ['generic'], array $after = [])
48  {
49  if (!count($before)) {
50  $before[] = 'generic';
51  }
52 
53  $this->registry[$name] = [
54  'module' => $className,
55  'before' => $before,
56  'after' => $after
57  ];
58  $this->managers = null;
59  }
60 
67  public function ‪getManagerForProperty(string $property): ‪MetaTagManagerInterface
68  {
69  $property = strtolower($property);
70  foreach ($this->‪getAllManagers() as $manager) {
71  if ($manager->canHandleProperty($property)) {
72  return $manager;
73  }
74  }
75 
76  // Just a fallback because the GenericMetaTagManager is also registered in the list of MetaTagManagers
77  return GeneralUtility::makeInstance(GenericMetaTagManager::class);
78  }
79 
85  public function ‪getAllManagers(): array
86  {
87  if ($this->managers !== null) {
88  return ‪$this->managers;
89  }
90 
91  $orderedManagers = GeneralUtility::makeInstance(DependencyOrderingService::class)->orderByDependencies(
92  $this->registry
93  );
94 
95  $this->managers = [];
96  foreach ($orderedManagers as $manager => $managerConfiguration) {
97  $module = $managerConfiguration['module'];
98  if (class_exists($module)) {
99  $this->instances[$module] = $this->instances[$module] ?? GeneralUtility::makeInstance($module);
100  $this->managers[$manager] = $this->instances[$module];
101  }
102  }
103 
104  return ‪$this->managers;
105  }
106 
110  public function ‪removeAllManagers()
111  {
112  $this->registry = [];
113  $this->managers = null;
114  }
115 }
‪TYPO3\CMS\Core\MetaTag\MetaTagManagerRegistry\$registry
‪$registry
Definition: MetaTagManagerRegistry.php:28
‪TYPO3\CMS\Core\MetaTag\MetaTagManagerRegistry\getAllManagers
‪MetaTagManagerInterface[] getAllManagers()
Definition: MetaTagManagerRegistry.php:85
‪TYPO3\CMS\Core\MetaTag\MetaTagManagerRegistry\removeAllManagers
‪removeAllManagers()
Definition: MetaTagManagerRegistry.php:110
‪TYPO3\CMS\Core\MetaTag\MetaTagManagerRegistry\getManagerForProperty
‪MetaTagManagerInterface getManagerForProperty(string $property)
Definition: MetaTagManagerRegistry.php:67
‪TYPO3\CMS\Core\MetaTag\MetaTagManagerRegistry
Definition: MetaTagManagerRegistry.php:27
‪TYPO3\CMS\Core\MetaTag\MetaTagManagerInterface
Definition: MetaTagManagerInterface.php:20
‪TYPO3\CMS\Core\MetaTag\MetaTagManagerRegistry\__construct
‪__construct()
Definition: MetaTagManagerRegistry.php:32
‪TYPO3\CMS\Core\MetaTag\MetaTagManagerRegistry\registerManager
‪registerManager(string $name, string $className, array $before=['generic'], array $after=[])
Definition: MetaTagManagerRegistry.php:47
‪TYPO3\CMS\Core\MetaTag
Definition: AbstractMetaTagManager.php:4
‪TYPO3\CMS\Core\MetaTag\MetaTagManagerRegistry\$instances
‪$instances
Definition: MetaTagManagerRegistry.php:29
‪TYPO3\CMS\Core\Service\DependencyOrderingService
Definition: DependencyOrderingService.php:31
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:22
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\MetaTag\MetaTagManagerRegistry\$managers
‪$managers
Definition: MetaTagManagerRegistry.php:30