[TASK] Makes Uri/ExternalViewHelper compilable 66/39166/2
authorJan Helke <typo3@helke.de>
Fri, 1 May 2015 18:13:21 +0000 (20:13 +0200)
committerAndreas Fernandez <typo3@scripting-base.de>
Sat, 2 May 2015 16:44:59 +0000 (18:44 +0200)
Resolves: #66716
Releases: master
Change-Id: I0d5094091eed5eeb3e846c93b68ea5a804296291
Reviewed-on: http://review.typo3.org/39166
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Tested-by: Andreas Fernandez <typo3@scripting-base.de>
typo3/sysext/fluid/Classes/ViewHelpers/Uri/ExternalViewHelper.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Uri/ExternalViewHelperTest.php

index 992a667..e016b92 100644 (file)
@@ -10,6 +10,9 @@ namespace TYPO3\CMS\Fluid\ViewHelpers\Uri;
  *                                                                        *
  * The TYPO3 project - inspiring people to share!                         *
  *                                                                        */
+use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
+use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
+use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
 
 /**
  * A view helper for creating URIs to external targets.
@@ -33,7 +36,7 @@ namespace TYPO3\CMS\Fluid\ViewHelpers\Uri;
  *
  * @api
  */
-class ExternalViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
+class ExternalViewHelper extends AbstractViewHelper implements CompilableInterface {
 
        /**
         * @param string $uri target URI
@@ -42,11 +45,31 @@ class ExternalViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHe
         * @api
         */
        public function render($uri, $defaultScheme = 'http') {
+               return self::renderStatic(
+                       array(
+                               'uri' => $uri,
+                               'defaultScheme' => $defaultScheme
+                       ),
+                       $this->buildRenderChildrenClosure(),
+                       $this->renderingContext
+               );
+       }
+
+       /**
+        * @param array $arguments
+        * @param callable $renderChildrenClosure
+        * @param RenderingContextInterface $renderingContext
+        *
+        * @return string
+        */
+       static public function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) {
+               $uri = $arguments['uri'];
+               $defaultScheme = $arguments['defaultScheme'];
+
                $scheme = parse_url($uri, PHP_URL_SCHEME);
                if ($scheme === NULL && $defaultScheme !== '') {
                        $uri = $defaultScheme . '://' . $uri;
                }
                return $uri;
        }
-
 }
index b31311d..731a021 100644 (file)
@@ -10,11 +10,13 @@ namespace TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Uri;
  *                                                                        *
  * The TYPO3 project - inspiring people to share!                         *
  *                                                                        */
+use TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\ViewHelperBaseTestcase;
+use TYPO3\CMS\Fluid\ViewHelpers\Uri\ExternalViewHelper;
 
 /**
  * Testcase for the external uri view helper
  */
-class ExternalViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\ViewHelperBaseTestcase {
+class ExternalViewHelperTest extends ViewHelperBaseTestcase {
 
        /**
         * @var \TYPO3\CMS\Fluid\ViewHelpers\Uri\ExternalViewHelper
@@ -23,7 +25,7 @@ class ExternalViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Vie
 
        protected function setUp() {
                parent::setUp();
-               $this->viewHelper = new \TYPO3\CMS\Fluid\ViewHelpers\Uri\ExternalViewHelper();
+               $this->viewHelper = new ExternalViewHelper();
                $this->injectDependenciesIntoViewHelper($this->viewHelper);
                $this->viewHelper->initializeArguments();
        }