private function getAnnotatedTargetValue($annotationName, CommandMessageInterface $command, AnnotationReader $reader, \ReflectionClass $reflClass) { foreach (ReflectionUtils::getProperties($reflClass) as $property) { if (null !== ($annot = $reader->getPropertyAnnotation($property, $annotationName))) { $property->setAccessible(true); return $property->getValue($command->getPayload()); } } foreach (ReflectionUtils::getMethods($reflClass) as $method) { if (null !== ($annot = $reader->getMethodAnnotation($method, $annotationName))) { $method->setAccessible(true); return $method->invoke($command->getPayload()); } } return null; }
private function doHandle(CommandMessageInterface $command) { $violations = $this->validator->validate($command->getPayload()); if (0 !== $violations->count()) { throw new ValidatorException("One or more constraints were violated.", $violations); } return $command; }
public function dispatch(CommandMessageInterface $command, CommandCallbackInterface $callback = null) { $this->dispatchedCommands[] = $command; try { if (null !== $callback) { $callback->onSuccess($this->callbackBehavior->handle($command->getPayload(), $command->getMetaData())); } } catch (\Exception $ex) { if (null !== $callback) { $callback->onFailure($ex); } } }
/** * {@inheritdoc} */ protected function doResolveRoutingKey(CommandMessageInterface $command) { $reflectionClass = new \ReflectionClass($command->getPayload()); return $this->findIdentifier($command, $reflectionClass); }
public function handle(CommandMessageInterface $commandMessage, UnitOfWorkInterface $unitOfWork) { $command = $commandMessage->getPayload(); switch ($commandMessage->getPayloadType()) { case 'CommandHandlerExample\\CreateUserCommand': $aggregate = new User($command->getIdentifier(), $command->getEmail()); $this->repository->add($aggregate); break; case 'CommandHandlerExample\\ChangeUserEmailCommand': $aggregate = $this->repository->load($command->getIdentifier()); $aggregate->changeEmail($command->getEmail()); break; } }