Feature #56556
support hasProperty and isProperty
Status: | New | Start date: | 2014-03-04 | |
---|---|---|---|---|
Priority: | Should have | Due date: | ||
Assigned To: | - | % Done: | 0% |
|
Category: | - | |||
Target version: | - | |||
PHP Version: | Complexity: | |||
Has patch: | No |
Description
The way how you currently check for existence of a value in fluid is not nice.
<f:if condition="{object.hasChildren}"> [...] </f:if>
results in a method in the Model:
public function getHasChildren()
Instead it should be possible to just write:
public funtion hasChildren()
Same for "is".
Inspired by: https://github.com/czenker/cz_simple_cal/blob/master/Classes/Domain/Model/Base.php
Related issues
History
#1 Updated by Alexander Berl over 1 year ago
One thing that needs to be discussed before implementing this is, how the old "isSomething" behaviour should be handled, as it would create a redundancy/duplication:
If this is implemented in a BC way, it means that the method "isSomething" is accessible in two ways, by "{object.something}" (unless "getSomething" exists) and "{object.isSomething}" (unless "getIsSomething" exists).
Should this be kept or removed to force explicitt access as with "hasSomething"?
IMHO it would make more sense to require more verbose boolean checks in Fluid by "{object.isSomething}" instead of "{object.something}", which could also mean "getSomething", but that would be a pretty hard breaking change for a lot of Fluid templates.
Proposed solution in Classes/TYPO3/Flow/Reflection/ObjectAccess.php:
if (is_callable(array($subject, $getterMethodName))) { self::$propertyGetterCache[$identifier]['accessorMethod'] = $getterMethodName; } else { - $getterMethodName = 'is' . ucfirst($propertyName); + if (substr($propertyName, 0, 2) === 'is' || substr($propertyName, 0, 3) === 'has') { + $getterMethodName = $propertyName; + } else { + $getterMethodName = 'is' . ucfirst($propertyName); + } if (is_callable(array($subject, $getterMethodName))) { self::$propertyGetterCache[$identifier]['accessorMethod'] = $getterMethodName; } else {