本文整理匯總了PHP中Symfony\Component\OptionsResolver\OptionsResolverInterface::setDefined方法的典型用法代碼示例。如果您正苦於以下問題:PHP OptionsResolverInterface::setDefined方法的具體用法?PHP OptionsResolverInterface::setDefined怎麽用?PHP OptionsResolverInterface::setDefined使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\OptionsResolver\OptionsResolverInterface
的用法示例。
在下文中一共展示了OptionsResolverInterface::setDefined方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: initActionOptions
private function initActionOptions()
{
$this->actionOptionsResolver = new OptionsResolver();
$this->actionOptionsResolver->setRequired(array('route_name'));
$this->actionOptionsResolver->setDefined(array('element'));
$self = $this;
$this->actionOptionsResolver->setDefaults(array('route_name' => function (Options $options) use($self) {
return $self->getDefaultRouteName($options);
}, 'additional_parameters' => array(), 'label' => null));
$this->actionOptionsResolver->setNormalizer('additional_parameters', function (Options $options, $value) use($self) {
return $self->normalizeAdditionalParameters($options, $value);
});
$this->actionOptionsResolver->setAllowedTypes('element', 'string');
$this->actionOptionsResolver->setAllowedTypes('route_name', 'string');
$this->actionOptionsResolver->setAllowedTypes('additional_parameters', 'array');
$this->actionOptionsResolver->setAllowedTypes('label', array('string', 'null'));
}
示例2: setDefaultOptions
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefined('entityName');
$resolver->setRequired('entityName');
$resolver->setAllowedTypes('entityName', 'string');
$resolver->setDefault('invalid_message', function (Options $options) {
return 'This value is not valid. Unable to find ' . $options['entityName'] . ' in the database.';
});
}
示例3: setDefaultOptions
/**
* {@inheritdoc}
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$compound = function (Options $options) {
return $options['widget'] !== 'single_text';
};
// Defaults to the value of "widget"
$dateWidget = function (Options $options) {
return $options['widget'];
};
// Defaults to the value of "widget"
$timeWidget = function (Options $options) {
return $options['widget'];
};
$resolver->setDefaults(array('input' => 'datetime', 'model_timezone' => null, 'view_timezone' => null, 'format' => self::HTML5_FORMAT, 'date_format' => null, 'widget' => null, 'date_widget' => $dateWidget, 'time_widget' => $timeWidget, 'with_minutes' => true, 'with_seconds' => false, 'html5' => true, 'by_reference' => false, 'error_bubbling' => false, 'data_class' => null, 'compound' => $compound));
// Don't add some defaults in order to preserve the defaults
// set in DateType and TimeType
$resolver->setDefined(array('empty_value', 'placeholder', 'years', 'months', 'days', 'hours', 'minutes', 'seconds'));
$resolver->setAllowedValues(array('input' => array('datetime', 'string', 'timestamp', 'array'), 'date_widget' => array(null, 'single_text', 'text', 'choice'), 'time_widget' => array(null, 'single_text', 'text', 'choice'), 'widget' => array(null, 'single_text', 'text', 'choice')));
}