[BUGFIX] Fix several typos in php comments
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Resource / OnlineMedia / Helpers / OnlineMediaHelperRegistry.php
1 <?php
2 namespace TYPO3\CMS\Core\Resource\OnlineMedia\Helpers;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Resource\File;
18 use TYPO3\CMS\Core\Resource\Folder;
19 use TYPO3\CMS\Core\Utility\GeneralUtility;
20
21 /**
22 * Online Media Source Registry
23 */
24 class OnlineMediaHelperRegistry implements \TYPO3\CMS\Core\SingletonInterface
25 {
26 /**
27 * Returns an instance of this class
28 *
29 * @return OnlineMediaHelperRegistry
30 */
31 public static function getInstance()
32 {
33 return GeneralUtility::makeInstance(self::class);
34 }
35
36 /**
37 * Get helper class for given File
38 *
39 * @param File $file
40 * @return bool|OnlineMediaHelperInterface
41 */
42 public function getOnlineMediaHelper(File $file)
43 {
44 $registeredHelpers = $GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['onlineMediaHelpers'];
45 if (isset($registeredHelpers[$file->getExtension()])) {
46 return GeneralUtility::makeInstance($registeredHelpers[$file->getExtension()], $file->getExtension());
47 }
48 return false;
49 }
50
51 /**
52 * Try to transform given URL to a File
53 *
54 * @param string $url
55 * @param Folder $targetFolder
56 * @param string[] $allowedExtensions
57 * @return File|null
58 */
59 public function transformUrlToFile($url, Folder $targetFolder, $allowedExtensions = [])
60 {
61 $registeredHelpers = $GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['onlineMediaHelpers'];
62 foreach ($registeredHelpers as $extension => $className) {
63 if (!empty($allowedExtensions) && !in_array($extension, $allowedExtensions, true)) {
64 continue;
65 }
66 /** @var OnlineMediaHelperInterface $helper */
67 $helper = GeneralUtility::makeInstance($className, $extension);
68 $file = $helper->transformUrlToFile($url, $targetFolder);
69 if ($file !== null) {
70 return $file;
71 }
72 }
73 return null;
74 }
75
76 /**
77 * Get all file extensions that have an OnlineMediaHelper
78 *
79 * @return string[]
80 */
81 public function getSupportedFileExtensions()
82 {
83 return array_keys($GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['onlineMediaHelpers']);
84 }
85 }