TYPO3 CMS  TYPO3_8-7
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 = null;
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 }
compareExtractorPriority(ExtractorInterface $extractorA, ExtractorInterface $extractorB)
static makeInstance($className,... $constructorArguments)