1 | <?php |
||
21 | abstract class BaseWorker implements WorkerInterface |
||
22 | { |
||
23 | |||
24 | /** |
||
25 | * Processor factory instance. |
||
26 | * |
||
27 | * @var ProcessorFactoryInterface |
||
28 | */ |
||
29 | private $processorFactory; |
||
30 | |||
31 | /** |
||
32 | * Logger instance. |
||
33 | * |
||
34 | * @var LoggerInterface |
||
35 | */ |
||
36 | private $logger; |
||
37 | |||
38 | /** |
||
39 | * Class constructor. |
||
40 | * |
||
41 | * @param ProcessorFactoryInterface $processorFactory |
||
42 | * @param LoggerInterface $logger Logger instance. |
||
43 | */ |
||
44 | 4 | public function __construct(ProcessorFactoryInterface $processorFactory, LoggerInterface $logger = null) |
|
49 | |||
50 | /** |
||
51 | * |
||
52 | * @param mixed $commandData |
||
53 | * @return void |
||
54 | * |
||
55 | * @throws TranslateErrorException Thrown, when translation process resulted in an error. |
||
56 | * @throws ProcessorNotFoundException Thrown, when processor for given command has not been found. |
||
57 | * @throws ProcessorErrorException Thrown, when processor resulted in an error. |
||
58 | */ |
||
59 | 4 | public function process($commandData) |
|
77 | |||
78 | /** |
||
79 | * {@inheritdoc} |
||
80 | */ |
||
81 | 3 | public function getProcessor(CommandInterface $command) |
|
87 | |||
88 | /** |
||
89 | * {@inheritdoc} |
||
90 | */ |
||
91 | 1 | public function setProcessorFactory(ProcessorFactoryInterface $processorFactory) |
|
92 | { |
||
93 | 1 | $this->processorFactory = $processorFactory; |
|
94 | 1 | } |
|
95 | |||
96 | /** |
||
97 | * Get command from command data. |
||
98 | * |
||
99 | * @param mixed $commandData |
||
100 | * |
||
101 | * @return CommandInterface |
||
102 | * @throws \Exception Thrown, when translation has been unsuccessfull. |
||
103 | */ |
||
104 | abstract protected function translateCommand($commandData); |
||
105 | |||
106 | /** |
||
107 | * Hook called before command translation. |
||
108 | * |
||
109 | * @param string $commandData |
||
110 | * @return void |
||
111 | * |
||
112 | * @codeCoverageIgnore |
||
113 | */ |
||
114 | protected function beforeTranslateHook(&$commandData) |
||
117 | |||
118 | /** |
||
119 | * Hook called before getting processor for command. |
||
120 | * |
||
121 | * @param CommandInterface $command |
||
122 | * @return void |
||
123 | * |
||
124 | * @codeCoverageIgnore |
||
125 | */ |
||
126 | protected function beforeGetProcessorHook(CommandInterface $command) |
||
129 | |||
130 | /** |
||
131 | * Hook called before processing command. |
||
132 | * |
||
133 | * @param CommandInterface $command |
||
134 | * @return void |
||
135 | * |
||
136 | * @codeCoverageIgnore |
||
137 | */ |
||
138 | protected function beforeProcessHook(CommandInterface $command, CommandProcessorInterface $processor) |
||
141 | |||
142 | /** |
||
143 | * Hook called after successfull processing of command. |
||
144 | * |
||
145 | * @param CommandInterface $command |
||
146 | * @param CommandProcessorInterface $processor |
||
147 | * @return void |
||
148 | * |
||
149 | * @codeCoverageIgnore |
||
150 | */ |
||
151 | protected function afterProcessHook(CommandInterface $command, CommandProcessorInterface $processor) |
||
154 | } |
||
155 |