本文整理汇总了PHP中Symfony\Component\OptionsResolver\OptionsResolverInterface::setFilters方法的典型用法代码示例。如果您正苦于以下问题:PHP OptionsResolverInterface::setFilters方法的具体用法?PHP OptionsResolverInterface::setFilters怎么用?PHP OptionsResolverInterface::setFilters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\OptionsResolver\OptionsResolverInterface
的用法示例。
在下文中一共展示了OptionsResolverInterface::setFilters方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setDefaultOptions
/**
* {@inheritdoc}
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$optionsFilter = function (Options $options, $value) {
$value['block_name'] = 'entry';
return $value;
};
$resolver->setDefaults(array('allow_add' => false, 'allow_delete' => false, 'prototype' => true, 'prototype_name' => '__name__', 'type' => 'text', 'options' => array()));
$resolver->setFilters(array('options' => $optionsFilter));
}
示例2: setDefaultOptions
/**
* {@inheritdoc}
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
// BC clause
$constraints = function (Options $options) {
return $options['validation_constraint'];
};
// Make sure that validation groups end up as null, closure or array
$validationGroupsFilter = function (Options $options, $groups) {
if (empty($groups)) {
return null;
}
if (is_callable($groups)) {
return $groups;
}
return (array) $groups;
};
// Constraint should always be converted to an array
$constraintsFilter = function (Options $options, $constraints) {
return is_object($constraints) ? array($constraints) : (array) $constraints;
};
$resolver->setDefaults(array('error_mapping' => array(), 'validation_groups' => null, 'validation_constraint' => null, 'constraints' => $constraints, 'cascade_validation' => false, 'invalid_message' => 'This value is not valid.', 'extra_fields_message' => 'This form should not contain extra fields.', 'post_max_size_message' => 'The uploaded file was too large. Please try to upload a smaller file.'));
$resolver->setFilters(array('validation_groups' => $validationGroupsFilter, 'constraints' => $constraintsFilter));
}
示例3: setDefaultOptions
/**
* {@inheritdoc}
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$choiceListCache =& $this->choiceListCache;
$choiceList = function (Options $options) use(&$choiceListCache) {
// Harden against NULL values (like in EntityType and ModelType)
$choices = null !== $options['choices'] ? $options['choices'] : array();
// Reuse existing choice lists in order to increase performance
$hash = md5(json_encode(array($choices, $options['preferred_choices'])));
if (!isset($choiceListCache[$hash])) {
$choiceListCache[$hash] = new SimpleChoiceList($choices, $options['preferred_choices']);
}
return $choiceListCache[$hash];
};
$emptyData = function (Options $options) {
if ($options['multiple'] || $options['expanded']) {
return array();
}
return '';
};
$emptyValue = function (Options $options) {
return $options['required'] ? null : '';
};
$emptyValueFilter = function (Options $options, $emptyValue) {
if ($options['multiple'] || $options['expanded']) {
// never use an empty value for these cases
return null;
} elseif (false === $emptyValue) {
// an empty value should be added but the user decided otherwise
return null;
}
// empty value has been set explicitly
return $emptyValue;
};
$compound = function (Options $options) {
return $options['expanded'];
};
$resolver->setDefaults(array('multiple' => false, 'expanded' => false, 'choice_list' => $choiceList, 'choices' => array(), 'preferred_choices' => array(), 'empty_data' => $emptyData, 'empty_value' => $emptyValue, 'error_bubbling' => false, 'compound' => $compound));
$resolver->setFilters(array('empty_value' => $emptyValueFilter));
$resolver->setAllowedTypes(array('choice_list' => array('null', 'Symfony\\Component\\Form\\Extension\\Core\\ChoiceList\\ChoiceListInterface')));
}
示例4: setDefaultOptions
/**
* {@inheritdoc}
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$compound = function (Options $options) {
return $options['widget'] !== 'single_text';
};
$emptyValue = $emptyValueDefault = function (Options $options) {
return $options['required'] ? null : '';
};
$emptyValueFilter = function (Options $options, $emptyValue) use($emptyValueDefault) {
if (is_array($emptyValue)) {
$default = $emptyValueDefault($options);
return array_merge(array('hour' => $default, 'minute' => $default, 'second' => $default), $emptyValue);
}
return array('hour' => $emptyValue, 'minute' => $emptyValue, 'second' => $emptyValue);
};
// BC until Symfony 2.3
$modelTimezone = function (Options $options) {
return $options['data_timezone'];
};
// BC until Symfony 2.3
$viewTimezone = function (Options $options) {
return $options['user_timezone'];
};
$resolver->setDefaults(array('hours' => range(0, 23), 'minutes' => range(0, 59), 'seconds' => range(0, 59), 'widget' => 'choice', 'input' => 'datetime', 'with_seconds' => false, 'model_timezone' => $modelTimezone, 'view_timezone' => $viewTimezone, 'data_timezone' => null, 'user_timezone' => null, 'empty_value' => $emptyValue, 'by_reference' => false, 'error_bubbling' => false, 'data_class' => null, 'compound' => $compound));
$resolver->setFilters(array('empty_value' => $emptyValueFilter));
$resolver->setAllowedValues(array('input' => array('datetime', 'string', 'timestamp', 'array'), 'widget' => array('single_text', 'text', 'choice')));
}
示例5: setDefaultOptions
/**
* {@inheritdoc}
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$compound = function (Options $options) {
return $options['widget'] !== 'single_text';
};
$emptyValue = $emptyValueDefault = function (Options $options) {
return $options['required'] ? null : '';
};
$emptyValueFilter = function (Options $options, $emptyValue) use($emptyValueDefault) {
if (is_array($emptyValue)) {
$default = $emptyValueDefault($options);
return array_merge(array('year' => $default, 'month' => $default, 'day' => $default), $emptyValue);
}
return array('year' => $emptyValue, 'month' => $emptyValue, 'day' => $emptyValue);
};
$resolver->setDefaults(array('years' => range(date('Y') - 5, date('Y') + 5), 'months' => range(1, 12), 'days' => range(1, 31), 'widget' => 'choice', 'input' => 'datetime', 'format' => self::DEFAULT_FORMAT, 'data_timezone' => null, 'user_timezone' => null, 'empty_value' => $emptyValue, 'by_reference' => false, 'error_bubbling' => false, 'data_class' => null, 'compound' => $compound));
$resolver->setFilters(array('empty_value' => $emptyValueFilter));
$resolver->setAllowedValues(array('input' => array('datetime', 'string', 'timestamp', 'array'), 'widget' => array('single_text', 'text', 'choice')));
}
示例6: setDefaultOptions
/**
* {@inheritdoc}
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$compound = function (Options $options) {
return $options['widget'] !== 'single_text';
};
$emptyValueFilter = function (Options $options, $emptyValue) {
if (is_array($emptyValue)) {
return array_merge(array('hour' => null, 'minute' => null, 'second' => null), $emptyValue);
}
return array('hour' => $emptyValue, 'minute' => $emptyValue, 'second' => $emptyValue);
};
$resolver->setDefaults(array('hours' => range(0, 23), 'minutes' => range(0, 59), 'seconds' => range(0, 59), 'widget' => 'choice', 'input' => 'datetime', 'with_seconds' => false, 'data_timezone' => null, 'user_timezone' => null, 'empty_value' => null, 'by_reference' => false, 'error_bubbling' => false, 'data_class' => null, 'compound' => $compound));
$resolver->setFilters(array('empty_value' => $emptyValueFilter));
$resolver->setAllowedValues(array('input' => array('datetime', 'string', 'timestamp', 'array'), 'widget' => array('single_text', 'text', 'choice')));
}
示例7: setDefaultOptions
/**
* {@inheritdoc}
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$choiceList = function (Options $options) {
return new SimpleChoiceList(null !== $options['choices'] ? $options['choices'] : array(), $options['preferred_choices']);
};
$emptyData = function (Options $options) {
if ($options['multiple'] || $options['expanded']) {
return array();
}
return '';
};
$emptyValue = function (Options $options) {
return $options['required'] ? null : '';
};
$emptyValueFilter = function (Options $options, $emptyValue) {
if ($options['multiple'] || $options['expanded']) {
// never use an empty value for these cases
return null;
} elseif (false === $emptyValue) {
// an empty value should be added but the user decided otherwise
return null;
}
// empty value has been set explicitly
return $emptyValue;
};
$compound = function (Options $options) {
return $options['expanded'];
};
$resolver->setDefaults(array('multiple' => false, 'expanded' => false, 'choice_list' => $choiceList, 'choices' => array(), 'preferred_choices' => array(), 'empty_data' => $emptyData, 'empty_value' => $emptyValue, 'error_bubbling' => false, 'compound' => $compound));
$resolver->setFilters(array('empty_value' => $emptyValueFilter));
$resolver->setAllowedTypes(array('choice_list' => array('null', 'Symfony\\Component\\Form\\Extension\\Core\\ChoiceList\\ChoiceListInterface')));
}