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