cb11bb376da1dd032a5704b2aa8c13795da2e5c3
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Status / StatusUtility.php
1 <?php
2 namespace TYPO3\CMS\Install\Status;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * Utility methods to handle status objects. Provides some helper
19 * methods to filter, sort and render status objects.
20 */
21 class StatusUtility
22 {
23 /**
24 * Order status objects by severity
25 *
26 * @param array<\TYPO3\CMS\Install\Status\StatusInterface> $statusObjects Status objects in random order
27 * @return array With sub arrays by severity
28 * @throws Exception
29 */
30 public function sortBySeverity(array $statusObjects = array())
31 {
32 $orderedStatus = array(
33 'alert' => $this->filterBySeverity($statusObjects, 'alert'),
34 'danger' => $this->filterBySeverity($statusObjects, 'danger'),
35 'warning' => $this->filterBySeverity($statusObjects, 'warning'),
36 'success' => $this->filterBySeverity($statusObjects, 'success'),
37 'info' => $this->filterBySeverity($statusObjects, 'info'),
38 'notice' => $this->filterBySeverity($statusObjects, 'notice'),
39 );
40 return $orderedStatus;
41 }
42
43 /**
44 * Filter a list of status objects by severity
45 *
46 * @param array $statusObjects Given list of status objects
47 * @param string $severity Severity identifier
48 * @throws Exception
49 * @return array List of status objects with given severity
50 */
51 public function filterBySeverity(array $statusObjects = array(), $severity = 'ok')
52 {
53 $filteredObjects = array();
54 /** @var $status StatusInterface */
55 foreach ($statusObjects as $status) {
56 if (!$status instanceof StatusInterface) {
57 throw new Exception(
58 'Object must implement StatusInterface',
59 1366919442
60 );
61 }
62 if ($status->getSeverity() === $severity) {
63 $filteredObjects[] = $status;
64 }
65 }
66 return $filteredObjects;
67 }
68 }