private function createEmailQuestion(OutputInterface $output) { return (new Question('E-mail:'))->setValidator(function ($value) use($output) { /** @var ConstraintViolationListInterface $errors */ $errors = $this->get('validator')->validate((string) $value, [new Email(), new NotBlank()]); foreach ($errors as $error) { throw new \DomainException($error->getMessage()); } return $value; })->setMaxAttempts(3); }