Fluid
Fluid copied to clipboard
f:assert ViewHelper
A new <f:assert> ViewHelper should be added to Fluid, which checks if a provided values type is matching with the given type. If the type dose not match, the ViewHelper will throw an Exception.
Arguments:
mixed $value (can be any value that is matched against the type)
string $type
See also the pattern-matching rfc.
Examples:
<f:assert value="{user.name}" type="string" />
<f:assert value="{user.age}" type="int" />
<f:assert value="{user.birthday}" type="DateTimeInterface" />
<f:assert value="{data}" type="TYPO3\CMS\ContentBlocks\DataProcessing\ContentBlockData" />
<f:assert value="{data}" type="?TYPO3\CMS\ContentBlocks\DataProcessing\ContentBlockData" /> <!-- nullable -->
<f:assert value="{data}" type="TYPO3\CMS\ContentBlocks\DataProcessing\ContentBlockData|null" /> <!-- nullable/union type -->
<f:assert value="{data}" type="string|array" /> <!-- union type -->
<f:assert value="{data}" type="Traversable&Countable" /><!-- intersection type -->
<f:assert value="{data}" type="User|(Account&Authenticated)" /><!-- union + intersection type -->
<f:assert value="{loginType}" type="0|100|200" /><!-- litteral + union type -->
<f:assert value="{loginType}" type="'login'|'logout'" /><!-- litteral + union type -->
We would probably start with the types the ArgumentProcessor already supports.
We just discussed this internally: We're currently unsure if this would cement the connection between the "PHP world" and Fluid templates too much. However, we're still open to the idea to add more validations to templates, so we will re-evaluate in the future.