‪TYPO3CMS  11.5
ExtractorRegistry.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
20 
25 {
30  protected ‪$extractors = [];
31 
37  protected ‪$instances;
38 
45  public static function ‪getInstance()
46  {
47  trigger_error(__CLASS__ . '::getInstance() will be removed in TYPO3 v12.0. Use Dependency Injection or GeneralUtility::makeInstance() if DI is not possible.', E_USER_DEPRECATED);
48  return GeneralUtility::makeInstance(self::class);
49  }
50 
57  public function ‪registerExtractionService($className)
58  {
59  if (!class_exists($className)) {
60  throw new \InvalidArgumentException('The class "' . $className . '" you are registering is not available', 1422705270);
61  }
62  if (!in_array(ExtractorInterface::class, class_implements($className) ?: [])) {
63  throw new \InvalidArgumentException('The extractor needs to implement the ExtractorInterface', 1422705271);
64  }
65  $this->extractors[] = $className;
66  }
67 
73  public function ‪getExtractors()
74  {
75  if ($this->instances === null) {
76  $this->instances = [];
77 
78  ‪$extractors = array_reverse($this->extractors);
79  foreach (‪$extractors as $className) {
80  $object = $this->‪createExtractorInstance($className);
81  $this->instances[] = $object;
82  }
83 
84  if (count($this->instances) > 1) {
85  usort($this->instances, [$this, 'compareExtractorPriority']);
86  }
87  }
88  return ‪$this->instances;
89  }
90 
97  public function ‪getExtractorsWithDriverSupport($driverType)
98  {
99  $allExtractors = $this->‪getExtractors();
100 
101  $filteredExtractors = [];
102  foreach ($allExtractors as $priority => $extractorObject) {
103  if (empty($extractorObject->getDriverRestrictions()) ||
104  in_array($driverType, $extractorObject->getDriverRestrictions(), true)) {
105  $filteredExtractors[$extractorObject->getPriority()][] = $extractorObject;
106  }
107  }
108  return $filteredExtractors;
109  }
110 
121  protected function ‪compareExtractorPriority(‪ExtractorInterface $extractorA, ‪ExtractorInterface $extractorB)
122  {
123  return $extractorB->‪getPriority() - $extractorA->‪getPriority();
124  }
125 
132  protected function ‪createExtractorInstance($className)
133  {
134  return GeneralUtility::makeInstance($className);
135  }
136 }
‪TYPO3\CMS\Core\Resource\Index\ExtractorRegistry\getExtractorsWithDriverSupport
‪ExtractorInterface[] getExtractorsWithDriverSupport($driverType)
Definition: ExtractorRegistry.php:95
‪TYPO3\CMS\Core\Resource\Index\ExtractorInterface
Definition: ExtractorInterface.php:25
‪TYPO3\CMS\Core\Resource\Index\ExtractorRegistry
Definition: ExtractorRegistry.php:25
‪TYPO3\CMS\Core\Resource\Index\ExtractorRegistry\getInstance
‪static ExtractorRegistry getInstance()
Definition: ExtractorRegistry.php:43
‪TYPO3\CMS\Core\Resource\Index\ExtractorRegistry\getExtractors
‪ExtractorInterface[] getExtractors()
Definition: ExtractorRegistry.php:71
‪TYPO3\CMS\Core\Resource\Index\ExtractorRegistry\createExtractorInstance
‪ExtractorInterface createExtractorInstance($className)
Definition: ExtractorRegistry.php:130
‪TYPO3\CMS\Core\Resource\Index\ExtractorRegistry\$instances
‪ExtractorInterface[] $instances
Definition: ExtractorRegistry.php:35
‪TYPO3\CMS\Core\Resource\Index
Definition: ExtractorInterface.php:16
‪TYPO3\CMS\Core\Resource\Index\ExtractorRegistry\registerExtractionService
‪registerExtractionService($className)
Definition: ExtractorRegistry.php:55
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:22
‪TYPO3\CMS\Core\Resource\Index\ExtractorRegistry\$extractors
‪array $extractors
Definition: ExtractorRegistry.php:29
‪TYPO3\CMS\Core\Resource\Index\ExtractorInterface\getPriority
‪int getPriority()
‪TYPO3\CMS\Core\Resource\Index\ExtractorRegistry\compareExtractorPriority
‪int compareExtractorPriority(ExtractorInterface $extractorA, ExtractorInterface $extractorB)
Definition: ExtractorRegistry.php:119
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50