當前位置: 首頁>>代碼示例>>PHP>>正文


PHP OptionsResolver::setAllowedTypes方法代碼示例

本文整理匯總了PHP中Symfony\Component\OptionsResolver\OptionsResolver::setAllowedTypes方法的典型用法代碼示例。如果您正苦於以下問題:PHP OptionsResolver::setAllowedTypes方法的具體用法?PHP OptionsResolver::setAllowedTypes怎麽用?PHP OptionsResolver::setAllowedTypes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Component\OptionsResolver\OptionsResolver的用法示例。


在下文中一共展示了OptionsResolver::setAllowedTypes方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: 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

示例2: configureOptions

 /**
  * {@inheritdoc}
  */
 public function configureOptions(OptionsResolver $optionsResolver)
 {
     $validator = $this->validator;
     $optionsResolver->setDefaults(['validation_groups' => ['Default'], 'constraints' => function (Options $options) use($validator) {
         if (null === $options['model_class'] || null === $options['model_property']) {
             return [];
         }
         // Its possible getting of the Metadata gives an error,
         // but that means the model class was invalid already.
         // Getting a property without metadata will give an empty array
         /** @var ClassMetadata $classMetadata */
         $classMetadata = $validator->getMetadataFor($options['model_class']);
         $propertyMetadata = $classMetadata->getPropertyMetadata($options['model_property']);
         $constraints = [];
         foreach ($propertyMetadata as $metadata) {
             $constraints += $metadata->getConstraints();
         }
         return $constraints;
     }]);
     // BC layer for Symfony 2.7 and 3.0
     if ($optionsResolver instanceof OptionsResolverInterface) {
         $optionsResolver->setAllowedTypes(['constraints' => ['array', 'Symfony\\Component\\Validator\\Constraint'], 'validation_groups' => ['array']]);
     } else {
         $optionsResolver->setAllowedTypes('constraints', ['array', 'Symfony\\Component\\Validator\\Constraint']);
         $optionsResolver->setAllowedTypes('validation_groups', ['array']);
     }
 }
開發者ID:rollerworks,項目名稱:search-symfony-validator,代碼行數:30,代碼來源:FieldTypeValidatorExtension.php

示例3: configureOptionResolver

 /**
  * {@inheritdoc}
  */
 protected static function configureOptionResolver(OptionsResolver $resolver)
 {
     $resolver->setDefaults(['host' => '127.0.0.1', 'port' => '6379', 'scheme' => 'tcp']);
     $resolver->setAllowedTypes('host', ['string']);
     $resolver->setAllowedTypes('port', ['string', 'int']);
     $resolver->setAllowedTypes('scheme', ['string']);
 }
開發者ID:aequasi,項目名稱:adapter-bundle,代碼行數:10,代碼來源:DoctrinePredisFactory.php

示例4: configureOptions

 /**
  * {@inheritdoc}
  */
 public function configureOptions(OptionsResolver $resolver)
 {
     $resolver->setDefaults(['value_glue' => null, 'value_format' => null, 'empty_value' => null]);
     $resolver->setAllowedTypes('value_glue', ['string', 'null']);
     $resolver->setAllowedTypes('value_format', ['string', 'callable', 'null']);
     $resolver->setAllowedTypes('empty_value', ['string', 'array', 'null']);
 }
開發者ID:rollerworks,項目名稱:datagrid,代碼行數:10,代碼來源:TextType.php

示例5: configureOptions

 public function configureOptions(OptionsResolver $resolver)
 {
     $resolver->setRequired(['field', 'form', 'condition']);
     $resolver->setAllowedTypes('field', ElementInterface::class);
     $resolver->setAllowedTypes('form', Form::class);
     $resolver->setAllowedTypes('condition', ConditionInterface::class);
 }
開發者ID:Newman101,項目名稱:WellCommerce,代碼行數:7,代碼來源:AbstractDependency.php

示例6: configureOptions

 /**
  * Configure options
  *
  * @param OptionsResolver $resolver
  * @return void
  */
 protected function configureOptions(OptionsResolver $resolver)
 {
     $resolver->setRequired(['amount']);
     $resolver->setDefined(['currency', 'terminal', 'credit_card_token', 'payment_id']);
     $resolver->setAllowedTypes('credit_card_token', 'string');
     $resolver->setAllowedTypes('payment_id', 'string');
     $resolver->setNormalizer('currency', function (Options $options, $value) {
         if (!isset($options['payment_id'])) {
             $fields = ['terminal', 'credit_card_token', 'currency'];
             foreach ($fields as $field) {
                 if (!isset($options[$field])) {
                     throw new \InvalidArgumentException(sprintf('The fields "%s" is required', implode(', ', $fields)));
                 }
             }
         }
         return $value;
     });
     $resolver->setNormalizer('payment_id', function (Options $options, $value) {
         $fields = ['currency', 'terminal', 'credit_card_token'];
         foreach ($fields as $field) {
             if (isset($options[$field])) {
                 throw new \InvalidArgumentException(sprintf('The fields "%s" is not allowed when "payment_id" is set', implode(', ', $fields)));
             }
         }
         return $value;
     });
 }
開發者ID:lsv,項目名稱:altapay-php-api,代碼行數:33,代碼來源:CalculateSurcharge.php

示例7: configureOptions

 public function configureOptions(OptionsResolver $resolver)
 {
     $resolver->setDefaults(['label' => false, 'name' => '', 'data_class' => 'RZ\\Roadiz\\Core\\Entities\\Folder', 'attr' => ['class' => 'uk-form folder-form']]);
     $resolver->setRequired(['em']);
     $resolver->setAllowedTypes('em', 'Doctrine\\Common\\Persistence\\ObjectManager');
     $resolver->setAllowedTypes('name', 'string');
 }
開發者ID:QuangDang212,項目名稱:roadiz,代碼行數:7,代碼來源:FolderType.php

示例8: configureOptions

 /**
  * {@inheritdoc}
  */
 public function configureOptions(OptionsResolver $resolver)
 {
     $resolver->setRequired(['column_transformers', 'cache']);
     $resolver->setDefaults(['column_transformers' => new ColumnTransformerCollection(), 'cache' => true]);
     $resolver->setAllowedTypes('column_transformers', ColumnTransformerCollection::class);
     $resolver->setAllowedTypes('cache', 'bool');
 }
開發者ID:wellcommerce,項目名稱:wellcommerce,代碼行數:10,代碼來源:AbstractDataSetContext.php

示例9: configureOptions

 public function configureOptions(OptionsResolver $resolver)
 {
     $resolver->setDefaults(['compound' => true, 'label' => false, 'nodeName' => null, 'attr' => ['class' => 'uk-form transtype-form']]);
     $resolver->setRequired(['em', 'currentType']);
     $resolver->setAllowedTypes('em', 'Doctrine\\Common\\Persistence\\ObjectManager');
     $resolver->setAllowedTypes('currentType', 'RZ\\Roadiz\\Core\\Entities\\NodeType');
 }
開發者ID:QuangDang212,項目名稱:roadiz,代碼行數:7,代碼來源:TranstypeType.php

示例10: configureOptions

 /**
  * Option configuration.
  *
  * @param OptionsResolver $resolver
  */
 private function configureOptions(OptionsResolver $resolver)
 {
     $resolver->setDefault('url', 'https://news.google.com/news?cf=all&hl=en&ned=us&topic=t&output=rss');
     $resolver->setAllowedTypes('url', array('string'));
     $resolver->setRequired(array('location_id'));
     $resolver->setAllowedTypes('location_id', array('int'));
 }
開發者ID:htollefsen,項目名稱:examples,代碼行數:12,代碼來源:GoogleNewsToEzPlatformContentManifest.php

示例11: configureOptions

 /**
  * {@inheritdoc}
  */
 public function configureOptions(OptionsResolver $resolver)
 {
     $resolver->setDefaults(['controller_body' => null, 'angular_modules' => [], 'angular_services' => ['$scope']]);
     $resolver->setAllowedTypes('controller_body', ['null', 'string']);
     $resolver->setAllowedTypes('angular_modules', ['array']);
     $resolver->setAllowedTypes('angular_services', ['array']);
 }
開發者ID:ynloultratech,項目名稱:framework,代碼行數:10,代碼來源:AngularControllerType.php

示例12: configureOptions

 /**
  * {@inheritdoc}
  */
 public function configureOptions(OptionsResolver $resolver)
 {
     $resolver->setRequired(['route', 'group_action']);
     $resolver->setDefaults(['route' => false, 'group_action' => false]);
     $resolver->setAllowedTypes('route', ['bool', 'string']);
     $resolver->setAllowedTypes('group_action', ['bool', 'string']);
 }
開發者ID:wellcommerce,項目名稱:wellcommerce,代碼行數:10,代碼來源:DeleteGroupEventHandler.php

示例13: configureOptions

 /**
  * Configure options
  *
  * @param OptionsResolver $resolver
  *
  * @throws \Symfony\Component\OptionsResolver\Exception\ExceptionInterface
  */
 public function configureOptions(OptionsResolver $resolver)
 {
     $resolver->setDefaults(['name' => null, 'label' => null, 'entity' => null]);
     $resolver->setAllowedTypes('name', 'string');
     $resolver->setAllowedTypes('label', ['string', 'null']);
     $resolver->setAllowedTypes('entity', 'string');
 }
開發者ID:sunnyct,項目名稱:silexcmf-rest,代碼行數:14,代碼來源:RestController.php

示例14: configureWeekMealOptions

 /**
  * Set up the configurations of options
  * passed as argument into the following methods of this class :
  * - getWeekDates
  * - getWeekMeals
  */
 private function configureWeekMealOptions()
 {
     $this->weekMealResolver->setDefined(array('date_day', 'without_pork', 'enable_next_week', 'days_ofweek_off', 'dates_off'));
     $this->weekMealResolver->setAllowedTypes('date_day', \DateTimeInterface::class);
     $this->weekMealResolver->setDefaults(array('without_pork' => false, 'enable_next_week' => false, 'days_ofweek_off' => array(Day::WEEK_WEDNESDAY), 'dates_off' => array()));
     $this->weekMealResolver->setRequired(array('without_pork', 'date_day'));
 }
開發者ID:WildCodeSchool,項目名稱:projet-gesty,代碼行數:13,代碼來源:LunchRepository.php

示例15: configureOptions

 public function configureOptions(OptionsResolver $options)
 {
     $options->setDefaults(['field_options' => []]);
     $options->setRequired(['field_type']);
     $options->setAllowedTypes('field_type', ['string']);
     $options->setAllowedTypes('field_options', ['array']);
 }
開發者ID:symfony-cmf,項目名稱:content-type,代碼行數:7,代碼來源:CollectionType.php


注:本文中的Symfony\Component\OptionsResolver\OptionsResolver::setAllowedTypes方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。