‪TYPO3CMS  9.5
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 }
‪TYPO3\CMS\Core\Resource\TextExtraction\TextExtractorRegistry\$instances
‪TextExtractorInterface[] $instances
Definition: TextExtractorRegistry.php:36
‪TYPO3\CMS\Core\Resource\FileInterface
Definition: FileInterface.php:21
‪TYPO3\CMS\Core\Resource\TextExtraction\TextExtractorInterface
Definition: TextExtractorInterface.php:23
‪TYPO3\CMS\Core\Resource\TextExtraction\TextExtractorRegistry\getTextExtractorInstances
‪TextExtractorInterface[] getTextExtractorInstances()
Definition: TextExtractorRegistry.php:72
‪TYPO3\CMS\Core\Resource\TextExtraction\TextExtractorRegistry
Definition: TextExtractorRegistry.php:25
‪TYPO3\CMS\Core\Resource\TextExtraction\TextExtractorRegistry\registerTextExtractor
‪registerTextExtractor($className)
Definition: TextExtractorRegistry.php:54
‪TYPO3\CMS\Core\Resource\TextExtraction\TextExtractorRegistry\getInstance
‪static TextExtractorRegistry getInstance()
Definition: TextExtractorRegistry.php:43
‪TYPO3\CMS\Core\Resource\TextExtraction\TextExtractorRegistry\$textExtractorClasses
‪array $textExtractorClasses
Definition: TextExtractorRegistry.php:30
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:22
‪TYPO3\CMS\Core\Resource\TextExtraction
Definition: PlainTextExtractor.php:2
‪TYPO3\CMS\Core\Resource\TextExtraction\TextExtractorRegistry\createTextExtractorInstance
‪TextExtractorInterface createTextExtractorInstance($className)
Definition: TextExtractorRegistry.php:90
‪TYPO3\CMS\Core\Resource\TextExtraction\TextExtractorRegistry\getTextExtractor
‪TextExtractorInterface null getTextExtractor(FileInterface $file)
Definition: TextExtractorRegistry.php:102
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45