[TASK] Import forward-compatible Fluid compiling Traits
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Resources / PHP / Traits / CompileWithRenderStatic.php
1 <?php
2 namespace TYPO3Fluid\Fluid\Core\ViewHelper\Traits;
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 TYPO3\CMS\Fluid\Core\Compiler\TemplateCompiler;
18 use TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\AbstractNode;
19
20 /**
21 * Trait CompilableWithRenderStatic
22 *
23 * Provides default methods for rendering and compiling
24 * any ViewHelper that conforms to the `renderStatic`
25 * method pattern.
26 */
27 trait CompileWithRenderStatic
28 {
29
30 /**
31 * @return \Closure
32 */
33 abstract function buildRenderChildrenClosure();
34
35 /**
36 * Default render method - simply calls renderStatic() with a
37 * prepared set of arguments.
38 *
39 * @return string Rendered string
40 * @api
41 */
42 public function render() {
43 return static::renderStatic(
44 $this->arguments,
45 $this->buildRenderChildrenClosure(),
46 $this->renderingContext
47 );
48 }
49
50 /**
51 * @param string $argumentsName
52 * @param string $closureName
53 * @param string $initializationPhpCode
54 * @param AbstractNode $node
55 * @param TemplateCompiler $compiler
56 * @return string
57 */
58 public function compile(
59 $argumentsName,
60 $closureName,
61 &$initializationPhpCode,
62 AbstractNode $node,
63 TemplateCompiler $compiler
64 ) {
65 return sprintf(
66 '%s::renderStatic(%s, %s, $renderingContext)',
67 static::class,
68 $argumentsName,
69 $closureName
70 );
71 }
72 }