本文整理汇总了PHP中Symfony\Component\Console\Question\Question::setNormalizer方法的典型用法代码示例。如果您正苦于以下问题:PHP Question::setNormalizer方法的具体用法?PHP Question::setNormalizer怎么用?PHP Question::setNormalizer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Console\Question\Question
的用法示例。
在下文中一共展示了Question::setNormalizer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: informAboutStructure
/**
* 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);
}