‪TYPO3CMS  11.5
PublicUrlPrefixer.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 
24 
26 {
34  private static bool ‪$isProcessingUrl = false;
35 
37  {
38  $controller = $this->‪getCurrentFrontendController();
39  if (self::$isProcessingUrl || !$controller) {
40  return;
41  }
42  $resource = $event->‪getResource();
43  if (!$this->‪isLocalResource($resource)) {
44  return;
45  }
46 
47  // Before calling getPublicUrl, we set the static property to true to avoid to be called in a loop
48  self::$isProcessingUrl = true;
49  try {
50  $resource = $event->‪getResource();
51  $originalUrl = $event->‪getStorage()->getPublicUrl($resource);
52  if (!$originalUrl || ‪PathUtility::hasProtocolAndScheme($originalUrl)) {
53  return;
54  }
55  $event->‪setPublicUrl($controller->absRefPrefix . $originalUrl);
56  } finally {
57  self::$isProcessingUrl = false;
58  }
59  }
60 
61  private function ‪isLocalResource(‪ResourceInterface $resource): bool
62  {
63  return $resource->‪getStorage()->‪getDriverType() === 'Local';
64  }
65 
67  {
68  return ‪$GLOBALS['TSFE'] ?? null;
69  }
70 }
‪TYPO3\CMS\Core\Utility\PathUtility
Definition: PathUtility.php:25
‪TYPO3\CMS\Frontend\Resource\PublicUrlPrefixer\prefixWithAbsRefPrefix
‪prefixWithAbsRefPrefix(GeneratePublicUrlForResourceEvent $event)
Definition: PublicUrlPrefixer.php:36
‪TYPO3\CMS\Core\Resource\ResourceStorage\getDriverType
‪string getDriverType()
Definition: ResourceStorage.php:2904
‪TYPO3\CMS\Core\Resource\Event\GeneratePublicUrlForResourceEvent\setPublicUrl
‪setPublicUrl(?string $publicUrl)
Definition: GeneratePublicUrlForResourceEvent.php:91
‪TYPO3\CMS\Frontend\Resource
Definition: FileCollector.php:16
‪TYPO3\CMS\Core\Resource\ResourceInterface\getStorage
‪ResourceStorage getStorage()
‪TYPO3\CMS\Frontend\Resource\PublicUrlPrefixer
Definition: PublicUrlPrefixer.php:26
‪TYPO3\CMS\Frontend\Resource\PublicUrlPrefixer\isLocalResource
‪isLocalResource(ResourceInterface $resource)
Definition: PublicUrlPrefixer.php:61
‪TYPO3\CMS\Core\Resource\Event\GeneratePublicUrlForResourceEvent
Definition: GeneratePublicUrlForResourceEvent.php:31
‪TYPO3\CMS\Core\Resource\Event\GeneratePublicUrlForResourceEvent\getStorage
‪getStorage()
Definition: GeneratePublicUrlForResourceEvent.php:67
‪TYPO3\CMS\Core\Resource\Event\GeneratePublicUrlForResourceEvent\getResource
‪getResource()
Definition: GeneratePublicUrlForResourceEvent.php:62
‪TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
Definition: TypoScriptFrontendController.php:104
‪TYPO3\CMS\Frontend\Resource\PublicUrlPrefixer\$isProcessingUrl
‪static bool $isProcessingUrl
Definition: PublicUrlPrefixer.php:34
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Utility\PathUtility\hasProtocolAndScheme
‪static bool hasProtocolAndScheme(string $path)
Definition: PathUtility.php:463
‪TYPO3\CMS\Core\Resource\ResourceInterface
Definition: ResourceInterface.php:22
‪TYPO3\CMS\Frontend\Resource\PublicUrlPrefixer\getCurrentFrontendController
‪getCurrentFrontendController()
Definition: PublicUrlPrefixer.php:66