本文整理汇总了PHP中Symfony\Component\OptionsResolver\OptionsResolverInterface::setNormalizer方法的典型用法代码示例。如果您正苦于以下问题:PHP OptionsResolverInterface::setNormalizer方法的具体用法?PHP OptionsResolverInterface::setNormalizer怎么用?PHP OptionsResolverInterface::setNormalizer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\OptionsResolver\OptionsResolverInterface
的用法示例。
在下文中一共展示了OptionsResolverInterface::setNormalizer方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: __construct
/**
* @param EventDispatcherInterface $dispatcher
*/
public function __construct(EventDispatcherInterface $dispatcher)
{
$this->dispatcher = $dispatcher;
$this->specResolver = new OptionsResolver();
$this->specResolver->setDefaults(array('on' => self::ALL, 'from' => self::ALL, 'to' => self::ALL, 'exclude_from' => array(), 'exclude_to' => array()));
$this->specResolver->setAllowedTypes('on', ['string', 'array']);
$this->specResolver->setAllowedTypes('from', ['string', 'array']);
$this->specResolver->setAllowedTypes('to', ['string', 'array']);
$this->specResolver->setAllowedTypes('exclude_from', ['string', 'array']);
$this->specResolver->setAllowedTypes('exclude_to', ['string', 'array']);
$toArrayNormalizer = function (Options $options, $value) {
return (array) $value;
};
foreach (['on', 'from', 'to', 'exclude_to', 'exclude_from'] as $value) {
$this->specResolver->setNormalizer($value, $toArrayNormalizer);
}
}
示例3: setDefaultOptions
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array('on' => 'on', 'off' => 'off'));
$resolver->setNormalizer('attr', function ($options, $value) {
$value["class"] = "switch-input";
if (array_key_exists("class", $value)) {
$value["class"] .= " " . $value["class"];
}
return $value;
});
}
示例4: setDefaultOptions
/**
* {@inheritdoc}
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$optionsNormalizer = function (Options $options, $value) {
$value['block_name'] = 'entry';
return $value;
};
$resolver->setDefaults(['allow_add' => false, 'allow_delete' => false, 'prototype' => true, 'prototype_name' => '__name__', 'type_name' => '_type', 'options' => []]);
$resolver->setRequired(['types']);
$resolver->setAllowedTypes(['types' => 'array']);
$resolver->setNormalizer('empty_value', $emptyValueNormalizer);
}