TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
ExtractorRegistry.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Core\Resource\Index;
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 
25 {
30  protected $extractors = [];
31 
37  protected $instances = null;
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  } elseif (!in_array(ExtractorInterface::class, class_implements($className))) {
60  throw new \InvalidArgumentException('The extractor needs to implement the ExtractorInterface', 1422705271);
61  } else {
62  $this->extractors[] = $className;
63  }
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  $filteredExtractors[$priority] = $extractorObject;
104  } elseif (in_array($driverType, $extractorObject->getDriverRestrictions())) {
105  $filteredExtractors[$priority] = $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 }
compareExtractorPriority(ExtractorInterface $extractorA, ExtractorInterface $extractorB)
static makeInstance($className,...$constructorArguments)