Skip to content

Commit

Permalink
First rework (not yet fonctionnal)
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Rabaix committed Feb 15, 2012
1 parent 4511b1b commit 1fb66c2
Showing 1 changed file with 48 additions and 13 deletions.
61 changes: 48 additions & 13 deletions Invalidation/Recorder.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,23 @@ class Recorder
{
protected $collectionIdentifiers;

protected $informations = array();
protected $stack = array();

protected $current = 0;

/**
* @param ModelCollectionIdentifiers $collectionIdentifiers
*/
public function __construct(ModelCollectionIdentifiers $collectionIdentifiers)
{
$this->collectionIdentifiers = $collectionIdentifiers;
$this->stack[$this->current] = array();
}

/**
* @param $object
* @return void
*/
public function add($object)
{
$class = get_class($object);
Expand All @@ -31,28 +41,53 @@ public function add($object)
return;
}

if (!isset($this->informations[$class])) {
$this->informations[$class] = array();
if (!isset($this->stack[$this->current][$class])) {
$this->stack[$this->current][$class] = array();
}

if (!in_array($identifier, $this->informations[$class])) {
$this->informations[$class][] = $identifier;
if (!in_array($identifier, $this->stack[$this->current][$class])) {
$this->stack[$this->current][$class][] = $identifier;
}
}

public function reset()
/**
* Add a new elements into the stack
*
* @return void
*/
public function push()
{
foreach ($this->informations as $class => $identifier) {
$this->informations[$class] = array();
}
$this->stack[$this->current + 1] = $this->stack[$this->current];

$this->current++;
}

public function get($name = null)
/**
* Remove an element from the stack and return it
*
* @return array
*/
public function pop()
{
if ($name) {
return $this->informations[$name];
$value = $this->stack[$this->current];

unset($this->stack[$this->current]);

$this->current--;

if ($this->current < 0) {
$this->reset();
}

return $this->informations;
return $value;
}

/**
* @return void
*/
public function reset()
{
$this->current = 0;
$this->stack = array();
}
}

0 comments on commit 1fb66c2

Please sign in to comment.