|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* YAWIK |
|
4
|
|
|
* |
|
5
|
|
|
* @filesource |
|
6
|
|
|
* @license MIT |
|
7
|
|
|
* @copyright 2013 - 2018 Cross Solution <http://cross-solution.de> |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
/** */ |
|
11
|
|
|
namespace Core\Service\EntityEraser; |
|
12
|
|
|
|
|
13
|
|
|
use Core\EventManager\EventManager as CoreEventManager; |
|
14
|
|
|
use Zend\EventManager\EventInterface; |
|
15
|
|
|
use Zend\EventManager\SharedEventManagerInterface; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* EventManager for Dependency events. |
|
19
|
|
|
* |
|
20
|
|
|
* Handles the repsonses from the listeners and add them to the events' dependency result collection. |
|
21
|
|
|
* |
|
22
|
|
|
* @author Mathias Gelhausen <[email protected]> |
|
23
|
|
|
* @todo write test |
|
24
|
|
|
*/ |
|
25
|
|
|
class EntityEraserEvents extends CoreEventManager |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* Set the event prototype. |
|
29
|
|
|
* |
|
30
|
|
|
* Only instances of DependencyResultEvent are allowed. |
|
31
|
|
|
* |
|
32
|
|
|
* @param EventInterface $prototype |
|
33
|
|
|
* @throws \InvalidArgumentException |
|
34
|
|
|
*/ |
|
35
|
|
|
public function setEventPrototype(EventInterface $prototype) |
|
36
|
|
|
{ |
|
37
|
|
|
if (!$prototype instanceOf DependencyResultEvent) { |
|
38
|
|
|
throw new \InvalidArgumentException('This event manager only accepts events of the type ' . DependencyResultEvent::class); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
parent::setEventPrototype($prototype); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Triggers listeners. |
|
46
|
|
|
* |
|
47
|
|
|
* Loops over the responses and tries to add any non empty response as a DepnendecyResult to the collection. |
|
48
|
|
|
* |
|
49
|
|
|
* @param EventInterface $event |
|
50
|
|
|
* @param callable|null $callback |
|
51
|
|
|
* |
|
52
|
|
|
* @return \Zend\EventManager\ResponseCollection |
|
53
|
|
|
* @throws \InvalidArgumentException if the event is not an instance of DependencyResultEvent |
|
54
|
|
|
*/ |
|
55
|
|
|
protected function triggerListeners(EventInterface $event, callable $callback = null) |
|
56
|
|
|
{ |
|
57
|
|
|
if (!$event instanceOf DependencyResultEvent) { |
|
58
|
|
|
throw new \InvalidArgumentException('This event manager only accepts events of the type ' . DependencyResultEvent::class); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
$results = parent::triggerListeners($event, $callback); |
|
62
|
|
|
|
|
63
|
|
|
$dependencies = $event->getDependencyResultCollection(); |
|
64
|
|
|
|
|
65
|
|
|
foreach ($results as $result) { |
|
66
|
|
|
if (null !== $result) { |
|
67
|
|
|
try { $dependencies->add($result); } |
|
68
|
|
|
/* silently ignore all invalid results */ |
|
69
|
|
|
catch (\UnexpectedValueException $e) {} |
|
70
|
|
|
catch (\InvalidArgumentException $e) {} |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
return $results; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
|
|
78
|
|
|
} |
|
79
|
|
|
|