‪TYPO3CMS  10.4
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 
44  public static function ‪getInstance()
45  {
46  return GeneralUtility::makeInstance(self::class);
47  }
48 
55  public function ‪registerExtractionService($className)
56  {
57  if (!class_exists($className)) {
58  throw new \InvalidArgumentException('The class "' . $className . '" you are registering is not available', 1422705270);
59  }
60  if (!in_array(ExtractorInterface::class, class_implements($className))) {
61  throw new \InvalidArgumentException('The extractor needs to implement the ExtractorInterface', 1422705271);
62  }
63  $this->extractors[] = $className;
64  }
65 
71  public function ‪getExtractors()
72  {
73  if ($this->instances === null) {
74  $this->instances = [];
75 
76  ‪$extractors = array_reverse($this->extractors);
77  foreach (‪$extractors as $className) {
79  $object = $this->‪createExtractorInstance($className);
80  $this->instances[] = $object;
81  }
82 
83  if (count($this->instances) > 1) {
84  usort($this->instances, [$this, 'compareExtractorPriority']);
85  }
86  }
87  return ‪$this->instances;
88  }
89 
96  public function ‪getExtractorsWithDriverSupport($driverType)
97  {
98  $allExtractors = $this->‪getExtractors();
99 
100  $filteredExtractors = [];
101  foreach ($allExtractors as $priority => $extractorObject) {
102  if (empty($extractorObject->getDriverRestrictions()) ||
103  in_array($driverType, $extractorObject->getDriverRestrictions(), true)) {
104  $filteredExtractors[$extractorObject->getPriority()][] = $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:94
‪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:42
‪TYPO3\CMS\Core\Resource\Index\ExtractorRegistry\getExtractors
‪ExtractorInterface[] getExtractors()
Definition: ExtractorRegistry.php:69
‪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:35
‪TYPO3\CMS\Core\Resource\Index
Definition: ExtractorInterface.php:16
‪TYPO3\CMS\Core\Resource\Index\ExtractorRegistry\registerExtractionService
‪registerExtractionService($className)
Definition: ExtractorRegistry.php:53
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:23
‪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:118
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46