[TASK] TemplateService: Add verbose option 06/32706/2
authorBenjamin Mack <benni@typo3.org>
Wed, 10 Sep 2014 13:56:36 +0000 (15:56 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Sat, 13 Sep 2014 19:53:07 +0000 (21:53 +0200)
The TemplateService class contains the functionality
to parse the TypoScript constants that haven't
been replaced yet.

This is done each time in the frontend, although
it is only useful when $this->tt_track is active,
thus when a BE user is logged in, who can read the info.

The improvement in this patch is to skip the strstr()
check if not set, thus making first-hit page calls a bit
quicker and the code more readable.

Releases: 6.3
Resolves: #61512
Change-Id: I8ebdb5e4bdc643e24dc9328ef48ed91a67376636
Reviewed-on: http://review.typo3.org/32706
Reviewed-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
Tested-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/core/Classes/TypoScript/TemplateService.php
typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php

index b1acc13..3d8b6a5 100644 (file)
@@ -27,6 +27,15 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
 class TemplateService {
 
        // Debugging, analysis:
+       /**
+        * option to enable logging, time-tracking (FE-only)
+        * usually, this is only done when
+        *  - in FE a BE_USER is logged-in
+        *  - in BE when the BE_USER needs information about the template (TypoScript module)
+        * @var bool
+        */
+       protected $verbose = FALSE;
+
        // If set, the global tt-timeobject is used to log the performance.
        /**
         * @todo Define visibility
@@ -304,6 +313,14 @@ class TemplateService {
        }
 
        /**
+        * sets the verbose parameter
+        * @param bool $verbose
+        */
+       public function setVerbose($verbose) {
+               $this->verbose = (bool)$verbose;
+       }
+
+       /**
         * Initialize
         * MUST be called directly after creating a new template-object
         *
@@ -940,19 +957,24 @@ class TemplateService {
                if ($this->tt_track) {
                        $GLOBALS['TT']->pull();
                }
+
                // Searching for possible unsubstituted constants left (only for information)
-               if (strstr($all, '{$')) {
-                       $theConstList = array();
-                       $findConst = explode('{$', $all);
-                       array_shift($findConst);
-                       foreach ($findConst as $constVal) {
-                               $constLen = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange(strcspn($constVal, '}'), 0, 50);
-                               $theConstList[] = '{$' . substr($constVal, 0, ($constLen + 1));
-                       }
-                       if ($this->tt_track) {
-                               $GLOBALS['TT']->setTSlogMessage(implode(', ', $theConstList) . ': Constants may remain un-substituted!!', 2);
+               if ($this->verbose) {
+                       if (strstr($all, '{$')) {
+                               $theConstList = array();
+                               $findConst = explode('{$', $all);
+                               array_shift($findConst);
+                               foreach ($findConst as $constVal) {
+                                       $constLen = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange(strcspn($constVal, '}'), 0, 50);
+                                       $theConstList[] = '{$' . substr($constVal, 0, ($constLen + 1));
+                               }
+                               if ($this->tt_track) {
+                                       $GLOBALS['TT']->setTSlogMessage(implode(', ', $theConstList) . ': Constants may remain un-substituted!!', 2);
+                               }
                        }
+
                }
+
                // Logging the textual size of the TypoScript Setup field text with all constants substituted:
                if ($this->tt_track) {
                        $GLOBALS['TT']->setTSlogMessage('TypoScript template size as textfile: ' . strlen($all) . ' bytes');
index 8676c59..dce83df 100644 (file)
@@ -2308,6 +2308,7 @@ class TypoScriptFrontendController {
         */
        public function initTemplate() {
                $this->tmpl = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\TypoScript\\TemplateService');
+               $this->tmpl->setVerbose((bool)$this->beUserLogin);
                $this->tmpl->init();
                $this->tmpl->tt_track = (bool)$this->beUserLogin;
        }