‪TYPO3CMS  10.4
ExtractorService.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
23 
28 {
32  private ‪$extractionServices;
33 
38  public function ‪extractMetaData(‪File $fileObject): array
39  {
40  $newMetaData = [];
41  // Loop through available extractors and fetch metadata for the given file.
42  foreach ($this->‪getExtractionServices($fileObject->‪getStorage()->‪getDriverType()) as $service) {
43  foreach ($service ?? [] as $extractorService) {
44  if ($this->‪isFileTypeSupportedByExtractor($fileObject, $extractorService) &&
45  $extractorService->canProcess($fileObject)) {
46  $newMetaData[$extractorService->getPriority()] = $extractorService->extractMetaData($fileObject, $newMetaData);
47  }
48  }
49  }
50  // Sort metadata by priority so that merging happens in order of precedence.
51  ksort($newMetaData);
52  // Merge the collected metadata.
53  $metaData = [[]];
54  foreach ($newMetaData as $data) {
55  $metaData[] = $data;
56  }
57  return array_filter(array_merge(...$metaData));
58  }
59 
66  protected function ‪getExtractionServices(string $driverType): array
67  {
68  if (empty($this->extractionServices[$driverType])) {
69  $this->extractionServices[$driverType] = $this->‪getExtractorRegistry()->‪getExtractorsWithDriverSupport($driverType);
70  }
71  return $this->extractionServices[$driverType];
72  }
73 
81  private function ‪isFileTypeSupportedByExtractor(‪File $file, ‪ExtractorInterface $extractor): bool
82  {
83  $isSupported = true;
84  $fileTypeRestrictions = $extractor->‪getFileTypeRestrictions();
85  if (!empty($fileTypeRestrictions) && !in_array($file->‪getType(), $fileTypeRestrictions, true)) {
86  $isSupported = false;
87  }
88  return $isSupported;
89  }
90 
96  protected function ‪getExtractorRegistry(): ‪ExtractorRegistry
97  {
99  }
100 }
‪TYPO3\CMS\Core\Resource\Index\ExtractorInterface\getFileTypeRestrictions
‪array getFileTypeRestrictions()
‪TYPO3\CMS\Core\Resource\Service\ExtractorService\extractMetaData
‪array extractMetaData(File $fileObject)
Definition: ExtractorService.php:37
‪TYPO3\CMS\Core\Resource\Index\ExtractorRegistry\getExtractorsWithDriverSupport
‪ExtractorInterface[] getExtractorsWithDriverSupport($driverType)
Definition: ExtractorRegistry.php:94
‪TYPO3\CMS\Core\Resource\AbstractFile\getType
‪int getType()
Definition: AbstractFile.php:286
‪TYPO3\CMS\Core\Resource\ResourceStorage\getDriverType
‪string getDriverType()
Definition: ResourceStorage.php:2865
‪TYPO3\CMS\Core\Resource\Service\ExtractorService\getExtractionServices
‪ExtractorInterface[] getExtractionServices(string $driverType)
Definition: ExtractorService.php:65
‪TYPO3\CMS\Core\Resource\Service\ExtractorService\isFileTypeSupportedByExtractor
‪bool isFileTypeSupportedByExtractor(File $file, ExtractorInterface $extractor)
Definition: ExtractorService.php:80
‪TYPO3\CMS\Core\Resource\Index\ExtractorInterface
Definition: ExtractorInterface.php:25
‪TYPO3\CMS\Core\Resource\Index\ExtractorRegistry
Definition: ExtractorRegistry.php:25
‪TYPO3\CMS\Core\Resource\Service\ExtractorService\$extractionServices
‪ExtractorInterface[][] $extractionServices
Definition: ExtractorService.php:31
‪TYPO3\CMS\Core\Resource\Index\ExtractorRegistry\getInstance
‪static ExtractorRegistry getInstance()
Definition: ExtractorRegistry.php:42
‪TYPO3\CMS\Core\Resource\Service
Definition: ExtractorService.php:18
‪TYPO3\CMS\Core\Resource\File
Definition: File.php:24
‪TYPO3\CMS\Core\Resource\Service\ExtractorService
Definition: ExtractorService.php:28
‪TYPO3\CMS\Core\Resource\Service\ExtractorService\getExtractorRegistry
‪ExtractorRegistry getExtractorRegistry()
Definition: ExtractorService.php:95
‪TYPO3\CMS\Core\Resource\AbstractFile\getStorage
‪ResourceStorage getStorage()
Definition: AbstractFile.php:390