1 | <?php |
||
42 | abstract class AbstractSagaManager implements SagaManagerInterface, LoggerAwareInterface |
||
43 | { |
||
44 | |||
45 | /** |
||
46 | * @var SagaRepositoryInterface |
||
47 | */ |
||
48 | private $sagaRepository; |
||
49 | |||
50 | /** |
||
51 | * @var SagaFactoryInterface |
||
52 | */ |
||
53 | private $sagaFactory; |
||
54 | |||
55 | /** |
||
56 | * @var array |
||
57 | */ |
||
58 | private $sagaTypes = []; |
||
59 | |||
60 | /** |
||
61 | * @var boolean |
||
62 | */ |
||
63 | private $suppressExceptions = true; |
||
64 | |||
65 | /** |
||
66 | * @var LoggerInterface |
||
67 | */ |
||
68 | private $logger; |
||
69 | |||
70 | /** |
||
71 | * @var CorrelationDataProviderInterface |
||
72 | */ |
||
73 | private $correlationDataProvider; |
||
74 | |||
75 | /** |
||
76 | * @param SagaRepositoryInterface $sagaRepository |
||
77 | * @param SagaFactoryInterface $sagaFactory |
||
78 | * @param array $sagaTypes |
||
79 | */ |
||
80 | 18 | public function __construct( |
|
91 | |||
92 | /** |
||
93 | * {@inheritdoc} |
||
94 | */ |
||
95 | 18 | public function handle(EventMessageInterface $event) |
|
126 | |||
127 | 9 | private function containsAny( |
|
139 | |||
140 | 11 | private function startNewSaga( |
|
155 | |||
156 | 16 | private function invokeExistingSagas( |
|
179 | |||
180 | 9 | private function loadAndInvoke( |
|
226 | |||
227 | 11 | private function doInvokeSaga( |
|
238 | |||
239 | 2 | private function handleInvokationException( |
|
257 | |||
258 | /** |
||
259 | * Commits the given <code>saga</code> to the registered repository. |
||
260 | * |
||
261 | * @param SagaInterface $saga the Saga to commit. |
||
262 | */ |
||
263 | 9 | protected function commit(SagaInterface $saga) |
|
267 | |||
268 | /** |
||
269 | * Perform pre-processing of sagas that have been newly created or have been loaded from the repository. This |
||
270 | * method is invoked prior to invocation of the saga instance itself. |
||
271 | * |
||
272 | * @param SagaInterface $saga The saga instance for preprocessing |
||
273 | */ |
||
274 | 3 | protected function preProcessSaga(SagaInterface $saga) |
|
278 | |||
279 | /** |
||
280 | * Returns the Saga Initialization Policy for a Saga of the given <code>sagaType</code> and <code>event</code>. |
||
281 | * This policy provides the conditions to create new Saga instance, as well as the initial association of that |
||
282 | * saga. |
||
283 | * |
||
284 | * @param string $sagaType The type of Saga to get the creation policy for |
||
285 | * @param EventMessageInterface $event The Event that is being dispatched to Saga instances |
||
286 | * @return SagaInitializationPolicy the initialization policy for the Saga |
||
287 | */ |
||
288 | abstract protected function getSagaCreationPolicy( |
||
292 | |||
293 | /** |
||
294 | * Extracts the AssociationValues from the given <code>event</code> as relevant for a Saga of given |
||
295 | * <code>sagaType</code>. A single event may be associated with multiple values. |
||
296 | * |
||
297 | * @param string $sagaType The type of Saga about to handle the Event |
||
298 | * @param EventMessageInterface $event The event containing the association information |
||
299 | * @return array the AssociationValues indicating which Sagas should handle given event |
||
300 | */ |
||
301 | abstract protected function extractAssociationValues( |
||
305 | |||
306 | /** |
||
307 | * Sets whether or not to suppress any exceptions that are cause by invoking Sagas. When suppressed, exceptions are |
||
308 | * logged. Defaults to <code>true</code>. |
||
309 | * |
||
310 | * @param boolean $suppressExceptions whether or not to suppress exceptions from Sagas. |
||
311 | */ |
||
312 | 6 | public function setSuppressExceptions($suppressExceptions) |
|
316 | |||
317 | |||
318 | /** |
||
319 | * @param LoggerInterface $logger |
||
320 | * @return null |
||
321 | */ |
||
322 | 3 | public function setLogger(LoggerInterface $logger) |
|
326 | |||
327 | /** |
||
328 | * @return array |
||
329 | */ |
||
330 | public function getManagedSagaTypes() |
||
334 | |||
335 | /** |
||
336 | * Sets the correlation data provider for this SagaManager. It will provide the data to attach to messages sent by |
||
337 | * Sagas managed by this manager. |
||
338 | * |
||
339 | * @param CorrelationDataProviderInterface $correlationDataProvider the correlation data provider for this SagaManager |
||
340 | */ |
||
341 | 1 | public function setCorrelationDataProvider(CorrelationDataProviderInterface $correlationDataProvider) |
|
345 | |||
346 | /** |
||
347 | * Sets the given <code>correlationDataProviders</code>. Each will provide data to attach to messages sent by Sagas |
||
348 | * managed by this manager. When multiple providers provide different values for the same key, the latter provider |
||
349 | * will overwrite any values set earlier. |
||
350 | * |
||
351 | * @param array $correlationDataProviders the correlation data providers for this SagaManager |
||
352 | */ |
||
353 | 1 | public function setCorrelationDataProviders(array $correlationDataProviders) |
|
357 | |||
358 | } |
||
359 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: