[TASK] Re-work/simplify copyright header in PHP files - Part 1
[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 $orderedStatus = array(
32 'alert' => $this->filterBySeverity($statusObjects, 'alert'),
33 'error' => $this->filterBySeverity($statusObjects, 'error'),
34 'warning' => $this->filterBySeverity($statusObjects, 'warning'),
35 'ok' => $this->filterBySeverity($statusObjects, 'ok'),
36 'information' => $this->filterBySeverity($statusObjects, 'information'),
37 'notice' => $this->filterBySeverity($statusObjects, 'notice'),
38 );
39 return $orderedStatus;
40 }
41
42 /**
43 * Filter a list of status objects by severity
44 *
45 * @param array $statusObjects Given list of status objects
46 * @param string $severity Severity identifier
47 * @throws Exception
48 * @return array List of status objects with given severity
49 */
50 public function filterBySeverity(array $statusObjects = array(), $severity = 'ok') {
51 $filteredObjects = array();
52 /** @var $status StatusInterface */
53 foreach ($statusObjects as $status) {
54 if (!$status instanceof StatusInterface) {
55 throw new Exception(
56 'Object must implement StatusInterface',
57 1366919442
58 );
59 }
60 if ($status->getSeverity() === $severity) {
61 $filteredObjects[] = $status;
62 }
63 }
64 return $filteredObjects;
65 }
66 }