‪TYPO3CMS  11.5
TextExtractorRegistry.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
21 
26 {
32  protected ‪$textExtractorClasses = [];
33 
39  protected ‪$instances = [];
40 
47  public static function ‪getInstance()
48  {
49  trigger_error(__CLASS__ . '::getInstance() will be removed in TYPO3 v12.0. Use Dependency Injection or GeneralUtility::makeInstance() if DI is not possible.', E_USER_DEPRECATED);
50  return GeneralUtility::makeInstance(__CLASS__);
51  }
52 
59  public function ‪registerTextExtractor($className)
60  {
61  if (!class_exists($className)) {
62  throw new \InvalidArgumentException('The class "' . $className . '" you are trying to register is not available', 1422906893);
63  }
64 
65  if (!in_array(TextExtractorInterface::class, class_implements($className) ?: [], true)) {
66  throw new \InvalidArgumentException($className . ' must implement interface' . TextExtractorInterface::class, 1422771427);
67  }
68 
69  $this->textExtractorClasses[] = $className;
70  }
71 
77  public function ‪getTextExtractorInstances()
78  {
79  if (empty($this->instances) && !empty($this->textExtractorClasses)) {
80  foreach ($this->textExtractorClasses as $className) {
81  $object = $this->‪createTextExtractorInstance($className);
82  $this->instances[] = $object;
83  }
84  }
85 
86  return ‪$this->instances;
87  }
88 
95  protected function ‪createTextExtractorInstance($className)
96  {
97  return GeneralUtility::makeInstance($className);
98  }
99 
107  public function ‪getTextExtractor(‪FileInterface $file)
108  {
109  foreach ($this->‪getTextExtractorInstances() as $textExtractor) {
110  if ($textExtractor->canExtractText($file)) {
111  return $textExtractor;
112  }
113  }
114 
115  return null;
116  }
117 }
‪TYPO3\CMS\Core\Resource\TextExtraction\TextExtractorRegistry\$instances
‪TextExtractorInterface[] $instances
Definition: TextExtractorRegistry.php:37
‪TYPO3\CMS\Core\Resource\FileInterface
Definition: FileInterface.php:22
‪TYPO3\CMS\Core\Resource\TextExtraction\TextExtractorInterface
Definition: TextExtractorInterface.php:24
‪TYPO3\CMS\Core\Resource\TextExtraction\TextExtractorRegistry\getTextExtractorInstances
‪TextExtractorInterface[] getTextExtractorInstances()
Definition: TextExtractorRegistry.php:75
‪TYPO3\CMS\Core\Resource\TextExtraction\TextExtractorRegistry
Definition: TextExtractorRegistry.php:26
‪TYPO3\CMS\Core\Resource\TextExtraction\TextExtractorRegistry\registerTextExtractor
‪registerTextExtractor($className)
Definition: TextExtractorRegistry.php:57
‪TYPO3\CMS\Core\Resource\TextExtraction\TextExtractorRegistry\getInstance
‪static TextExtractorRegistry getInstance()
Definition: TextExtractorRegistry.php:45
‪TYPO3\CMS\Core\Resource\TextExtraction\TextExtractorRegistry\$textExtractorClasses
‪array $textExtractorClasses
Definition: TextExtractorRegistry.php:31
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:22
‪TYPO3\CMS\Core\Resource\TextExtraction
Definition: PlainTextExtractor.php:16
‪TYPO3\CMS\Core\Resource\TextExtraction\TextExtractorRegistry\createTextExtractorInstance
‪TextExtractorInterface createTextExtractorInstance($className)
Definition: TextExtractorRegistry.php:93
‪TYPO3\CMS\Core\Resource\TextExtraction\TextExtractorRegistry\getTextExtractor
‪TextExtractorInterface null getTextExtractor(FileInterface $file)
Definition: TextExtractorRegistry.php:105
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50