private function getPasswordQuestionValidator(OutputInterface $output) { return function ($value) use($output) { /** @var ConstraintViolationListInterface $errors */ $errors = $this->get('validator')->validate($value, [new NotBlank()]); foreach ($errors as $error) { throw new \DomainException($error->getMessage()); } return $value; }; }