2 declare(strict_types
= 1);
4 namespace TYPO3\CMS\Core\MetaTag
;
7 * This file is part of the TYPO3 CMS project.
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.
13 * For the full copyright and license information, please read the
14 * LICENSE.txt file that was distributed with this source code.
16 * The TYPO3 project - inspiring people to share!
19 use TYPO3\CMS\Core\Service\DependencyOrderingService
;
20 use TYPO3\CMS\Core\SingletonInterface
;
21 use TYPO3\CMS\Core\Utility\GeneralUtility
;
24 * Holds all available meta tag managers
26 class MetaTagManagerRegistry
implements SingletonInterface
28 protected $registry = [];
29 private $instances = [];
32 public function __construct()
34 $this->registry
['generic'] = [
35 'module' => GenericMetaTagManager
::class
40 * Add a MetaTagManager to the registry
43 * @param string $className
44 * @param array $before
47 public function registerManager(string $name, string $className, array $before = ['generic'], array $after = [])
49 if (!count($before)) {
50 $before[] = 'generic';
53 $this->registry
[$name] = [
54 'module' => $className,
58 $this->managers
= null;
62 * Get the MetaTagManager for a specific property
64 * @param string $property
65 * @return MetaTagManagerInterface
67 public function getManagerForProperty(string $property): MetaTagManagerInterface
69 $property = strtolower($property);
70 foreach ($this->getAllManagers() as $manager) {
71 if ($manager->canHandleProperty($property)) {
76 // Just a fallback because the GenericMetaTagManager is also registered in the list of MetaTagManagers
77 return GeneralUtility
::makeInstance(GenericMetaTagManager
::class);
81 * Get an array of all registered MetaTagManagers
83 * @return MetaTagManagerInterface[]
85 public function getAllManagers(): array
87 if ($this->managers
!== null) {
88 return $this->managers
;
91 $orderedManagers = GeneralUtility
::makeInstance(DependencyOrderingService
::class)->orderByDependencies(
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];
104 return $this->managers
;
108 * Remove all registered MetaTagManagers
110 public function removeAllManagers()
112 $this->registry
= [];
113 $this->managers
= null;