TYPO3 CMS  TYPO3_8-7
TextExtractorRegistry.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 
20 
25 {
31  protected $textExtractorClasses = [];
32 
38  protected $instances = [];
39 
45  public static function getInstance()
46  {
47  return GeneralUtility::makeInstance(__CLASS__);
48  }
49 
56  public function registerTextExtractor($className)
57  {
58  if (!class_exists($className)) {
59  throw new \InvalidArgumentException('The class "' . $className . '" you are trying to register is not available', 1422906893);
60  }
61 
62  if (!in_array(TextExtractorInterface::class, class_implements($className), true)) {
63  throw new \InvalidArgumentException($className . ' must implement interface' . TextExtractorInterface::class, 1422771427);
64  }
65 
66  $this->textExtractorClasses[] = $className;
67  }
68 
74  public function getTextExtractorInstances()
75  {
76  if (empty($this->instances) && !empty($this->textExtractorClasses)) {
77  foreach ($this->textExtractorClasses as $className) {
78  $object = $this->createTextExtractorInstance($className);
79  $this->instances[] = $object;
80  }
81  }
82 
83  return $this->instances;
84  }
85 
92  protected function createTextExtractorInstance($className)
93  {
94  return GeneralUtility::makeInstance($className);
95  }
96 
104  public function getTextExtractor(FileInterface $file)
105  {
106  foreach ($this->getTextExtractorInstances() as $textExtractor) {
107  if ($textExtractor->canExtractText($file)) {
108  return $textExtractor;
109  }
110  }
111 
112  return null;
113  }
114 }
static makeInstance($className,... $constructorArguments)