85ee14f51bcb835464c386640d7fea1c148cb1cc
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Status / StatusUtility.php
1 <?php
2 namespace TYPO3\CMS\Install\Status;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2013 Christian Kuhn <lolli@schwarzbu.ch>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 /**
28 * Utility methods to handle status objects. Provides some helper
29 * methods to filter, sort and render status objects.
30 */
31 class StatusUtility {
32
33 /**
34 * Order status objects by severity
35 *
36 * @param array<\TYPO3\CMS\Install\Status\StatusInterface> $statusObjects Status objects in random order
37 * @return array With sub arrays by severity
38 * @throws Exception
39 */
40 public function sortBySeverity(array $statusObjects = array()) {
41 $orderedStatus = array(
42 'alert' => $this->filterBySeverity($statusObjects, 'alert'),
43 'error' => $this->filterBySeverity($statusObjects, 'error'),
44 'warning' => $this->filterBySeverity($statusObjects, 'warning'),
45 'ok' => $this->filterBySeverity($statusObjects, 'ok'),
46 'information' => $this->filterBySeverity($statusObjects, 'information'),
47 'notice' => $this->filterBySeverity($statusObjects, 'notice'),
48 );
49 return $orderedStatus;
50 }
51
52 /**
53 * Filter a list of status objects by severity
54 *
55 * @param array $statusObjects Given list of status objects
56 * @param string $severity Severity identifier
57 * @throws Exception
58 * @return array List of status objects with given severity
59 */
60 public function filterBySeverity(array $statusObjects = array(), $severity = 'ok') {
61 $filteredObjects = array();
62 /** @var $status StatusInterface */
63 foreach ($statusObjects as $status) {
64 if (!$status instanceof StatusInterface) {
65 throw new Exception(
66 'Object must implement StatusInterface',
67 1366919442
68 );
69 }
70 if ($status->getSeverity() === $severity) {
71 $filteredObjects[] = $status;
72 }
73 }
74 return $filteredObjects;
75 }
76 }