/** * Informs the display about the structure of a Field. * * Each time the Field structure changes for some reason, this method shall * be called. * * @param \Feeld\Display\DisplayDataSourceInterface $field * @throws Exception */ public function informAboutStructure(\Feeld\Display\DisplayDataSourceInterface $field) { parent::informAboutStructure($field); $this->field = $field; if ($field instanceof \Feeld\Field\Entry) { $this->symfonyQuestion = new SymfonyQuestion((string) $this, $field instanceof DefaultValueInterface && $field->hasDefault() ? $field->getDefault() : null); } elseif ($field instanceof \Feeld\Field\Select) { $this->symfonyQuestion = new \Symfony\Component\Console\Question\ChoiceQuestion((string) $this, array_keys($field->getOptions()), $field instanceof DefaultValueInterface && $field->hasDefault() ? $field->getDefault() : null); if ($field instanceof \Feeld\Field\CommonProperties\MultipleChoiceInterface && $field->isMultipleChoice()) { $field->symfonyQuestion->setMultiselect(true); } } elseif ($field instanceof \Feeld\Field\CloakedEntry) { $this->symfonyQuestion = new SymfonyQuestion((string) $this, $field instanceof DefaultValueInterface && $field->hasDefault() ? $field->getDefault() : null); $this->symfonyQuestion->setHidden(true); } elseif ($field instanceof \Feeld\Field\Constant) { throw new Exception('Constants are currently not supported in SymfonyConsoleDisplay'); } elseif ($field instanceof \Feeld\Field\Checkbox) { $this->symfonyQuestion = new \Symfony\Component\Console\Question\ConfirmationQuestion((string) $this, $field instanceof DefaultValueInterface && $field->hasDefault() ? $field->getDefault() : true, '/^' . strtolower(substr($this->getTrueOption(), 0, 1)) . '/i'); } $this->symfonyQuestion->setNormalizer(function ($value) { return $this->field->getSanitizer()->filter($value); }); $this->symfonyQuestion->setValidator(function ($value) { $validationResultSet = $this->field->validateValue($value); if ($validationResultSet->hasErrors()) { $this->field->clearValidationResult(); throw new \Exception(implode(PHP_EOL, $validationResultSet->getErrorMessages())); } return $this->field->getFilteredValue(); }); $this->symfonyQuestion->setMaxAttempts(null); }