[TASK] Detect inject methods more strictly
authortomas <t.grzemski@macopedia.pl>
Sat, 17 Nov 2012 09:55:15 +0000 (10:55 +0100)
committerOliver Hader <oliver.hader@typo3.org>
Sat, 13 Apr 2013 18:52:34 +0000 (20:52 +0200)
Bugport from Flow https://review.typo3.org/#/c/13566/.
It checks method name to prevent using for example injectingFoo.

Change-Id: I5a70c3b21682143cd515bb2fe9ca03618bf834d4
Resolves: #40337
Releases: 6.1
Reviewed-on: https://review.typo3.org/16511
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
typo3/sysext/extbase/Classes/Object/Container/ClassInfoFactory.php
typo3/sysext/extbase/Tests/Unit/Object/Container/Fixtures/Testclasses.php

index 74d017a..e667a0c 100644 (file)
@@ -94,7 +94,7 @@ class ClassInfoFactory {
                $reflectionMethods = $reflectedClass->getMethods();
                if (is_array($reflectionMethods)) {
                        foreach ($reflectionMethods as $reflectionMethod) {
-                               if ($reflectionMethod->isPublic() && substr($reflectionMethod->getName(), 0, 6) === 'inject' && $reflectionMethod->getName() !== 'injectSettings') {
+                               if ($reflectionMethod->isPublic() && $this->isNameOfInjectMethod($reflectionMethod->getName())) {
                                        $reflectionParameter = $reflectionMethod->getParameters();
                                        if (isset($reflectionParameter[0])) {
                                                if (!$reflectionParameter[0]->getClass()) {
@@ -132,7 +132,24 @@ class ClassInfoFactory {
        }
 
        /**
-        * This method is used to determin if a class is a singleton or not.
+        * This method checks if given method can be used for injection
+        *
+        * @param string $methodName
+        * @return boolean
+        */
+       private function isNameOfInjectMethod($methodName) {
+               if (
+                       substr($methodName, 0, 6) === 'inject'
+                       && $methodName[6] === strtoupper($methodName[6])
+                       && $methodName !== 'injectSettings'
+               ) {
+                       return TRUE;
+               }
+               return FALSE;
+       }
+
+       /**
+        * This method is used to determine if a class is a singleton or not.
         *
         * @param string $classname
         * @return boolean
index e0cdf9a..d423ac4 100644 (file)
@@ -310,6 +310,13 @@ class t3lib_object_tests_class_with_injectsettings {
        public function injectFoo(\t3lib_object_tests_resolveablecyclic1 $c1) {
        }
 
+       /**
+        * @param \t3lib_object_tests_resolveablecyclic1 $c1
+        */
+       public function injectingFoo(\t3lib_object_tests_resolveablecyclic1 $c1) {
+
+       }
+
        /**
         * @param array $settings
         */