‪TYPO3CMS  11.5
NormalizedUrlViewHelper.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 
22 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
23 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
24 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithContentArgumentAndRenderStatic;
25 
49 class ‪NormalizedUrlViewHelper extends AbstractViewHelper
50 {
51  use CompileWithContentArgumentAndRenderStatic;
52 
56  public function ‪initializeArguments()
57  {
58  $this->registerArgument('pathOrUrl', 'string', 'Absolute path to file using EXT: syntax or URL.');
59  }
60 
69  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
70  {
71  $pathOrUrl = $renderChildrenClosure();
72  if (‪PathUtility::hasProtocolAndScheme($pathOrUrl)) {
73  return $pathOrUrl;
74  }
75 
76  return GeneralUtility::locationHeaderUrl(‪PathUtility::getPublicResourceWebPath($pathOrUrl));
77  }
78 }
‪TYPO3\CMS\Core\Utility\PathUtility
Definition: PathUtility.php:25
‪TYPO3\CMS\Core\Utility\PathUtility\getPublicResourceWebPath
‪static string getPublicResourceWebPath(string $resourcePath, bool $prefixWithSitePath=true)
Definition: PathUtility.php:98
‪TYPO3\CMS\Core\ViewHelpers\NormalizedUrlViewHelper\initializeArguments
‪initializeArguments()
Definition: NormalizedUrlViewHelper.php:55
‪TYPO3\CMS\Core\ViewHelpers
‪TYPO3\CMS\Core\ViewHelpers\NormalizedUrlViewHelper
Definition: NormalizedUrlViewHelper.php:50
‪TYPO3\CMS\Core\Utility\PathUtility\hasProtocolAndScheme
‪static bool hasProtocolAndScheme(string $path)
Definition: PathUtility.php:463
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Core\ViewHelpers\NormalizedUrlViewHelper\renderStatic
‪static string renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
Definition: NormalizedUrlViewHelper.php:68