‪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  if (self::$isProcessingUrl) {
37  return;
38  }
39  $resource = $event->‪getResource();
40  if (!$this->‪isLocalResource($resource)) {
41  return;
42  }
43 
44  // Before calling getPublicUrl, we set the static property to true to avoid to be called in a loop
45  self::$isProcessingUrl = true;
46  try {
47  $resource = $event->‪getResource();
48  $originalUrl = $event->‪getStorage()->getPublicUrl($resource);
49  if (!$originalUrl || ‪PathUtility::hasProtocolAndScheme($originalUrl)) {
50  return;
51  }
52  $event->‪setPublicUrl(GeneralUtility::getIndpEnv('TYPO3_SITE_PATH') . $originalUrl);
53  } finally {
54  self::$isProcessingUrl = false;
55  }
56  }
57 
58  private function ‪isLocalResource(‪ResourceInterface $resource): bool
59  {
60  return $resource->‪getStorage()->getDriverType() === 'Local';
61  }
62 }
‪TYPO3\CMS\Core\Utility\PathUtility
Definition: PathUtility.php:27
‪TYPO3\CMS\Backend\Resource\PublicUrlPrefixer\$isProcessingUrl
‪static bool $isProcessingUrl
Definition: PublicUrlPrefixer.php:32
‪TYPO3\CMS\Core\Resource\Event\GeneratePublicUrlForResourceEvent\setPublicUrl
‪setPublicUrl(?string $publicUrl)
Definition: GeneratePublicUrlForResourceEvent.php:60
‪TYPO3\CMS\Core\Resource\ResourceInterface\getStorage
‪getStorage()
‪TYPO3\CMS\Backend\Resource\PublicUrlPrefixer
Definition: PublicUrlPrefixer.php:26
‪TYPO3\CMS\Backend\Resource
‪TYPO3\CMS\Core\Resource\Event\GeneratePublicUrlForResourceEvent
Definition: GeneratePublicUrlForResourceEvent.php:31
‪TYPO3\CMS\Core\Resource\Event\GeneratePublicUrlForResourceEvent\getStorage
‪getStorage()
Definition: GeneratePublicUrlForResourceEvent.php:45
‪TYPO3\CMS\Backend\Resource\PublicUrlPrefixer\prefixWithSitePath
‪prefixWithSitePath(GeneratePublicUrlForResourceEvent $event)
Definition: PublicUrlPrefixer.php:34
‪TYPO3\CMS\Core\Resource\Event\GeneratePublicUrlForResourceEvent\getResource
‪getResource()
Definition: GeneratePublicUrlForResourceEvent.php:40
‪TYPO3\CMS\Backend\Resource\PublicUrlPrefixer\isLocalResource
‪isLocalResource(ResourceInterface $resource)
Definition: PublicUrlPrefixer.php:58
‪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\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52