Skip to content

Commit

Permalink
Refactor queue to use observation classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Stratadox committed Jan 25, 2018
1 parent f87f0f2 commit 63c98e3
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,23 @@ class Queue implements QueuesObservations
{
private $observations;

public function __construct()
{
$this->observations = new Observations;
}

public function add($observer, string $method, ...$params) : void
{
$this->observations[] = [$observer, $method, $params];
$this->observations = $this->observations->add(
new Observation($observer, $method, ...$params)
);
}

public function trigger() : void
{
foreach ($this->observations as $i => $observation) {
unset($this->observations[$i]);
call_user_func(
[$observation[0], $observation[1]],
...$observation[2]
);
foreach ($this->observations as $observation) {
$this->observations = $this->observations->remove($observation);
$observation->trigger();
}
}
}

0 comments on commit 63c98e3

Please sign in to comment.