Feature #56556

support hasProperty and isProperty

Added by Simon Schaufelberger over 5 years ago. Updated over 5 years ago.

Status:
New
Priority:
Should have
Assignee:
-
Category:
-
Target version:
-
Start date:
2014-03-04
Due date:
% Done:

0%

PHP Version:
Has patch:
No
Complexity:

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

Related to TYPO3 Core - Feature #56529: support hasProperty and isProperty Closed 2014-03-04

History

#1 Updated by Alexander Berl over 5 years 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 {

Also available in: Atom PDF