Completed
Branch master (1d7ebe)
by Wanderson
02:15
created

Session::alert()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 2
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Win\Alert;
4
5
/**
6
 * Armazena e exibe Alertas
7
 */
8
class Session {
9
10
	/**
11
	 * Adiciona o alerta na sessão
12
	 * @param Alert $alert
13
	 */
14
	public static function addAlert(Alert $alert) {
15
		$_SESSION['alerts'][] = $alert;
16
	}
17
18
	/**
19
	 * Mostra todos os alertas criados, removendo-os da sessão
20
	 */
21
	public static function showAlerts() {
22
		foreach (static::getAlerts() as $alert) {
23
			$alert->load();
24
		}
25
		unset($_SESSION['alerts']);
26
	}
27
28
	/**
29
	 * Retorna todos os alertas da sessão
30
	 * @return Alert[]
31
	 */
32
	public static function getAlerts() {
33
		if (!isset($_SESSION['alerts'])) {
34
			$_SESSION['alerts'] = [];
35
		}
36
		return array_unique($_SESSION['alerts']);
37
	}
38
39
	/**
40
	 * Remove todos os alertas da sessão
41
	 */
42
	public static function clearAlerts() {
43
		unset($_SESSION['alerts']);
44
	}
45
46
	/**
47
	 * Retorna TRUE se a sessão possui algum alerta
48
	 * @return boolean
49
	 */
50
	public static function hasAlert() {
51
		return count(static::getAlerts());
52
	}
53
54
}
55