TYPO3 CMS  TYPO3_6-2
ExtractorRegistry.php
Go to the documentation of this file.
1 <?php
3 
19 
25 
30  protected $extractors = array();
31 
37  protected $instances = NULL;
38 
44  public static function getInstance() {
45  return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\Index\\ExtractorRegistry');
46  }
47 
54  public function registerExtractionService($className) {
55  if (!class_exists($className)) {
56  throw new \InvalidArgumentException('The class "' . $className . '" you are registering is not available', 1422705270);
57  } elseif (!in_array('TYPO3\\CMS\\Core\\Resource\\Index\\ExtractorInterface', class_implements($className))) {
58  throw new \InvalidArgumentException('The extractor needs to implement the ExtractorInterface', 1422705271);
59  } else {
60  $this->extractors[] = $className;
61  }
62  }
63 
69  public function getExtractors() {
70  if ($this->instances === NULL) {
71  $this->instances = array();
72 
73  $extractors = array_reverse($this->extractors);
74  foreach ($extractors as $className) {
76  $object = $this->createExtractorInstance($className);
77  $this->instances[] = $object;
78  }
79 
80  if (count($this->instances) > 1) {
81  usort($this->instances, array($this, 'compareExtractorPriority'));
82  }
83  }
84  return $this->instances;
85  }
86 
93  public function getExtractorsWithDriverSupport($driverType) {
94  $allExtractors = $this->getExtractors();
95 
96  $filteredExtractors = array();
97  foreach ($allExtractors as $priority => $extractorObject) {
98  if (count($extractorObject->getDriverRestrictions()) == 0) {
99  $filteredExtractors[$priority] = $extractorObject;
100  } elseif (in_array($driverType, $extractorObject->getDriverRestrictions())) {
101  $filteredExtractors[$priority] = $extractorObject;
102  }
103  }
104  return $filteredExtractors;
105  }
106 
117  protected function compareExtractorPriority(ExtractorInterface $extractorA, ExtractorInterface $extractorB) {
118  return $extractorB->getPriority() - $extractorA->getPriority();
119  }
120 
127  protected function createExtractorInstance($className) {
128  return GeneralUtility::makeInstance($className);
129  }
130 
131 
132 }
compareExtractorPriority(ExtractorInterface $extractorA, ExtractorInterface $extractorB)