[BUGFIX] Unnecessary instantiation of objects in contentObjectRender 44/30644/4
authorTomas Norre Mikkelsen <tomasnorre@gmail.com>
Tue, 10 Jun 2014 13:15:15 +0000 (15:15 +0200)
committerSteffen Ritter <info@rs-websystems.de>
Thu, 12 Jun 2014 11:39:53 +0000 (13:39 +0200)
Classes implementing the hook cObjTypeAndClass are instantiated each
time a contentObjectRender is created, even if they are not needed.

This patch introduces lazy loading.

Change-Id: Ifdae8c35fccc8d5070e8b7b30b5e275d9b26561d
Resolves: #59449
Releases: 6.2
Reviewed-on: https://review.typo3.org/30644
Reviewed-by: Xavier Perseguers
Tested-by: Xavier Perseguers
Reviewed-by: Steffen Ritter
Reviewed-by: Fabien Udriot
Reviewed-by: Christian Zenker
Tested-by: Christian Zenker
Tested-by: Steffen Ritter
typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php

index dc7ee27..6e6e3e8 100644 (file)
@@ -510,6 +510,12 @@ class ContentObjectRenderer {
 
        // Containing hooks for userdefined cObjects
        /**
+        * Additionally registered content object types and class names
+        * @var array
+        */
+       protected $cObjHookObjectsRegistry = array();
+
+       /**
         * @todo Define visibility
         */
        public $cObjHookObjectsArr = array();
@@ -570,7 +576,7 @@ class ContentObjectRenderer {
                $this->parameters = array();
                if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_content.php']['cObjTypeAndClass'])) {
                        foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_content.php']['cObjTypeAndClass'] as $classArr) {
-                               $this->cObjHookObjectsArr[$classArr[0]] = GeneralUtility::getUserObj($classArr[1]);
+                               $this->cObjHookObjectsRegistry[$classArr[0]] = $classArr[1];
                        }
                }
                $this->stdWrapHookObjects = array();
@@ -734,7 +740,10 @@ class ContentObjectRenderer {
                        } else {
                                $hooked = FALSE;
                                // Application defined cObjects
-                               if (!empty($this->cObjHookObjectsArr[$name])) {
+                               if (!empty($this->cObjHookObjectsRegistry[$name])) {
+                                       if (empty($this->cObjHookObjectsArr[$name])) {
+                                               $this->cObjHookObjectsArr[$name] = GeneralUtility::getUserObj($this->cObjHookObjectsRegistry[$name]);
+                                       }
                                        $hookObj = $this->cObjHookObjectsArr[$name];
                                        if (method_exists($hookObj, 'cObjGetSingleExt')) {
                                                $content .= $hookObj->cObjGetSingleExt($name, $conf, $TSkey, $this);