Skip to content

Commit bdd4bed

Browse files
committed
verifiers and events should trigger in correct order
1 parent 0577b22 commit bdd4bed

File tree

1 file changed

+12
-26
lines changed

1 file changed

+12
-26
lines changed

src/Event/EventDispatcher.php

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace PhpSchool\PhpWorkshop\Event;
44

5-
use Assert\Assertion;
65
use PhpSchool\PhpWorkshop\Result\ResultInterface;
76
use PhpSchool\PhpWorkshop\ResultAggregator;
87

@@ -18,11 +17,6 @@ class EventDispatcher
1817
*/
1918
private $listeners = [];
2019

21-
/**
22-
* @var array
23-
*/
24-
private $verifiers = [];
25-
2620
/**
2721
* @var ResultAggregator
2822
*/
@@ -48,19 +42,6 @@ public function dispatch(EventInterface $event)
4842
}
4943
}
5044

51-
if (array_key_exists($event->getName(), $this->verifiers)) {
52-
foreach ($this->verifiers[$event->getName()] as $verifier) {
53-
$result = $verifier($event);
54-
55-
//return type hints pls
56-
if ($result instanceof ResultInterface) {
57-
$this->resultAggregator->add($result);
58-
} else {
59-
//??!!
60-
}
61-
}
62-
}
63-
6445
return $event;
6546
}
6647

@@ -94,14 +75,19 @@ private function attachListener($eventName, callable $callback)
9475

9576
/**
9677
* @param string $eventName
97-
* @param callable $callback
78+
* @param callable $verifier
9879
*/
99-
public function insertVerifier($eventName, callable $callback)
80+
public function insertVerifier($eventName, callable $verifier)
10081
{
101-
if (!array_key_exists($eventName, $this->verifiers)) {
102-
$this->verifiers[$eventName] = [$callback];
103-
} else {
104-
$this->verifiers[$eventName][] = $callback;
105-
}
82+
$this->attachListener($eventName, function (EventInterface $event) use ($verifier) {
83+
$result = $verifier($event);
84+
85+
//return type hints pls
86+
if ($result instanceof ResultInterface) {
87+
$this->resultAggregator->add($result);
88+
} else {
89+
//??!!
90+
}
91+
});
10692
}
10793
}

0 commit comments

Comments
 (0)