1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Itkg\DelayEventBundle\EventListener; |
4
|
|
|
|
5
|
|
|
use Itkg\DelayEventBundle\DomainManager\EventManagerInterface; |
6
|
|
|
use Itkg\DelayEventBundle\Event\SuccessProcessedEvent; |
7
|
|
|
use Itkg\DelayEventBundle\Event\ProcessedEvents; |
8
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* class RemoveSuccessedEventSubscriber |
12
|
|
|
*/ |
13
|
|
|
class RemoveSuccessedEventSubscriber implements EventSubscriberInterface |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var EventManagerInterface |
17
|
|
|
*/ |
18
|
|
|
private $eventManager; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @param EventManagerInterface $eventManager |
22
|
|
|
*/ |
23
|
|
|
public function __construct(EventManagerInterface $eventManager) |
24
|
|
|
{ |
25
|
|
|
$this->eventManager = $eventManager; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Returns an array of event names this subscriber wants to listen to. |
30
|
|
|
* |
31
|
|
|
* The array keys are event names and the value can be: |
32
|
|
|
* |
33
|
|
|
* * The method name to call (priority defaults to 0) |
34
|
|
|
* * An array composed of the method name to call and the priority |
35
|
|
|
* * An array of arrays composed of the method names to call and respective |
36
|
|
|
* priorities, or 0 if unset |
37
|
|
|
* |
38
|
|
|
* For instance: |
39
|
|
|
* |
40
|
|
|
* * array('eventName' => 'methodName') |
41
|
|
|
* * array('eventName' => array('methodName', $priority)) |
42
|
|
|
* * array('eventName' => array(array('methodName1', $priority), array('methodName2')) |
43
|
|
|
* |
44
|
|
|
* @return array The event names to listen to |
45
|
|
|
* |
46
|
|
|
* @api |
47
|
|
|
*/ |
48
|
|
|
public static function getSubscribedEvents() |
49
|
|
|
{ |
50
|
|
|
return array( |
51
|
|
|
ProcessedEvents::SUCCESS => 'onSuccess' |
52
|
|
|
); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param SuccessProcessedEvent $processedEvent |
57
|
|
|
*/ |
58
|
|
|
public function onSuccess(SuccessProcessedEvent $processedEvent) |
59
|
|
|
{ |
60
|
|
|
$this->eventManager->delete($processedEvent->getEvent()); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|