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