本文整理汇总了PHP中Symfony\Component\OptionsResolver\OptionsResolver::setNormalizer方法的典型用法代码示例。如果您正苦于以下问题:PHP OptionsResolver::setNormalizer方法的具体用法?PHP OptionsResolver::setNormalizer怎么用?PHP OptionsResolver::setNormalizer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\OptionsResolver\OptionsResolver
的用法示例。
在下文中一共展示了OptionsResolver::setNormalizer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: configureOptions
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$defaultFieldOptions = ['multiple' => true];
$resolver->setDefaults(['enum_code' => null, 'class' => null, 'field_options' => $defaultFieldOptions, 'operator_choices' => [self::TYPE_IN => $this->translator->trans('oro.filter.form.label_type_in'), self::TYPE_NOT_IN => $this->translator->trans('oro.filter.form.label_type_not_in')]]);
$resolver->setNormalizer('class', function (Options $options, $value) {
if ($value !== null) {
return $value;
}
if (empty($options['enum_code'])) {
throw new InvalidOptionsException('Either "class" or "enum_code" must option must be set.');
}
$class = ExtendHelper::buildEnumValueClassName($options['enum_code']);
if (!is_a($class, 'Oro\\Bundle\\EntityExtendBundle\\Entity\\AbstractEnumValue', true)) {
throw new InvalidOptionsException(sprintf('"%s" must be a child of "%s"', $class, 'Oro\\Bundle\\EntityExtendBundle\\Entity\\AbstractEnumValue'));
}
return $class;
});
// this normalizer allows to add/override field_options options outside
$resolver->setNormalizer('field_options', function (Options $options, $value) use(&$defaultFieldOptions) {
if (isset($options['class'])) {
$nullValue = null;
if ($options->offsetExists('null_value')) {
$nullValue = $options->offsetGet('null_value');
}
$value['choices'] = $this->getChoices($options['class'], $nullValue);
} else {
$value['choices'] = [];
}
return array_merge($defaultFieldOptions, $value);
});
}
示例2: configureOptions
/**
* @param OptionsResolver $resolver
*/
protected function configureOptions(OptionsResolver $resolver)
{
$resolver->setRequired(['fields', 'associations', 'callbacks']);
$fieldsNormalizer = function (Options $options, $fields) {
$collection = new Collection\FieldMetadataCollection();
$factory = new FieldMetadataFactory();
foreach ($fields as $fieldName => $parameters) {
$fieldMetadata = $factory->create($fieldName, $parameters);
$collection->add($fieldMetadata);
}
return $collection;
};
$associationsNormalizer = function (Options $options, $associations) {
$collection = new Collection\AssociationMetadataCollection();
$factory = new AssociationMetadataFactory();
foreach ($associations as $associationName => $parameters) {
$associationMetadata = $factory->create($associationName, $parameters);
$collection->add($associationMetadata);
}
return $collection;
};
$resolver->setNormalizer('fields', $fieldsNormalizer);
$resolver->setNormalizer('associations', $associationsNormalizer);
$resolver->setDefaults(['fields' => new Collection\FieldMetadataCollection(), 'associations' => new Collection\AssociationMetadataCollection(), 'callbacks' => []]);
$resolver->setAllowedTypes('fields', ['array', Collection\FieldMetadataCollection::class]);
$resolver->setAllowedTypes('associations', ['array', Collection\AssociationMetadataCollection::class]);
$resolver->setAllowedTypes('callbacks', 'array');
}
示例3: configureOptions
/**
* @param OptionsResolver $resolver
* @throws AccessException
* @throws UndefinedOptionsException
* @throws MissingFamilyException
* @throws \UnexpectedValueException
* @throws ConstraintDefinitionException
* @throws InvalidOptionsException
* @throws MissingOptionsException
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(['required' => true, 'constraints' => new NotBlank()]);
$resolver->setRequired(['attribute', 'parent_data']);
$resolver->setNormalizer('attribute', function (Options $options, $value) {
return VariantType::normalizeVariantAttribute($value);
});
$resolver->setNormalizer('parent_data', function (Options $options, $value) {
return VariantType::normalizeParentData($options, $value);
});
$resolver->setNormalizer('choices', function (Options $options, $value) {
$attribute = $options['attribute'];
$families = [];
/** @var array $variantFamilies */
$variantFamilies = $attribute->getOptions()['variant_families'];
foreach ($variantFamilies as $familyCode) {
$family = $this->familyConfigurationHandler->getFamily($familyCode);
if (!$family instanceof VariantFamily) {
throw new \UnexpectedValueException("Variant families in attribute options must be of type VariantFamily, '{$family->getCode()}' is not a variant");
}
$families[ucfirst($family)] = $family;
}
return $families;
});
}
示例4: configureOptions
private function configureOptions(OptionsResolver $resolver)
{
$resolver->setRequired(['alias', 'source', 'aggregated', 'paginator_source']);
$resolver->setDefaults(['aggregated' => false, 'paginator_source' => '']);
$resolver->setNormalizer('aggregated', function (Options $options) {
return $this->isAggregateColumn($options['source'], ['SUM', 'GROUP_CONCAT', 'MIN', 'MAX', 'AVG', 'COUNT']);
});
$resolver->setNormalizer('paginator_source', function (Options $options) {
return $this->normalizePaginatorSource($options);
});
}
示例5: __construct
public function __construct(array $options)
{
$math = new NativeMath();
$resolver = new OptionsResolver();
$dimensionsNormalizer = new DimensionsNormalizer($math);
$resolver->setDefined(['extra_data'])->setDefaults(['currency' => 'USD', 'math' => $math, 'weight_converter' => new WeightConverter($math), 'length_converter' => new LengthConverter($math), 'girth_calculator' => new UspsGirthCalculator($math, $dimensionsNormalizer), 'dimensions_normalizer' => $dimensionsNormalizer, 'extra_data' => null])->setRequired(['export_countries', 'import_countries', 'zone_calculators', 'currency', 'fuel_subcharge', 'math', 'weight_converter', 'length_converter', 'mass_unit', 'dimensions_unit', 'maximum_girth', 'maximum_dimension'])->setAllowedTypes(['export_countries' => 'array', 'import_countries' => 'array', 'zone_calculators' => 'array', 'currency' => 'string', 'math' => MathInterface::class, 'weight_converter' => UnitConverterInterface::class, 'length_converter' => UnitConverterInterface::class, 'girth_calculator' => UspsGirthCalculator::class, 'dimensions_normalizer' => DimensionsNormalizer::class]);
$resolver->setNormalizer('import_countries', $this->createImportCountriesNormalizer());
$resolver->setNormalizer('export_countries', $this->createExportCountriesNormalizer());
$resolver->setNormalizer('zone_calculators', $this->createZoneCalculatorsNormalizer());
$this->options = $resolver->resolve($options);
}
示例6: configureOptions
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$defaults = array('image_url' => null, 'widget_type' => $this->widgetType, 'widget_width' => '100px', 'widget_height' => '100px', 'select_label' => 'Select image', 'change_label' => 'Change', 'remove_label' => 'Remove');
$ajaxDefaults = array('total_class' => null, 'total_id' => null, 'total_property' => null, 'parent_class' => null, 'parent_id' => null, 'parent_property' => null);
$resolver->setDefaults(array('zkFileSettings' => $defaults, 'zkAjaxSettings' => $ajaxDefaults));
$resolver->setNormalizer('zkFileSettings', function (Options $options, $configs) use($defaults) {
return array_merge($defaults, $configs);
});
$resolver->setNormalizer('zkAjaxSettings', function (Options $options, $configs) use($ajaxDefaults) {
return array_merge($ajaxDefaults, $configs);
});
}
示例7: __construct
public function __construct(array $options)
{
$math = new NativeMath();
$resolver = new OptionsResolver();
$weightConverter = new WeightConverter($math);
$lengthConverter = new LengthConverter($math);
$dimensionsNormalizer = new DimensionsNormalizer($math);
$resolver->setDefined(['extra_data'])->setDefaults(['currency' => 'USD', 'math' => $math, 'weight_converter' => $weightConverter, 'length_converter' => $lengthConverter, 'perimeter_calculator' => new MaximumPerimeterCalculator($math, $dimensionsNormalizer), 'volumetric_weight_calculator' => new IParcelVolumetricWeightCalculator($math, $weightConverter, $lengthConverter), 'dimensions_normalizer' => $dimensionsNormalizer, 'extra_data' => null])->setRequired(['export_countries', 'import_countries', 'zones', 'currency', 'math', 'weight_converter', 'length_converter', 'mass_unit', 'dimensions_unit', 'maximum_perimeter', 'maximum_dimension', 'maximum_weight'])->setAllowedTypes(['export_countries' => 'array', 'import_countries' => 'array', 'zones' => 'array', 'currency' => 'string', 'math' => MathInterface::class, 'weight_converter' => UnitConverterInterface::class, 'length_converter' => UnitConverterInterface::class, 'perimeter_calculator' => MaximumPerimeterCalculator::class, 'volumetric_weight_calculator' => IParcelVolumetricWeightCalculator::class, 'dimensions_normalizer' => DimensionsNormalizer::class]);
$resolver->setNormalizer('import_countries', $this->createImportCountriesNormalizer());
$resolver->setNormalizer('export_countries', $this->createExportCountriesNormalizer());
$resolver->setNormalizer('zones', $this->createZonesNormalizer());
$this->options = $resolver->resolve($options);
}
示例8: __construct
public function __construct(array $options)
{
$math = new NativeMath();
$resolver = new OptionsResolver();
$weightConverter = new WeightConverter($math);
$lengthConverter = new LengthConverter($math);
$resolver->setDefined(['extra_data'])->setDefaults(['currency' => 'USD', 'math' => $math, 'weight_converter' => $weightConverter, 'length_converter' => $lengthConverter, 'volumetric_weight_calculator' => new DhlVolumetricWeightCalculator($math, $weightConverter, $lengthConverter), 'dimensions_normalizer' => new DimensionsNormalizer($math), 'extra_data' => null])->setRequired(['export_countries', 'import_countries', 'zone_calculators', 'currency', 'math', 'weight_converter', 'length_converter', 'mass_unit', 'dimensions_unit', 'maximum_weight', 'maximum_dimensions'])->setAllowedTypes(['export_countries' => 'array', 'import_countries' => 'array', 'zone_calculators' => 'array', 'currency' => 'string', 'math' => 'Moriony\\Trivial\\Math\\MathInterface', 'weight_converter' => 'Moriony\\Trivial\\Converter\\UnitConverterInterface', 'length_converter' => 'Moriony\\Trivial\\Converter\\UnitConverterInterface', 'volumetric_weight_calculator' => 'EsteIt\\ShippingCalculator\\VolumetricWeightCalculator\\DhlVolumetricWeightCalculator', 'dimensions_normalizer' => 'EsteIt\\ShippingCalculator\\Tool\\DimensionsNormalizer']);
$resolver->setNormalizer('import_countries', $this->createImportCountriesNormalizer());
$resolver->setNormalizer('export_countries', $this->createExportCountriesNormalizer());
$resolver->setNormalizer('zone_calculators', $this->createZoneCalculatorsNormalizer());
$resolver->setNormalizer('maximum_dimensions', $this->createDimensionsNormalizer());
$this->options = $resolver->resolve($options);
}
示例9: configureOptions
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(['id_property' => 'id', 'manager' => null, 'limit' => 20, 'search' => [], 'property' => 'name']);
$resolver->setNormalizer('search', function (Options $options, $value) {
if (empty($value) && !empty($options['property'])) {
$value = [$options['property'] => self::SEARCH_MIDDLE];
}
return $value;
});
$resolver->setRequired(['class']);
$resolver->setNormalizer('manager', function (Options $options, $manager) {
return $this->normalize($options, $manager);
});
}
示例10: configureOptions
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array('operator' => true, 'sort' => true, 'type' => null, 'value_options' => array()));
$resolver->setAllowedTypes('value_options', 'array');
$resolver->setNormalizer('type', function (Options $options, $value) {
if ($options['operator'] == true && $value === null) {
throw new MissingOptionsException(sprintf('The required option "type" is missing.'));
}
return $value;
});
$resolver->setNormalizer('value_options', function (Options $options, $value) {
return array_merge(array('required' => false), $value);
});
}
示例11: configureOptions
public function configureOptions(OptionsResolver $resolver)
{
$manager = $this->manager;
$resolver->setNormalizer('query_builder', function (Options $options, $value) use($manager) {
return $manager->getRepository('EnhavoCategoryBundle:Category')->getByCollectionQuery($options['category_name']);
});
$resolver->setDefaults(array('expanded' => true, 'multiple' => true, 'class' => $this->dataClass, 'category_name' => $this->categoryDefaultCollection, 'translation_domain' => 'EnhavoCategoryBundle'));
$resolver->setNormalizer('label', function (Options $options, $value) {
if ($options['multiple']) {
return 'category.label.categories';
}
return 'category.label.category';
});
}
示例12: setNormalizers
private function setNormalizers()
{
$this->resolver->setNormalizer(TCO::TEMPLATES, function (Options $options, $value) {
return $this->makeTemplatePathsAbsolute($value, $options);
});
$this->resolver->setNormalizer(TCO::RESOURCES, function (Options $options, $resources) {
$absolutizedResources = [];
foreach ($resources as $key => $resource) {
$key = $options['templatesPath'] . '/' . $key;
$absolutizedResources[$key] = $resource;
}
return $absolutizedResources;
});
}
示例13: __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));
$this->specResolver->setAllowedTypes('on', array('string', 'array'));
$this->specResolver->setAllowedTypes('from', array('string', 'array'));
$this->specResolver->setAllowedTypes('to', array('string', 'array'));
$toArrayNormalizer = function (Options $options, $value) {
return (array) $value;
};
$this->specResolver->setNormalizer('on', $toArrayNormalizer);
$this->specResolver->setNormalizer('from', $toArrayNormalizer);
$this->specResolver->setNormalizer('to', $toArrayNormalizer);
}
示例14: configurePayload
/**
* @inheritdoc
*/
public function configurePayload(OptionsResolver $resolver)
{
$resolver->setRequired(0);
$resolver->setAllowedTypes(0, 'numeric');
$resolver->setNormalizer(0, function (Options $options, $value) {
if (null === ($listing = $this->scheduler->findFeed($value))) {
throw new InvalidArgumentException(sprintf('Feed with id "%d" does not exist', $value));
}
return $listing;
});
$resolver->setDefaults([1 => false]);
$resolver->setNormalizer(1, function (Options $options, $value) {
return (bool) $value;
});
}
示例15: configureOptions
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$entryOptionsNormalizer = function (Options $options, $value) {
$value['block_name'] = 'entry';
return $value;
};
$optionsNormalizer = function (Options $options, $value) use($entryOptionsNormalizer) {
if (null !== $value) {
@trigger_error('The form option "options" is deprecated since version 2.8 and will be removed in 3.0. Use "entry_options" instead.', E_USER_DEPRECATED);
}
return $entryOptionsNormalizer($options, $value);
};
$typeNormalizer = function (Options $options, $value) {
if (null !== $value) {
@trigger_error('The form option "type" is deprecated since version 2.8 and will be removed in 3.0. Use "entry_type" instead.', E_USER_DEPRECATED);
}
};
$entryType = function (Options $options) {
if (null !== $options['type']) {
return $options['type'];
}
return __NAMESPACE__ . '\\TextType';
};
$entryOptions = function (Options $options) {
if (1 === count($options['options']) && isset($options['block_name'])) {
return array();
}
return $options['options'];
};
$resolver->setDefaults(array('allow_add' => false, 'allow_delete' => false, 'prototype' => true, 'prototype_data' => null, 'prototype_name' => '__name__', 'type' => null, 'options' => null, 'entry_type' => $entryType, 'entry_options' => $entryOptions, 'delete_empty' => false));
$resolver->setNormalizer('options', $optionsNormalizer);
$resolver->setNormalizer('entry_options', $entryOptionsNormalizer);
}