‪TYPO3CMS  9.5
ExtractorRegistry.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
19 
24 {
29  protected ‪$extractors = [];
30 
36  protected ‪$instances;
37 
43  public static function ‪getInstance()
44  {
45  return GeneralUtility::makeInstance(self::class);
46  }
47 
54  public function ‪registerExtractionService($className)
55  {
56  if (!class_exists($className)) {
57  throw new \InvalidArgumentException('The class "' . $className . '" you are registering is not available', 1422705270);
58  }
59  if (!in_array(ExtractorInterface::class, class_implements($className))) {
60  throw new \InvalidArgumentException('The extractor needs to implement the ExtractorInterface', 1422705271);
61  }
62  $this->extractors[] = $className;
63  }
64 
70  public function ‪getExtractors()
71  {
72  if ($this->instances === null) {
73  $this->instances = [];
74 
75  ‪$extractors = array_reverse($this->extractors);
76  foreach (‪$extractors as $className) {
78  $object = $this->‪createExtractorInstance($className);
79  $this->instances[] = $object;
80  }
81 
82  if (count($this->instances) > 1) {
83  usort($this->instances, [$this, 'compareExtractorPriority']);
84  }
85  }
86  return ‪$this->instances;
87  }
88 
95  public function ‪getExtractorsWithDriverSupport($driverType)
96  {
97  $allExtractors = $this->‪getExtractors();
98 
99  $filteredExtractors = [];
100  foreach ($allExtractors as $priority => $extractorObject) {
101  if (empty($extractorObject->getDriverRestrictions())) {
102  $filteredExtractors[$priority] = $extractorObject;
103  } elseif (in_array($driverType, $extractorObject->getDriverRestrictions())) {
104  $filteredExtractors[$priority] = $extractorObject;
105  }
106  }
107  return $filteredExtractors;
108  }
109 
120  protected function ‪compareExtractorPriority(‪ExtractorInterface $extractorA, ‪ExtractorInterface $extractorB)
121  {
122  return $extractorB->‪getPriority() - $extractorA->‪getPriority();
123  }
124 
131  protected function ‪createExtractorInstance($className)
132  {
133  return GeneralUtility::makeInstance($className);
134  }
135 }
‪TYPO3\CMS\Core\Resource\Index\ExtractorRegistry\getExtractorsWithDriverSupport
‪ExtractorInterface[] getExtractorsWithDriverSupport($driverType)
Definition: ExtractorRegistry.php:93
‪TYPO3\CMS\Core\Resource\Index\ExtractorInterface
Definition: ExtractorInterface.php:23
‪TYPO3\CMS\Core\Resource\Index\ExtractorRegistry
Definition: ExtractorRegistry.php:24
‪TYPO3\CMS\Core\Resource\Index\ExtractorRegistry\getInstance
‪static ExtractorRegistry getInstance()
Definition: ExtractorRegistry.php:41
‪TYPO3\CMS\Core\Resource\Index\ExtractorRegistry\getExtractors
‪ExtractorInterface[] getExtractors()
Definition: ExtractorRegistry.php:68
‪TYPO3\CMS\Core\Resource\Index\ExtractorRegistry\createExtractorInstance
‪ExtractorInterface createExtractorInstance($className)
Definition: ExtractorRegistry.php:129
‪TYPO3\CMS\Core\Resource\Index\ExtractorRegistry\$instances
‪ExtractorInterface[] $instances
Definition: ExtractorRegistry.php:34
‪TYPO3\CMS\Core\Resource\Index
Definition: ExtractorInterface.php:2
‪TYPO3\CMS\Core\Resource\Index\ExtractorRegistry\registerExtractionService
‪registerExtractionService($className)
Definition: ExtractorRegistry.php:52
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:22
‪TYPO3\CMS\Core\Resource\Index\ExtractorRegistry\$extractors
‪array $extractors
Definition: ExtractorRegistry.php:28
‪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:118
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45