@@ -14,13 +14,23 @@ class Recorder
14
14
{
15
15
protected $ collectionIdentifiers ;
16
16
17
- protected $ informations = array ();
17
+ protected $ stack = array ();
18
18
19
+ protected $ current = 0 ;
20
+
21
+ /**
22
+ * @param ModelCollectionIdentifiers $collectionIdentifiers
23
+ */
19
24
public function __construct (ModelCollectionIdentifiers $ collectionIdentifiers )
20
25
{
21
26
$ this ->collectionIdentifiers = $ collectionIdentifiers ;
27
+ $ this ->stack [$ this ->current ] = array ();
22
28
}
23
29
30
+ /**
31
+ * @param $object
32
+ * @return void
33
+ */
24
34
public function add ($ object )
25
35
{
26
36
$ class = get_class ($ object );
@@ -31,28 +41,53 @@ public function add($object)
31
41
return ;
32
42
}
33
43
34
- if (!isset ($ this ->informations [$ class ])) {
35
- $ this ->informations [$ class ] = array ();
44
+ if (!isset ($ this ->stack [ $ this -> current ] [$ class ])) {
45
+ $ this ->stack [ $ this -> current ] [$ class ] = array ();
36
46
}
37
47
38
- if (!in_array ($ identifier , $ this ->informations [$ class ])) {
39
- $ this ->informations [$ class ][] = $ identifier ;
48
+ if (!in_array ($ identifier , $ this ->stack [ $ this -> current ] [$ class ])) {
49
+ $ this ->stack [ $ this -> current ] [$ class ][] = $ identifier ;
40
50
}
41
51
}
42
52
43
- public function reset ()
53
+ /**
54
+ * Add a new elements into the stack
55
+ *
56
+ * @return void
57
+ */
58
+ public function push ()
44
59
{
45
- foreach ( $ this ->informations as $ class => $ identifier ) {
46
- $ this -> informations [ $ class ] = array ();
47
- }
60
+ $ this ->stack [ $ this -> current + 1 ] = $ this -> stack [ $ this -> current ];
61
+
62
+ $ this -> current ++;
48
63
}
49
64
50
- public function get ($ name = null )
65
+ /**
66
+ * Remove an element from the stack and return it
67
+ *
68
+ * @return array
69
+ */
70
+ public function pop ()
51
71
{
52
- if ($ name ) {
53
- return $ this ->informations [$ name ];
72
+ $ value = $ this ->stack [$ this ->current ];
73
+
74
+ unset($ this ->stack [$ this ->current ]);
75
+
76
+ $ this ->current --;
77
+
78
+ if ($ this ->current < 0 ) {
79
+ $ this ->reset ();
54
80
}
55
81
56
- return $ this ->informations ;
82
+ return $ value ;
83
+ }
84
+
85
+ /**
86
+ * @return void
87
+ */
88
+ public function reset ()
89
+ {
90
+ $ this ->current = 0 ;
91
+ $ this ->stack = array ();
57
92
}
58
93
}
0 commit comments