‪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 
26 {
32  protected ‪$textExtractorClasses = [];
33 
39  protected ‪$instances = [];
40 
47  public function ‪registerTextExtractor($className)
48  {
49  if (!class_exists($className)) {
50  throw new \InvalidArgumentException('The class "' . $className . '" you are trying to register is not available', 1422906893);
51  }
52 
53  if (!in_array(TextExtractorInterface::class, class_implements($className) ?: [], true)) {
54  throw new \InvalidArgumentException($className . ' must implement interface' . TextExtractorInterface::class, 1422771427);
55  }
56 
57  $this->textExtractorClasses[] = $className;
58  }
59 
65  public function ‪getTextExtractorInstances()
66  {
67  if (empty($this->instances) && !empty($this->textExtractorClasses)) {
68  foreach ($this->textExtractorClasses as $className) {
69  $object = $this->‪createTextExtractorInstance($className);
70  $this->instances[] = $object;
71  }
72  }
73 
74  return ‪$this->instances;
75  }
76 
83  protected function ‪createTextExtractorInstance($className)
84  {
85  return GeneralUtility::makeInstance($className);
86  }
87 
94  public function ‪getTextExtractor(‪FileInterface $file)
95  {
96  foreach ($this->‪getTextExtractorInstances() as $textExtractor) {
97  if ($textExtractor->canExtractText($file)) {
98  return $textExtractor;
99  }
100  }
101 
102  return null;
103  }
104 }
‪TYPO3\CMS\Core\Resource\TextExtraction\TextExtractorRegistry\$instances
‪TextExtractorInterface[] $instances
Definition: TextExtractorRegistry.php:37
‪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:63
‪TYPO3\CMS\Core\Resource\TextExtraction\TextExtractorRegistry
Definition: TextExtractorRegistry.php:26
‪TYPO3\CMS\Core\Resource\TextExtraction\TextExtractorRegistry\registerTextExtractor
‪registerTextExtractor($className)
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:81
‪TYPO3\CMS\Core\Resource\TextExtraction\TextExtractorRegistry\getTextExtractor
‪TextExtractorInterface null getTextExtractor(FileInterface $file)
Definition: TextExtractorRegistry.php:92
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52