TYPO3  7.6
TextExtractorRegistry.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Core\Resource\TextExtraction;
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 
20 
26 {
32  protected $textExtractorClasses = array();
33 
39  protected $instances = array();
40 
41 
47  public static function getInstance()
48  {
49  return GeneralUtility::makeInstance(__CLASS__);
50  }
51 
58  public function registerTextExtractor($className)
59  {
60  if (!class_exists($className)) {
61  throw new \InvalidArgumentException('The class "' . $className . '" you are trying to register is not available', 1422906893);
62  }
63 
64  if (!in_array(TextExtractorInterface::class, class_implements($className), true)) {
65  throw new \InvalidArgumentException($className . ' must implement interface' . TextExtractorInterface::class, 1422771427);
66  }
67 
68  $this->textExtractorClasses[] = $className;
69  }
70 
76  public function getTextExtractorInstances()
77  {
78  if (empty($this->instances) && !empty($this->textExtractorClasses)) {
79  foreach ($this->textExtractorClasses as $className) {
80  $object = $this->createTextExtractorInstance($className);
81  $this->instances[] = $object;
82  }
83  }
84 
85  return $this->instances;
86  }
87 
94  protected function createTextExtractorInstance($className)
95  {
96  return GeneralUtility::makeInstance($className);
97  }
98 
106  public function getTextExtractor(FileInterface $file)
107  {
108  foreach ($this->getTextExtractorInstances() as $textExtractor) {
109  if ($textExtractor->canExtractText($file)) {
110  return $textExtractor;
111  }
112  }
113 
114  return null;
115  }
116 }