当前位置: 首页>>代码示例>>PHP>>正文


PHP OptionsResolver::setNormalizer方法代码示例

本文整理汇总了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);
     });
 }
开发者ID:snorchel,项目名称:platform,代码行数:34,代码来源:EnumFilterType.php

示例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');
 }
开发者ID:WellCommerce,项目名称:ApiBundle,代码行数:31,代码来源:SerializationClassMetadata.php

示例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;
     });
 }
开发者ID:VincentChalnot,项目名称:SidusEAVVariantBundle,代码行数:35,代码来源:VariantFamilySelectorType.php

示例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);
     });
 }
开发者ID:wellcommerce,项目名称:dataset,代码行数:11,代码来源:Column.php

示例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);
 }
开发者ID:esteit,项目名称:shipping-calculator,代码行数:11,代码来源:AsendiaHandler.php

示例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);
     });
 }
开发者ID:zk2,项目名称:useful-bundle,代码行数:15,代码来源:ZkFileTypeAbstract.php

示例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);
 }
开发者ID:esteit,项目名称:shipping-calculator,代码行数:13,代码来源:IParcelHandler.php

示例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);
 }
开发者ID:sektor-sumy,项目名称:shipping-calculator,代码行数:13,代码来源:DhlCalculatorHandler.php

示例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);
     });
 }
开发者ID:sirian,项目名称:suggest-bundle,代码行数:14,代码来源:DoctrineSuggester.php

示例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);
     });
 }
开发者ID:WedgeSama,项目名称:Listor,代码行数:17,代码来源:BaseType.php

示例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';
     });
 }
开发者ID:enhavo,项目名称:enhavo,代码行数:14,代码来源:CategoryEntityType.php

示例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;
     });
 }
开发者ID:nunodotferreira,项目名称:ApiGen,代码行数:14,代码来源:ThemeConfigOptionsResolver.php

示例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);
 }
开发者ID:Rioji,项目名称:Finite,代码行数:18,代码来源:CallbackHandler.php

示例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;
     });
 }
开发者ID:treehouselabs,项目名称:io-bundle,代码行数:18,代码来源:ImportScheduleExecutor.php

示例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);
 }
开发者ID:hungtrinh7,项目名称:symfony,代码行数:36,代码来源:CollectionType.php


注:本文中的Symfony\Component\OptionsResolver\OptionsResolver::setNormalizer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。