‪TYPO3CMS  ‪main
ProcessorRegistry.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 
22 
27 {
28  protected array ‪$registeredProcessors = [];
29 
33  public function ‪__construct(‪DependencyOrderingService $dependencyOrderingService)
34  {
35  $this->registeredProcessors = $dependencyOrderingService->‪orderByDependencies(
36  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['processors'] ?? []
37  );
38  }
39 
45  {
46  $processor = null;
47 
48  foreach ($this->registeredProcessors as $key => $processorConfiguration) {
49  if (!isset($processorConfiguration['className'])) {
50  throw new \RuntimeException(
51  'Missing key "className" for processor configuration "' . $key . '".',
52  1560875741
53  );
54  }
55 
56  $processor = GeneralUtility::makeInstance($processorConfiguration['className']);
57 
58  if (!$processor instanceof ‪ProcessorInterface) {
59  throw new \RuntimeException(
60  'Processor "' . get_class($processor) . '" needs to implement interface "' . ProcessorInterface::class . '".',
61  1560876288
62  );
63  }
64 
65  if ($processor->canProcessTask($task)) {
66  /*
67  * Stop checking for further processors to speed up image processing.
68  * If another processor should be used, it can be registered with higher priority.
69  */
70  break;
71  }
72 
73  $processor = null;
74  }
75 
76  if ($processor === null) {
77  throw new \RuntimeException(
78  sprintf('No matching file processor found for task type "%s" and name "%s".', $task->‪getType(), $task->‪getName()),
79  1560876294
80  );
81  }
82 
83  return $processor;
84  }
85 }
‪TYPO3\CMS\Core\Resource\Processing\TaskInterface\getType
‪getType()
‪TYPO3\CMS\Core\Resource\Processing\TaskInterface
Definition: TaskInterface.php:34
‪TYPO3\CMS\Core\Resource\Processing\ProcessorRegistry\$registeredProcessors
‪array $registeredProcessors
Definition: ProcessorRegistry.php:28
‪TYPO3\CMS\Core\Service\DependencyOrderingService\orderByDependencies
‪array orderByDependencies(array $items, $beforeKey='before', $afterKey='after')
Definition: DependencyOrderingService.php:51
‪TYPO3\CMS\Core\Resource\Processing
Definition: AbstractTask.php:18
‪TYPO3\CMS\Core\Resource\Processing\ProcessorRegistry\getProcessorByTask
‪getProcessorByTask(TaskInterface $task)
Definition: ProcessorRegistry.php:44
‪TYPO3\CMS\Core\Resource\Processing\ProcessorRegistry\__construct
‪__construct(DependencyOrderingService $dependencyOrderingService)
Definition: ProcessorRegistry.php:33
‪TYPO3\CMS\Core\Service\DependencyOrderingService
Definition: DependencyOrderingService.php:32
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Resource\Processing\ProcessorRegistry
Definition: ProcessorRegistry.php:27
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\Resource\Processing\ProcessorInterface
Definition: ProcessorInterface.php:22
‪TYPO3\CMS\Core\Resource\Processing\TaskInterface\getName
‪getName()