Passed
Push — master ( 189a75...597d2a )
by Jean-Christophe
05:35
created

FlashBag::key()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 2
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Ubiquity\utils\flash;
4
5
use Ubiquity\utils\http\USession;
6
7
/**
8
 * Bag for Session Flash messages
9
 * Ubiquity\utils\flash$FlashBag
10
 * This class is part of Ubiquity
11
 *
12
 * @author jcheron <[email protected]>
13
 * @version 1.0.1
14
 *
15
 */
16
class FlashBag implements \Iterator {
17
	const FLASH_BAG_KEY = "_flash_bag";
18
	private $array;
19
	private $position = 0;
20
21 7
	public function __construct() {
22 7
		USession::start ();
23 7
		$this->array = USession::get ( self::FLASH_BAG_KEY, [ ] );
24 7
	}
25
26 7
	public function addMessage($content, $title = NULL, $type = "info", $icon = null) {
27 7
		$this->array [] = new FlashMessage ( $content, $title, $type, $icon );
28 7
	}
29
30 1
	public function getMessages($type) {
31 1
		$result = [ ];
32 1
		foreach ( $this->array as $msg ) {
33 1
			if ($msg->getType () == $type)
34 1
				$result [] = $msg;
35
		}
36 1
		return $result;
37
	}
38
39 5
	public function getAll() {
40 5
		return $this->array;
41
	}
42
43 1
	public function clear() {
44 1
		$this->array = [ ];
45 1
		USession::delete ( self::FLASH_BAG_KEY );
46 1
	}
47
48 1
	public function rewind() {
49 1
		$this->position = 0;
50 1
	}
51
52
	/**
53
	 *
54
	 * @return FlashMessage
55
	 */
56 2
	public function current() {
57 2
		return $this->array [$this->position];
58
	}
59
60 1
	public function key() {
61 1
		return $this->position;
62
	}
63
64 2
	public function next() {
65 2
		++ $this->position;
66 2
	}
67
68 1
	public function valid() {
69 1
		return isset ( $this->array [$this->position] );
70
	}
71
72 1
	public function save() {
73 1
		$this->array = USession::set ( self::FLASH_BAG_KEY, $this->array );
74 1
	}
75
}
76
77