‪TYPO3CMS  ‪main
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 function ‪registerExtractionService($className)
46  {
47  if (!class_exists($className)) {
48  throw new \InvalidArgumentException('The class "' . $className . '" you are registering is not available', 1422705270);
49  }
50  if (!in_array(ExtractorInterface::class, class_implements($className) ?: [])) {
51  throw new \InvalidArgumentException('The extractor needs to implement the ExtractorInterface', 1422705271);
52  }
53  $this->extractors[] = $className;
54  }
55 
61  public function ‪getExtractors()
62  {
63  if ($this->instances === null) {
64  $this->instances = [];
65  foreach ($this->extractors as $className) {
66  $object = $this->‪createExtractorInstance($className);
67  $this->instances[] = $object;
68  }
69 
70  if (count($this->instances) > 1) {
71  usort($this->instances, [$this, 'compareExtractorPriority']);
72  }
73  }
74  return ‪$this->instances;
75  }
76 
83  public function ‪getExtractorsWithDriverSupport($driverType)
84  {
85  return array_filter(
86  $this->‪getExtractors(),
87  function (‪ExtractorInterface $extractor) use ($driverType): bool {
88  return empty($extractor->‪getDriverRestrictions())
89  || in_array($driverType, $extractor->‪getDriverRestrictions(), true);
90  }
91  );
92  }
93 
102  protected function ‪compareExtractorPriority(‪ExtractorInterface $extractorA, ‪ExtractorInterface $extractorB)
103  {
104  return $extractorB->‪getExecutionPriority() - $extractorA->‪getExecutionPriority();
105  }
106 
113  protected function ‪createExtractorInstance($className)
114  {
115  return GeneralUtility::makeInstance($className);
116  }
117 }
‪TYPO3\CMS\Core\Resource\Index\ExtractorRegistry\getExtractorsWithDriverSupport
‪ExtractorInterface[] getExtractorsWithDriverSupport($driverType)
Definition: ExtractorRegistry.php:81
‪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\ExtractorInterface\getExecutionPriority
‪int getExecutionPriority()
‪TYPO3\CMS\Core\Resource\Index\ExtractorInterface\getDriverRestrictions
‪array getDriverRestrictions()
‪TYPO3\CMS\Core\Resource\Index\ExtractorRegistry\getExtractors
‪ExtractorInterface[] getExtractors()
Definition: ExtractorRegistry.php:59
‪TYPO3\CMS\Core\Resource\Index\ExtractorRegistry\createExtractorInstance
‪ExtractorInterface createExtractorInstance($className)
Definition: ExtractorRegistry.php:111
‪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:43
‪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\ExtractorRegistry\compareExtractorPriority
‪int compareExtractorPriority(ExtractorInterface $extractorA, ExtractorInterface $extractorB)
Definition: ExtractorRegistry.php:100
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52