[BUGFIX] Call initializeObject() after instantiating empty objects
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Object / Container / Container.php
index 5888ef0..2e6d6f9 100644 (file)
@@ -136,6 +136,7 @@ class Container implements \TYPO3\CMS\Core\SingletonInterface {
                $classInfo = $this->getClassInfo($className);
                $object = $this->getInstantiator()->instantiate($className);
                $this->injectDependencies($object, $classInfo);
+               $this->initializeObject($object, $classInfo);
                return $object;
        }
 
@@ -176,9 +177,7 @@ class Container implements \TYPO3\CMS\Core\SingletonInterface {
                }
                $instance = $this->instanciateObject($classInfo, $givenConstructorArguments);
                $this->injectDependencies($instance, $classInfo);
-               if ($classInfo->getIsInitializeable() && is_callable(array($instance, 'initializeObject'))) {
-                       $instance->initializeObject();
-               }
+               $this->initializeObject($instance, $classInfo);
                if (!$classIsSingleton) {
                        unset($this->prototypeObjectsWhichAreCurrentlyInstanciated[$className]);
                }
@@ -242,6 +241,18 @@ class Container implements \TYPO3\CMS\Core\SingletonInterface {
                }
        }
 
+       /**
+        * Initialize $instance after injecting all dependencies
+        *
+        * @param object $instance
+        * @param \TYPO3\CMS\Extbase\Object\Container\ClassInfo $classInfo
+        */
+       protected function initializeObject($instance, \TYPO3\CMS\Extbase\Object\Container\ClassInfo $classInfo) {
+               if ($classInfo->getIsInitializeable() && is_callable(array($instance, 'initializeObject'))) {
+                       $instance->initializeObject();
+               }
+       }
+
        /**
         * Wrapper for dev log, in order to ease testing
         *
@@ -347,5 +358,4 @@ class Container implements \TYPO3\CMS\Core\SingletonInterface {
        public function isPrototype($className) {
                return !$this->isSingleton($className);
        }
-
 }