1 | <?php |
||
15 | class Target |
||
16 | { |
||
17 | /** |
||
18 | * @var ImportServiceInterface |
||
19 | */ |
||
20 | protected $importService; |
||
21 | |||
22 | /** |
||
23 | * @var Dispatcher |
||
24 | */ |
||
25 | protected $dispatcher; |
||
26 | |||
27 | /** |
||
28 | * Target constructor. |
||
29 | * |
||
30 | * @param ImportServiceInterface $importService |
||
31 | * @param Dispatcher $dispatcher |
||
32 | */ |
||
33 | 2 | public function __construct(ImportServiceInterface $importService, Dispatcher $dispatcher) |
|
34 | { |
||
35 | 2 | $this->importService = $importService; |
|
36 | 2 | $this->dispatcher = $dispatcher; |
|
37 | 2 | } |
|
38 | |||
39 | /** |
||
40 | * @param TargetInterface $target |
||
41 | * @param mixed $entry |
||
42 | * @param Import $import |
||
43 | * @param int $pointer |
||
44 | * |
||
45 | * @throws \Exception |
||
46 | */ |
||
47 | 2 | public function process(TargetInterface $target, $entry, Import $import, $pointer) |
|
48 | { |
||
49 | try { |
||
50 | 2 | $entry = $this->emitEntrySignal('preProcess', $target->getConfiguration(), $entry); |
|
51 | 2 | $result = $target->processEntry($entry); |
|
52 | 1 | $import->increaseCount($result); |
|
53 | 1 | } catch (\Exception $e) { |
|
54 | 1 | $import->increaseCount(TargetInterface::RESULT_ERROR); |
|
55 | 1 | $this->importService->updateImport($import, $pointer + 1); |
|
56 | 1 | throw $e; |
|
57 | } |
||
58 | 1 | } |
|
59 | |||
60 | /** |
||
61 | * @param string $name |
||
62 | * @param array $configuration |
||
63 | * @param mixed $entry |
||
64 | * |
||
65 | * @return mixed |
||
66 | */ |
||
67 | 2 | protected function emitEntrySignal($name, array $configuration, $entry) |
|
77 | } |
||
78 |