Skip to content

Commit 1fb66c2

Browse files
author
Thomas Rabaix
committed
First rework (not yet fonctionnal)
1 parent 4511b1b commit 1fb66c2

File tree

1 file changed

+48
-13
lines changed

1 file changed

+48
-13
lines changed

Invalidation/Recorder.php

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,23 @@ class Recorder
1414
{
1515
protected $collectionIdentifiers;
1616

17-
protected $informations = array();
17+
protected $stack = array();
1818

19+
protected $current = 0;
20+
21+
/**
22+
* @param ModelCollectionIdentifiers $collectionIdentifiers
23+
*/
1924
public function __construct(ModelCollectionIdentifiers $collectionIdentifiers)
2025
{
2126
$this->collectionIdentifiers = $collectionIdentifiers;
27+
$this->stack[$this->current] = array();
2228
}
2329

30+
/**
31+
* @param $object
32+
* @return void
33+
*/
2434
public function add($object)
2535
{
2636
$class = get_class($object);
@@ -31,28 +41,53 @@ public function add($object)
3141
return;
3242
}
3343

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();
3646
}
3747

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;
4050
}
4151
}
4252

43-
public function reset()
53+
/**
54+
* Add a new elements into the stack
55+
*
56+
* @return void
57+
*/
58+
public function push()
4459
{
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++;
4863
}
4964

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()
5171
{
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();
5480
}
5581

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();
5792
}
5893
}

0 commit comments

Comments
 (0)