‪TYPO3CMS  10.4
MetaTagManagerRegistry.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 
23 
28 {
32  protected ‪$registry = [];
33 
37  private ‪$instances = [];
38 
42  private ‪$managers;
43 
44  public function ‪__construct()
45  {
46  $this->registry['generic'] = [
47  'module' => GenericMetaTagManager::class
48  ];
49  }
50 
59  public function ‪registerManager(string $name, string $className, array $before = ['generic'], array $after = [])
60  {
61  if (!count($before)) {
62  $before[] = 'generic';
63  }
64 
65  $this->registry[$name] = [
66  'module' => $className,
67  'before' => $before,
68  'after' => $after
69  ];
70  $this->managers = null;
71  }
72 
79  public function ‪getManagerForProperty(string $property): ‪MetaTagManagerInterface
80  {
81  $property = strtolower($property);
82  foreach ($this->‪getAllManagers() as $manager) {
83  if ($manager->canHandleProperty($property)) {
84  return $manager;
85  }
86  }
87 
88  // Just a fallback because the GenericMetaTagManager is also registered in the list of MetaTagManagers
89  return GeneralUtility::makeInstance(GenericMetaTagManager::class);
90  }
91 
97  public function ‪getAllManagers(): array
98  {
99  if ($this->managers !== null) {
100  return ‪$this->managers;
101  }
102 
103  $orderedManagers = GeneralUtility::makeInstance(DependencyOrderingService::class)->orderByDependencies(
104  $this->registry
105  );
106 
107  $this->managers = [];
108  foreach ($orderedManagers as $manager => $managerConfiguration) {
109  $module = $managerConfiguration['module'];
110  if (class_exists($module)) {
111  $this->instances[$module] = $this->instances[$module] ?? GeneralUtility::makeInstance($module);
112  $this->managers[$manager] = $this->instances[$module];
113  }
114  }
115 
116  return ‪$this->managers;
117  }
118 
122  public function ‪removeAllManagers()
123  {
124  $this->registry = [];
125  $this->managers = null;
126  }
127 
132  public function ‪updateState(array $newState): void
133  {
134  foreach ($newState as $var => $value) {
135  $this->{$var} = $value;
136  }
137  }
138 
143  public function ‪getState(): array
144  {
145  $state = [];
146  foreach (get_object_vars($this) as $var => $value) {
147  $state[$var] = $value;
148  }
149  return $state;
150  }
151 }
‪TYPO3\CMS\Core\MetaTag\MetaTagManagerRegistry\getAllManagers
‪MetaTagManagerInterface[] getAllManagers()
Definition: MetaTagManagerRegistry.php:94
‪TYPO3\CMS\Core\MetaTag\MetaTagManagerRegistry\removeAllManagers
‪removeAllManagers()
Definition: MetaTagManagerRegistry.php:119
‪TYPO3\CMS\Core\MetaTag\MetaTagManagerRegistry\getManagerForProperty
‪MetaTagManagerInterface getManagerForProperty(string $property)
Definition: MetaTagManagerRegistry.php:76
‪TYPO3\CMS\Core\MetaTag\MetaTagManagerRegistry
Definition: MetaTagManagerRegistry.php:28
‪TYPO3\CMS\Core\MetaTag\MetaTagManagerInterface
Definition: MetaTagManagerInterface.php:21
‪TYPO3\CMS\Core\MetaTag\MetaTagManagerRegistry\__construct
‪__construct()
Definition: MetaTagManagerRegistry.php:41
‪TYPO3\CMS\Core\MetaTag\MetaTagManagerRegistry\registerManager
‪registerManager(string $name, string $className, array $before=['generic'], array $after=[])
Definition: MetaTagManagerRegistry.php:56
‪TYPO3\CMS\Core\MetaTag
Definition: AbstractMetaTagManager.php:18
‪TYPO3\CMS\Core\Service\DependencyOrderingService
Definition: DependencyOrderingService.php:32
‪TYPO3\CMS\Core\MetaTag\MetaTagManagerRegistry\getState
‪array getState()
Definition: MetaTagManagerRegistry.php:140
‪TYPO3\CMS\Core\MetaTag\MetaTagManagerRegistry\$managers
‪MetaTagManagerInterface[] null $managers
Definition: MetaTagManagerRegistry.php:39
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:23
‪TYPO3\CMS\Core\MetaTag\MetaTagManagerRegistry\$registry
‪mixed[] $registry
Definition: MetaTagManagerRegistry.php:31
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\MetaTag\MetaTagManagerRegistry\$instances
‪mixed[] $instances
Definition: MetaTagManagerRegistry.php:35
‪TYPO3\CMS\Core\MetaTag\MetaTagManagerRegistry\updateState
‪updateState(array $newState)
Definition: MetaTagManagerRegistry.php:129