public function create(UseCase $useCase, $tagParameters) { try { /** @var UseCase $useCase */ $methodAnnotations = $this->reader->getMethodAnnotations(new \ReflectionMethod($useCase, 'execute')); /** @var UseCaseProxyBuilder $builder */ $this->builder->create($useCase)->withReader($this->reader); foreach ($methodAnnotations as $annotation) { if ($annotation instanceof SecurityAnnotation) { $this->builder->withSecurity($this->buildSecurity($tagParameters)); } if ($annotation instanceof CacheAnnotation) { $this->builder->withCache($this->buildCache($tagParameters)); } if ($annotation instanceof TransactionAnnotation) { $this->builder->withTransaction($this->buildTransaction($tagParameters)); } if ($annotation instanceof EventAnnotation) { $this->builder->withEventSender($this->buildEvent($tagParameters))->withEventFactory($this->buildEventFactory($tagParameters)); } } return $this->builder->build(); } catch (SecurityIsNotDefinedException $sinde) { throw new SecurityIsNotDefinedException('Security should be defined for use case: ' . get_class($useCase) . '. ' . $sinde->getMessage()); } catch (CacheIsNotDefinedException $cinde) { throw new CacheIsNotDefinedException('Cache should be defined for use case: ' . get_class($useCase) . '. ' . $cinde->getMessage()); } catch (TransactionIsNotDefinedException $tinde) { throw new TransactionIsNotDefinedException('Transaction should be defined for use case: ' . get_class($useCase) . '. ' . $tinde->getMessage()); } catch (EventIsNotDefinedException $einde) { throw new EventIsNotDefinedException('EventSender should be defined for use case: ' . get_class($useCase) . '. ' . $einde->getMessage()); } catch (EventFactoryIsNotDefinedException $efinde) { throw new EventFactoryIsNotDefinedException('EventFactory should be defined for use case: ' . get_class($useCase) . '. ' . $efinde->getMessage()); } }