[BUGFIX] TypoScript userFunc condition does not work with static methods 62/34062/2
authorOliver Hader <oliver@typo3.org>
Thu, 13 Nov 2014 12:55:40 +0000 (13:55 +0100)
committerMarkus Klein <klein.t3@reelworx.at>
Thu, 13 Nov 2014 15:26:44 +0000 (16:26 +0100)
TypoScript allows to utilize functions (user-functions) to
integrate custom condition processing. However, this currently
only works with function defined in the global namespace - it
does not work with static methods.

Thus, something like this snipped won't work:
[userFunc = ConditionMatcherUserFunctions::isTrue(1)]

The solution is simple, replace function_exists() with a more
generic is_callable() check.

Fixes: #62918
Releases: master, 6.2
Change-Id: I260c73cac26dfd14efc67bc9f65ff39d6ba74da8
Reviewed-on: http://review.typo3.org/34062
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Markus Klein <klein.t3@reelworx.at>
Tested-by: Markus Klein <klein.t3@reelworx.at>
typo3/sysext/core/Classes/Configuration/TypoScript/ConditionMatching/AbstractConditionMatcher.php
typo3/sysext/core/Tests/Unit/Configuration/ConditionMatcherTest.php
typo3/sysext/core/Tests/Unit/Configuration/ConditionMatcherUserFuncs.php

index dc02c1b..a5eab38 100644 (file)
@@ -417,7 +417,7 @@ abstract class AbstractConditionMatcher {
                                preg_match_all('/^\s*([^\(\s]+)\s*(?:\((.*)\))?\s*$/', $value, $matches);
                                $funcName = $matches[1][0];
                                $funcValues = $matches[2][0] ? $this->parseUserFuncArguments($matches[2][0]) : array();
-                               if (function_exists($funcName) && call_user_func_array($funcName, $funcValues)) {
+                               if (is_callable($funcName) && call_user_func_array($funcName, $funcValues)) {
                                        return TRUE;
                                }
                                return FALSE;
index ef65e34..7398448 100644 (file)
@@ -122,5 +122,13 @@ class ConditionMatcherTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $this->assertTrue($this->conditionMatcher->match('[userFunc = user_testQuotes("1 \" 2") ]'));
        }
 
+       /**
+        * @test
+        * @return void
+        */
+       public function testUserFuncWithClassMethodCall() {
+               $this->assertTrue($this->conditionMatcher->match('[userFunc = ConditionMatcherUserFunctions::isTrue(1)]'));
+       }
+
 }
 
index 7933355..41c076b 100644 (file)
@@ -48,5 +48,17 @@ namespace {
        function user_testQuotes($value) {
                return $value === '1 " 2';
        }
+
+       class ConditionMatcherUserFunctions {
+
+               /**
+                * @param mixed $value
+                * @return bool
+                */
+               static public function isTrue($value) {
+                       return (bool)$value;
+               }
+
+       }
 }