‪TYPO3CMS  ‪main
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 
23 {
29  protected ‪$textExtractorClasses = [];
30 
36  protected ‪$instances = [];
37 
44  public function ‪registerTextExtractor($className)
45  {
46  if (!class_exists($className)) {
47  throw new \InvalidArgumentException('The class "' . $className . '" you are trying to register is not available', 1422906893);
48  }
49 
50  if (!in_array(TextExtractorInterface::class, class_implements($className) ?: [], true)) {
51  throw new \InvalidArgumentException($className . ' must implement interface' . TextExtractorInterface::class, 1422771427);
52  }
53 
54  $this->textExtractorClasses[] = $className;
55  }
56 
62  public function ‪getTextExtractorInstances()
63  {
64  if (empty($this->instances) && !empty($this->textExtractorClasses)) {
65  foreach ($this->textExtractorClasses as $className) {
66  $object = $this->‪createTextExtractorInstance($className);
67  $this->instances[] = $object;
68  }
69  }
70 
71  return ‪$this->instances;
72  }
73 
80  protected function ‪createTextExtractorInstance($className)
81  {
82  return GeneralUtility::makeInstance($className);
83  }
84 
91  public function ‪getTextExtractor(‪FileInterface $file)
92  {
93  foreach ($this->‪getTextExtractorInstances() as $textExtractor) {
94  if ($textExtractor->canExtractText($file)) {
95  return $textExtractor;
96  }
97  }
98 
99  return null;
100  }
101 }
‪TYPO3\CMS\Core\Resource\TextExtraction\TextExtractorRegistry\$instances
‪TextExtractorInterface[] $instances
Definition: TextExtractorRegistry.php:34
‪TYPO3\CMS\Core\Resource\FileInterface
Definition: FileInterface.php:26
‪TYPO3\CMS\Core\Resource\TextExtraction\TextExtractorInterface
Definition: TextExtractorInterface.php:24
‪TYPO3\CMS\Core\Resource\TextExtraction\TextExtractorRegistry\getTextExtractorInstances
‪TextExtractorInterface[] getTextExtractorInstances()
Definition: TextExtractorRegistry.php:60
‪TYPO3\CMS\Core\Resource\TextExtraction\TextExtractorRegistry
Definition: TextExtractorRegistry.php:23
‪TYPO3\CMS\Core\Resource\TextExtraction\TextExtractorRegistry\registerTextExtractor
‪registerTextExtractor($className)
Definition: TextExtractorRegistry.php:42
‪TYPO3\CMS\Core\Resource\TextExtraction\TextExtractorRegistry\$textExtractorClasses
‪array $textExtractorClasses
Definition: TextExtractorRegistry.php:28
‪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:78
‪TYPO3\CMS\Core\Resource\TextExtraction\TextExtractorRegistry\getTextExtractor
‪TextExtractorInterface null getTextExtractor(FileInterface $file)
Definition: TextExtractorRegistry.php:89
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52