‪TYPO3CMS  10.4
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 
46  public static function ‪getInstance()
47  {
48  return GeneralUtility::makeInstance(__CLASS__);
49  }
50 
57  public function ‪registerTextExtractor($className)
58  {
59  if (!class_exists($className)) {
60  throw new \InvalidArgumentException('The class "' . $className . '" you are trying to register is not available', 1422906893);
61  }
62 
63  if (!in_array(TextExtractorInterface::class, class_implements($className), true)) {
64  throw new \InvalidArgumentException($className . ' must implement interface' . TextExtractorInterface::class, 1422771427);
65  }
66 
67  $this->textExtractorClasses[] = $className;
68  }
69 
75  public function ‪getTextExtractorInstances()
76  {
77  if (empty($this->instances) && !empty($this->textExtractorClasses)) {
78  foreach ($this->textExtractorClasses as $className) {
79  $object = $this->‪createTextExtractorInstance($className);
80  $this->instances[] = $object;
81  }
82  }
83 
84  return ‪$this->instances;
85  }
86 
93  protected function ‪createTextExtractorInstance($className)
94  {
95  return GeneralUtility::makeInstance($className);
96  }
97 
105  public function ‪getTextExtractor(‪FileInterface $file)
106  {
107  foreach ($this->‪getTextExtractorInstances() as $textExtractor) {
108  if ($textExtractor->canExtractText($file)) {
109  return $textExtractor;
110  }
111  }
112 
113  return null;
114  }
115 }
‪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:73
‪TYPO3\CMS\Core\Resource\TextExtraction\TextExtractorRegistry
Definition: TextExtractorRegistry.php:26
‪TYPO3\CMS\Core\Resource\TextExtraction\TextExtractorRegistry\registerTextExtractor
‪registerTextExtractor($className)
Definition: TextExtractorRegistry.php:55
‪TYPO3\CMS\Core\Resource\TextExtraction\TextExtractorRegistry\getInstance
‪static TextExtractorRegistry getInstance()
Definition: TextExtractorRegistry.php:44
‪TYPO3\CMS\Core\Resource\TextExtraction\TextExtractorRegistry\$textExtractorClasses
‪array $textExtractorClasses
Definition: TextExtractorRegistry.php:31
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:23
‪TYPO3\CMS\Core\Resource\TextExtraction
Definition: PlainTextExtractor.php:16
‪TYPO3\CMS\Core\Resource\TextExtraction\TextExtractorRegistry\createTextExtractorInstance
‪TextExtractorInterface createTextExtractorInstance($className)
Definition: TextExtractorRegistry.php:91
‪TYPO3\CMS\Core\Resource\TextExtraction\TextExtractorRegistry\getTextExtractor
‪TextExtractorInterface null getTextExtractor(FileInterface $file)
Definition: TextExtractorRegistry.php:103
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46