|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of Transfer. |
|
5
|
|
|
* |
|
6
|
|
|
* For the full copyright and license information, please view the LICENSE file located |
|
7
|
|
|
* in the root directory. |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Transfer\Processor; |
|
11
|
|
|
|
|
12
|
|
|
use Psr\Log\LoggerInterface; |
|
13
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcher; |
|
14
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
|
15
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
|
16
|
|
|
use Transfer\Adapter\SourceAdapterInterface; |
|
17
|
|
|
use Transfer\Adapter\TargetAdapterInterface; |
|
18
|
|
|
use Transfer\Adapter\Transaction\Request; |
|
19
|
|
|
use Transfer\Event as Events; |
|
20
|
|
|
use Transfer\Event\TransferEvents; |
|
21
|
|
|
use Transfer\Procedure\Procedure; |
|
22
|
|
|
use Transfer\Processor\EventSubscriber\Logger; |
|
23
|
|
|
use Transfer\Storage\StorageInterface; |
|
24
|
|
|
use Transfer\Worker\WorkerInterface; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Partial processor implementation with event functionality. |
|
28
|
|
|
*/ |
|
29
|
|
|
abstract class EventDrivenProcessor extends Processor |
|
30
|
|
|
{ |
|
31
|
|
|
/** |
|
32
|
|
|
* @var EventDispatcherInterface Event dispatcher |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $dispatcher; |
|
35
|
|
|
|
|
36
|
13 |
|
public function __construct() |
|
37
|
|
|
{ |
|
38
|
13 |
|
parent::__construct(); |
|
39
|
|
|
|
|
40
|
13 |
|
$this->dispatcher = new EventDispatcher(); |
|
41
|
13 |
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* {@inheritdoc} |
|
45
|
|
|
*/ |
|
46
|
2 |
|
public function setEventDispatcher(EventDispatcherInterface $dispatcher) |
|
47
|
|
|
{ |
|
48
|
2 |
|
$this->dispatcher = $dispatcher; |
|
49
|
2 |
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* {@inheritdoc} |
|
53
|
|
|
*/ |
|
54
|
1 |
|
public function addSubscriber(EventSubscriberInterface $subscriber) |
|
55
|
|
|
{ |
|
56
|
1 |
|
$this->dispatcher->addSubscriber($subscriber); |
|
57
|
1 |
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* {@inheritdoc} |
|
61
|
|
|
*/ |
|
62
|
5 |
|
public function addListener($eventName, $listener, $priority = 0) |
|
63
|
|
|
{ |
|
64
|
5 |
|
$this->dispatcher->addListener($eventName, $listener, $priority); |
|
65
|
5 |
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* {@inheritdoc} |
|
69
|
|
|
*/ |
|
70
|
1 |
|
public function setLogger(LoggerInterface $logger) |
|
71
|
|
|
{ |
|
72
|
1 |
|
parent::setLogger($logger); |
|
73
|
|
|
|
|
74
|
1 |
|
$this->addSubscriber(new Logger($logger)); |
|
75
|
1 |
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* {@inheritdoc} |
|
79
|
|
|
*/ |
|
80
|
10 |
|
public function process() |
|
81
|
|
|
{ |
|
82
|
10 |
|
$this->dispatcher->dispatch(TransferEvents::PRE_PROCESS, new Events\PreProcessEvent($this)); |
|
|
|
|
|
|
83
|
|
|
|
|
84
|
10 |
|
parent::process(); |
|
85
|
|
|
|
|
86
|
8 |
|
$this->dispatcher->dispatch(TransferEvents::POST_PROCESS, new Events\PostProcessEvent($this)); |
|
|
|
|
|
|
87
|
8 |
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* {@inheritdoc} |
|
91
|
|
|
*/ |
|
92
|
10 |
|
protected function handleProcedureOuter(Procedure $procedure) |
|
93
|
|
|
{ |
|
94
|
10 |
|
$this->dispatcher->dispatch(TransferEvents::PRE_PROCEDURE, new Events\PreProcedureEvent($procedure)); |
|
|
|
|
|
|
95
|
|
|
|
|
96
|
10 |
|
parent::handleProcedureOuter($procedure); |
|
97
|
|
|
|
|
98
|
8 |
|
$this->dispatcher->dispatch(TransferEvents::POST_PROCEDURE, new Events\PostProcedureEvent($procedure, $this)); |
|
|
|
|
|
|
99
|
8 |
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* {@inheritdoc} |
|
103
|
|
|
*/ |
|
104
|
8 |
|
protected function handleSource(SourceAdapterInterface $adapter, Request $request) |
|
105
|
|
|
{ |
|
106
|
8 |
|
$this->dispatcher->dispatch(TransferEvents::PRE_ADAPTER_RECEIVE, new Events\PreAdapterReceiveEvent($adapter, $request)); |
|
|
|
|
|
|
107
|
|
|
|
|
108
|
8 |
|
$response = parent::handleSource($adapter, $request); |
|
109
|
|
|
|
|
110
|
7 |
|
$this->dispatcher->dispatch( |
|
111
|
7 |
|
TransferEvents::POST_ADAPTER_RECEIVE, |
|
112
|
7 |
|
new Events\PostAdapterReceiveEvent($adapter, $response, 0.0) |
|
|
|
|
|
|
113
|
7 |
|
); |
|
114
|
|
|
|
|
115
|
7 |
|
return $response; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* {@inheritdoc} |
|
120
|
|
|
*/ |
|
121
|
6 |
|
protected function handleWorker(WorkerInterface $worker, $object, StorageInterface $storage) |
|
122
|
|
|
{ |
|
123
|
6 |
|
$this->dispatcher->dispatch(TransferEvents::PRE_WORKER, new Events\PreWorkerEvent($worker, $object)); |
|
|
|
|
|
|
124
|
|
|
|
|
125
|
6 |
|
$modifiedObject = parent::handleWorker($worker, $object, $storage); |
|
126
|
|
|
|
|
127
|
6 |
|
$this->dispatcher->dispatch(TransferEvents::POST_WORKER, new Events\PostWorkerEvent($worker, $modifiedObject, 0.0)); |
|
|
|
|
|
|
128
|
|
|
|
|
129
|
6 |
|
return $modifiedObject; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* {@inheritdoc} |
|
134
|
|
|
*/ |
|
135
|
6 |
|
protected function handleTarget(TargetAdapterInterface $adapter, Request $request) |
|
136
|
|
|
{ |
|
137
|
6 |
|
$this->dispatcher->dispatch(TransferEvents::PRE_ADAPTER_SEND, new Events\PreAdapterSendEvent($adapter, $request)); |
|
|
|
|
|
|
138
|
|
|
|
|
139
|
6 |
|
$response = parent::handleTarget($adapter, $request); |
|
140
|
|
|
|
|
141
|
5 |
|
$this->dispatcher->dispatch(TransferEvents::POST_ADAPTER_SEND, new Events\PostAdapterSendEvent( |
|
|
|
|
|
|
142
|
6 |
|
$adapter, $request, $response, 0.0 |
|
143
|
5 |
|
)); |
|
144
|
|
|
|
|
145
|
5 |
|
return $response; |
|
146
|
|
|
} |
|
147
|
|
|
} |
|
148
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: