|
1
|
|
|
<?php |
|
2
|
|
|
namespace TYPO3Fluid\Fluid\Core\ViewHelper\Traits; |
|
3
|
|
|
|
|
4
|
|
|
use TYPO3Fluid\Fluid\Core\Compiler\TemplateCompiler; |
|
5
|
|
|
use TYPO3Fluid\Fluid\Core\Compiler\ViewHelperCompiler; |
|
6
|
|
|
use TYPO3Fluid\Fluid\Core\Exception; |
|
7
|
|
|
use TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\ViewHelperNode; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class CompilableWithContentArgumentAndRenderStatic |
|
11
|
|
|
* |
|
12
|
|
|
* Provides default methods for rendering and compiling |
|
13
|
|
|
* any ViewHelper that conforms to the `renderStatic` |
|
14
|
|
|
* method pattern but has the added common use case that |
|
15
|
|
|
* an argument value must be checked and used instead of |
|
16
|
|
|
* the normal render children closure, if that named |
|
17
|
|
|
* argument is specified and not empty. |
|
18
|
|
|
* |
|
19
|
|
|
* @deprecated Trait no longer required, content argument supported by any VH via base class. |
|
20
|
|
|
*/ |
|
21
|
|
|
trait CompileWithContentArgumentAndRenderStatic |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @return string |
|
25
|
|
|
*/ |
|
26
|
|
|
protected function resolveContentArgumentName() |
|
27
|
|
|
{ |
|
28
|
|
|
if (empty($this->contentArgumentName)) { |
|
29
|
|
|
$registeredArguments = call_user_func_array([$this, 'prepareArguments'], []); |
|
30
|
|
|
foreach ($registeredArguments as $registeredArgument) { |
|
31
|
|
|
if (!$registeredArgument->isRequired()) { |
|
32
|
|
|
$this->contentArgumentName = $registeredArgument->getName(); |
|
|
|
|
|
|
33
|
|
|
return $this->contentArgumentName; |
|
34
|
|
|
} |
|
35
|
|
|
} |
|
36
|
|
|
throw new Exception( |
|
37
|
|
|
sprintf('Attempting to compile %s failed. Chosen compile method requires that ViewHelper has ' . |
|
38
|
|
|
'at least one registered and optional argument', __CLASS__) |
|
39
|
|
|
); |
|
40
|
|
|
} |
|
41
|
|
|
return $this->contentArgumentName; |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: