[TASK] Streamline phpdoc annotations in EXT:fluid
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / Uri / ExternalViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Fluid\ViewHelpers\Uri;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
18 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
19 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
20
21 /**
22 * A view helper for creating URIs to external targets.
23 * Currently the specified URI is simply passed through.
24 *
25 * = Examples =
26 *
27 * <code>
28 * <f:uri.external uri="http://www.typo3.org" />
29 * </code>
30 * <output>
31 * http://www.typo3.org
32 * </output>
33 *
34 * <code title="custom default scheme">
35 * <f:uri.external uri="typo3.org" defaultScheme="ftp" />
36 * </code>
37 * <output>
38 * ftp://typo3.org
39 * </output>
40 */
41 class ExternalViewHelper extends AbstractViewHelper
42 {
43 use CompileWithRenderStatic;
44
45 /**
46 * Initialize arguments
47 *
48 * @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception
49 */
50 public function initializeArguments()
51 {
52 $this->registerArgument('uri', 'string', 'target URI', true);
53 $this->registerArgument('defaultScheme', 'string', 'scheme the href attribute will be prefixed with if specified $uri does not contain a scheme already', false, 'http');
54 }
55
56 /**
57 * @param array $arguments
58 * @param \Closure $renderChildrenClosure
59 * @param RenderingContextInterface $renderingContext
60 *
61 * @return string Rendered URI
62 */
63 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
64 {
65 $uri = $arguments['uri'];
66 $defaultScheme = $arguments['defaultScheme'];
67
68 $scheme = parse_url($uri, PHP_URL_SCHEME);
69 if ($scheme === null && $defaultScheme !== '') {
70 $uri = $defaultScheme . '://' . $uri;
71 }
72 return $uri;
73 }
74 }