[BUGFIX] Use late static binding for compilable viewhelpers
[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 script is backported from the TYPO3 Flow package "TYPO3.Fluid". *
6 * *
7 * It is free software; you can redistribute it and/or modify it under *
8 * the terms of the GNU Lesser General Public License, either version 3 *
9 * of the License, or (at your option) any later version. *
10 * *
11 * The TYPO3 project - inspiring people to share! *
12 * */
13
14 use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
15 use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
16 use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
17
18 /**
19 * A view helper for creating URIs to external targets.
20 * Currently the specified URI is simply passed through.
21 *
22 * = Examples =
23 *
24 * <code>
25 * <f:uri.external uri="http://www.typo3.org" />
26 * </code>
27 * <output>
28 * http://www.typo3.org
29 * </output>
30 *
31 * <code title="custom default scheme">
32 * <f:uri.external uri="typo3.org" defaultScheme="ftp" />
33 * </code>
34 * <output>
35 * ftp://typo3.org
36 * </output>
37 *
38 * @api
39 */
40 class ExternalViewHelper extends AbstractViewHelper implements CompilableInterface {
41
42 /**
43 * @param string $uri target URI
44 * @param string $defaultScheme scheme the href attribute will be prefixed with if specified $uri does not contain a scheme already
45 * @return string Rendered URI
46 * @api
47 */
48 public function render($uri, $defaultScheme = 'http') {
49 return static::renderStatic(
50 array(
51 'uri' => $uri,
52 'defaultScheme' => $defaultScheme
53 ),
54 $this->buildRenderChildrenClosure(),
55 $this->renderingContext
56 );
57 }
58
59 /**
60 * @param array $arguments
61 * @param callable $renderChildrenClosure
62 * @param RenderingContextInterface $renderingContext
63 *
64 * @return string
65 */
66 static public function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) {
67 $uri = $arguments['uri'];
68 $defaultScheme = $arguments['defaultScheme'];
69
70 $scheme = parse_url($uri, PHP_URL_SCHEME);
71 if ($scheme === NULL && $defaultScheme !== '') {
72 $uri = $defaultScheme . '://' . $uri;
73 }
74 return $uri;
75 }
76
77 }