[TASK] Extract status identifier to separate property 91/19591/8
authorNicole Cordes <typo3@cordes.co>
Fri, 5 Apr 2013 14:55:56 +0000 (16:55 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Fri, 5 Apr 2013 17:29:35 +0000 (19:29 +0200)
Instead of parsing the status objects for their classes it is better to
refactor the severity status as own property. So even the CSS class
backparsing can be dropped.

Change-Id: I6d709017e4b98582aa3b64e512107999d4f2bbb2
Resolves: #46943
Releases: 6.1
Reviewed-on: https://review.typo3.org/19591
Reviewed-by: Nicole Cordes
Tested-by: Nicole Cordes
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
Reviewed-by: Wouter Wolters
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
typo3/sysext/install/Classes/Installer.php
typo3/sysext/install/Classes/Report/EnvironmentStatusReport.php
typo3/sysext/install/Classes/SystemEnvironment/AbstractStatus.php
typo3/sysext/install/Classes/SystemEnvironment/ErrorStatus.php
typo3/sysext/install/Classes/SystemEnvironment/InfoStatus.php
typo3/sysext/install/Classes/SystemEnvironment/NoticeStatus.php
typo3/sysext/install/Classes/SystemEnvironment/OkStatus.php
typo3/sysext/install/Classes/SystemEnvironment/StatusInterface.php
typo3/sysext/install/Classes/SystemEnvironment/WarningStatus.php

index 4eecb1e..f01136c 100644 (file)
@@ -1328,31 +1328,23 @@ REMOTE_ADDR was \'' . \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REMOTE
                $statusObjects = $statusCheck->getStatus();
 
                $orderedStatus = array(
-                       'ErrorStatus' => array(),
-                       'WarningStatus' => array(),
-                       'OkStatus' => array(),
-                       'InfoStatus' => array(),
-                       'NoticeStatus' => array(),
+                       'error' => array(),
+                       'warning' => array(),
+                       'ok' => array(),
+                       'information' => array(),
+                       'notice' => array(),
                );
 
+               /** @var $statusObject \TYPO3\CMS\Install\SystemEnvironment\AbstractStatus */
                foreach ($statusObjects as $statusObject) {
-                       $className = get_class($statusObject);
-                       // Last part of class name
-                       $severityIdentifier = array_pop(explode('\\', $className));
-                       if (!is_array($orderedStatus[$severityIdentifier])) {
+                       $severityIdentifier = $statusObject->getSeverity();
+
+                       if (empty($severityIdentifier) || !is_array($orderedStatus[$severityIdentifier])) {
                                throw new \TYPO3\CMS\Install\Exception('Unknown status severity type', 1362602559);
                        }
                        $orderedStatus[$severityIdentifier][] = $statusObject;
                }
 
-               $severityToCssClass = array(
-                       'ErrorStatus' => 'error',
-                       'WarningStatus' => 'warning',
-                       'OkStatus' => 'ok',
-                       'InfoStatus' => 'information',
-                       'NoticeStatus' => 'notice',
-               );
-
                $messageHtmlBoilerPlate =
                        '<div class="typo3-message message-%1s" >' .
                                '<div class="header-container" >' .
@@ -1360,19 +1352,17 @@ REMOTE_ADDR was \'' . \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REMOTE
                                        '<div class="message-header message-right" ></div>' .
                                '</div >' .
                                '<div class="message-body" >%3s</div>' .
-                       '</div >' .
+                       '</div>' .
                        '<p></p>';
 
                $html = '<h3>System environment check</h3>';
                foreach ($orderedStatus as $severity) {
                        foreach ($severity as $status) {
                                /** @var $status \TYPO3\CMS\Install\SystemEnvironment\AbstractStatus */
-                               $className = get_class($status);
-                               // Last part of class name
-                               $severityIdentifier = array_pop(explode('\\', $className));
+                               $severityIdentifier = $status->getSeverity();
                                $html .= sprintf(
                                        $messageHtmlBoilerPlate,
-                                       $severityToCssClass[$severityIdentifier],
+                                       $severityIdentifier,
                                        $status->getTitle(),
                                        $status->getMessage()
                                );
index 2eebcb4..6a6140f 100644 (file)
@@ -43,19 +43,17 @@ class EnvironmentStatusReport implements \TYPO3\CMS\Reports\StatusProviderInterf
                $statusObjects = $statusCheck->getStatus();
 
                $reportStatusTypes = array(
-                       'ERROR' => array(),
-                       'WARNING' => array(),
-                       'OK' => array(),
-                       'INFO' => array(),
-                       'NOTICE' => array(),
+                       'error' => array(),
+                       'warning' => array(),
+                       'ok' => array(),
+                       'information' => array(),
+                       'notice' => array(),
                );
 
+               /** @var $statusObject \TYPO3\CMS\Install\SystemEnvironment\AbstractStatus */
                foreach ($statusObjects as $statusObject) {
-                       $className = get_class($statusObject);
-                       // Uppercase last part of class name, without last 6 chars:
-                       // TYPO3\CMS\Install\SystemEnvironment\ErrorStatus -> ERROR
-                       $severityIdentifier = strtoupper(substr(array_pop(explode('\\', $className)), 0, -6));
-                       if (!is_array($reportStatusTypes[$severityIdentifier])) {
+                       $severityIdentifier = $statusObject->getSeverity();
+                       if (empty($severityIdentifier) || !is_array($reportStatusTypes[$severityIdentifier])) {
                                throw new \TYPO3\CMS\Install\Exception('Unknown reports severity type', 1362602560);
                        }
                        $reportStatusTypes[$severityIdentifier][] = $statusObject;
@@ -66,8 +64,12 @@ class EnvironmentStatusReport implements \TYPO3\CMS\Reports\StatusProviderInterf
                        $value = count($statusObjects);
                        if ($value > 0) {
                                $pathToXliff = 'LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf';
-                               $message = $GLOBALS['LANG']->sL($pathToXliff . ':environment.status.message.' . strtolower($type));
-                               $severity = constant('\TYPO3\CMS\Reports\Status::' . $type);
+                               // Map information type to abbreviation which is used in \TYPO3\CMS\Reports\Status class
+                               if ($type === 'information') {
+                                       $type = 'info';
+                               }
+                               $message = $GLOBALS['LANG']->sL($pathToXliff . ':environment.status.message.' . $type);
+                               $severity = constant('\TYPO3\CMS\Reports\Status::' . strtoupper($type));
                                $statusArray[] = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
                                        'TYPO3\\CMS\\Reports\\Status',
                                        $GLOBALS['LANG']->sL($pathToXliff . ':environment.status.title'),
index 69b3116..8938891 100644 (file)
@@ -29,17 +29,29 @@ namespace TYPO3\CMS\Install\SystemEnvironment;
  *
  * @author Christian Kuhn <lolli@schwarzbu.ch>
  */
-class AbstractStatus implements StatusInterface {
+abstract class AbstractStatus implements StatusInterface {
+
+       /**
+        * @var string Severity
+        */
+       protected $severity = '';
 
        /**
         * @var string Title
         */
-       protected $title;
+       protected $title = '';
 
        /**
         * @var string Status message
         */
-       protected $message;
+       protected $message = '';
+
+       /**
+        * @return string The severity
+        */
+       public function getSeverity() {
+               return $this->severity;
+       }
 
        /**
         * @return string The title
index 9899e6c..8899c29 100644 (file)
@@ -31,5 +31,10 @@ namespace TYPO3\CMS\Install\SystemEnvironment;
  */
 class ErrorStatus extends AbstractStatus implements StatusInterface {
 
+       /**
+        * @var string The severity
+        */
+       protected $severity = 'error';
+
 }
 ?>
\ No newline at end of file
index 330f584..682ea7a 100644 (file)
@@ -31,5 +31,10 @@ namespace TYPO3\CMS\Install\SystemEnvironment;
  */
 class InfoStatus extends AbstractStatus implements StatusInterface {
 
+       /**
+        * @var string The severity
+        */
+       protected $severity = 'information';
+
 }
 ?>
\ No newline at end of file
index 2a5389e..8ee7c12 100644 (file)
@@ -31,5 +31,10 @@ namespace TYPO3\CMS\Install\SystemEnvironment;
  */
 class NoticeStatus extends AbstractStatus implements StatusInterface {
 
+       /**
+        * @var string The severity
+        */
+       protected $severity = 'notice';
+
 }
 ?>
\ No newline at end of file
index a63d122..680026e 100644 (file)
@@ -31,5 +31,10 @@ namespace TYPO3\CMS\Install\SystemEnvironment;
  */
 class OkStatus extends AbstractStatus implements StatusInterface {
 
+       /**
+        * @var string The severity
+        */
+       protected $severity = 'ok';
+
 }
 ?>
\ No newline at end of file
index dbec649..98ba128 100644 (file)
@@ -32,6 +32,11 @@ namespace TYPO3\CMS\Install\SystemEnvironment;
 interface StatusInterface {
 
        /**
+        * @return string The severity
+        */
+       public function getSeverity();
+
+       /**
         * @return string The title
         */
        public function getTitle();
index fc24c82..441ed2b 100644 (file)
@@ -31,5 +31,10 @@ namespace TYPO3\CMS\Install\SystemEnvironment;
  */
 class WarningStatus extends AbstractStatus implements StatusInterface {
 
+       /**
+        * @var string The severity
+        */
+       protected $severity = 'warning';
+
 }
 ?>
\ No newline at end of file