Total Complexity | 8 |
Total Lines | 44 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
7 | class AlertManager implements AlertManagerInterface |
||
8 | { |
||
9 | private $session; |
||
10 | |||
11 | public function __construct(Session $session) |
||
12 | { |
||
13 | $this->session = $session; |
||
14 | } |
||
15 | |||
16 | public function addAlert(AlertInterface $alert) |
||
17 | { |
||
18 | $this->session->getFlashBag()->add($alert->getType(), $alert->getMessage()); |
||
19 | } |
||
20 | |||
21 | public function getAlerts() |
||
22 | { |
||
23 | $alerts = []; |
||
24 | foreach (self::getAlertTypes() as $type) { |
||
25 | $messages = $this->session->getFlashBag()->get($type); |
||
26 | if (!empty($messages)) { |
||
27 | $alerts = array_merge($alerts, $this->createAlertsForType($type, $messages)); |
||
28 | } |
||
29 | } |
||
30 | |||
31 | return $alerts; |
||
32 | } |
||
33 | |||
34 | private function createAlertsForType($type, array $messages) |
||
35 | { |
||
36 | $alerts = []; |
||
37 | foreach ($messages as $msg) { |
||
38 | $alerts[] = new Alert($type, $msg); |
||
39 | } |
||
40 | |||
41 | return $alerts; |
||
42 | } |
||
43 | |||
44 | public static function getAlertTypes() |
||
51 | ]; |
||
52 | } |
||
53 | } |
||
54 |