1 | <?php |
||
22 | abstract class BaseWorker implements WorkerInterface |
||
23 | { |
||
24 | |||
25 | /** |
||
26 | * Processor factory instance. |
||
27 | * |
||
28 | * @var ProcessorFactoryInterface |
||
29 | */ |
||
30 | protected $processorFactory; |
||
31 | |||
32 | /** |
||
33 | * Logger instance. |
||
34 | * |
||
35 | * @var LoggerInterface |
||
36 | */ |
||
37 | protected $logger; |
||
38 | |||
39 | /** |
||
40 | * Serializer. |
||
41 | * |
||
42 | * @var SerializerInterface |
||
43 | */ |
||
44 | protected $serializer; |
||
45 | |||
46 | /** |
||
47 | * Class constructor. |
||
48 | * |
||
49 | * @param ProcessorFactoryInterface $processorFactory Command processor factory. |
||
50 | * @param SerializerInterface $serializer Serializer. |
||
51 | * @param LoggerInterface $logger Logger. |
||
52 | */ |
||
53 | 4 | public function __construct(ProcessorFactoryInterface $processorFactory, SerializerInterface $serializer, LoggerInterface $logger = null) |
|
59 | |||
60 | /** |
||
61 | * |
||
62 | * @param mixed $commandData |
||
63 | * @return void |
||
64 | * |
||
65 | * @throws UnserializeErrorException Thrown, when translation process resulted in an error. |
||
66 | * @throws ProcessorNotFoundException Thrown, when processor for given command has not been found. |
||
67 | * @throws ProcessorErrorException Thrown, when processor resulted in an error. |
||
68 | */ |
||
69 | 4 | public function process($commandData) |
|
84 | |||
85 | /** |
||
86 | * {@inheritdoc} |
||
87 | */ |
||
88 | 3 | public function getProcessor(CommandInterface $command) |
|
94 | |||
95 | /** |
||
96 | * {@inheritdoc} |
||
97 | */ |
||
98 | 1 | public function setProcessorFactory(ProcessorFactoryInterface $processorFactory) |
|
102 | |||
103 | /** |
||
104 | * Get serialized command data to use with translator. |
||
105 | * |
||
106 | * @param mixed $commandData |
||
107 | * @return SerializedCommandData |
||
108 | * |
||
109 | * @throws UnserializeErrorException Thrown, when data could not have been translated to serialized command data. |
||
110 | */ |
||
111 | abstract protected function getSerializedCommandData($commandData); |
||
112 | |||
113 | /** |
||
114 | * Hook called before command translation. |
||
115 | * |
||
116 | * @param string $commandData |
||
117 | * @return void |
||
118 | * |
||
119 | * @codeCoverageIgnore |
||
120 | */ |
||
121 | protected function beforeTranslateHook(&$commandData) |
||
124 | |||
125 | /** |
||
126 | * Hook called before getting processor for command. |
||
127 | * |
||
128 | * @param CommandInterface $command |
||
129 | * @return void |
||
130 | * |
||
131 | * @codeCoverageIgnore |
||
132 | */ |
||
133 | protected function beforeGetProcessorHook(CommandInterface $command) |
||
136 | |||
137 | /** |
||
138 | * Hook called before processing command. |
||
139 | * |
||
140 | * @param CommandInterface $command |
||
141 | * @return void |
||
142 | * |
||
143 | * @codeCoverageIgnore |
||
144 | */ |
||
145 | protected function beforeProcessHook(CommandInterface $command, CommandProcessorInterface $processor) |
||
148 | |||
149 | /** |
||
150 | * Hook called after successfull processing of command. |
||
151 | * |
||
152 | * @param CommandInterface $command |
||
153 | * @param CommandProcessorInterface $processor |
||
154 | * @return void |
||
155 | * |
||
156 | * @codeCoverageIgnore |
||
157 | */ |
||
158 | protected function afterProcessHook(CommandInterface $command, CommandProcessorInterface $processor) |
||
161 | |||
162 | /** |
||
163 | * Hook called after successfull processing of command. |
||
164 | * |
||
165 | * @param CommandInterface $command |
||
166 | * @param CommandProcessorInterface $processor |
||
167 | * @param Exception $e Exception thrown by processor. |
||
168 | * @return void |
||
169 | * |
||
170 | * @codeCoverageIgnore |
||
171 | */ |
||
172 | protected function processorErrorHook(CommandInterface $command, CommandProcessorInterface $processor, Exception $e) |
||
175 | } |
||
176 |