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


PHP OptionsResolver::addAllowedValues方法代码示例

本文整理汇总了PHP中Symfony\Component\OptionsResolver\OptionsResolver::addAllowedValues方法的典型用法代码示例。如果您正苦于以下问题:PHP OptionsResolver::addAllowedValues方法的具体用法?PHP OptionsResolver::addAllowedValues怎么用?PHP OptionsResolver::addAllowedValues使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\OptionsResolver\OptionsResolver的用法示例。


在下文中一共展示了OptionsResolver::addAllowedValues方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __construct

 /**
  * @param array $options
  */
 public function __construct(array $options = array())
 {
     $resolver = new OptionsResolver();
     $resolver->setDefaults(array('schema' => 'https', 'ip' => '127.0.0.1', 'port' => 8089, 'timeout' => 10, 'requestNamespace' => __NAMESPACE__ . '\\Request\\', 'curl_debug' => false, 'taximasterDateTimeFormat' => 'YmdHis'));
     $resolver->addAllowedValues(array('schema' => array('http', 'https')));
     $resolver->setRequired(array('secret_key', 'ip', 'port', 'requestNamespace'));
     $this->options = $resolver->resolve($options);
 }
开发者ID:it2k,项目名称:tmapi,代码行数:11,代码来源:Manager.php

示例2: testResolveSucceedsIfOptionValueAllowed2

 public function testResolveSucceedsIfOptionValueAllowed2()
 {
     $this->resolver->setDefaults(array('one' => '1', 'two' => '2'));
     $this->resolver->addAllowedValues(array('one' => array('1'), 'two' => array('2')));
     $this->resolver->addAllowedValues(array('one' => array('one'), 'two' => array('two')));
     $options = array('one' => '1', 'two' => 'two');
     $this->assertEquals(array('one' => '1', 'two' => 'two'), $this->resolver->resolve($options));
 }
开发者ID:nashadalam,项目名称:symfony,代码行数:8,代码来源:OptionResolverTest.php

示例3: getConfigurableOptions

 /**
  * @return OptionsResolver
  */
 public function getConfigurableOptions()
 {
     $resolver = new OptionsResolver();
     $resolver->setDefaults(array('directory' => 'features', 'align' => null));
     $resolver->addAllowedTypes('directory', array('string'));
     $resolver->addAllowedTypes('align', array('null', 'string'));
     $resolver->addAllowedValues('align', array(null, 'left', 'right'));
     return $resolver;
 }
开发者ID:Big-Shark,项目名称:grumphp,代码行数:12,代码来源:Gherkin.php

示例4: testResolveSucceedsIfAnyAddedClosureReturnsTrue2

 public function testResolveSucceedsIfAnyAddedClosureReturnsTrue2()
 {
     $this->resolver->setDefault('foo', 'bar');
     $this->resolver->setAllowedValues('foo', function () {
         return true;
     });
     $this->resolver->addAllowedValues('foo', function () {
         return false;
     });
     $this->assertEquals(array('foo' => 'bar'), $this->resolver->resolve());
 }
开发者ID:BusinessCookies,项目名称:CoffeeMachineProject,代码行数:11,代码来源:OptionsResolver2Dot6Test.php

示例5: setAllowedValues

 private function setAllowedValues()
 {
     $this->resolver->addAllowedValues(CO::DESTINATION, function ($destination) {
         return $this->allowedValuesForDestination($destination);
     });
     $this->resolver->addAllowedValues(CO::SOURCE, function ($source) {
         return $this->allowedValuesForSource($source);
     });
     $this->resolver->addAllowedValues(CO::TEMPLATE_CONFIG, function ($value) {
         if ($value && !is_file($value)) {
             throw new ConfigurationException("Template config '{$value}' was not found");
         }
         return TRUE;
     });
 }
开发者ID:nunodotferreira,项目名称:ApiGen,代码行数:15,代码来源:ConfigurationOptionsResolver.php

示例6: createNamedBuilder

 /**
  * Returns a form builder.
  *
  * @param string|FormTypeInterface  $type       The type of the form
  * @param string                    $name       The name of the form
  * @param mixed                     $data       The initial data
  * @param array                     $options    The options
  * @param FormBuilder               $parent     The parent builder
  *
  * @return FormBuilder The form builder
  *
  * @throws FormException if any given option is not applicable to the given type
  */
 public function createNamedBuilder($type, $name, $data = null, array $options = array(), FormBuilder $parent = null)
 {
     if (!array_key_exists('data', $options)) {
         $options['data'] = $data;
     }
     $builder = null;
     $types = array();
     $optionValues = array();
     $knownOptions = array();
     $optionsResolver = new OptionsResolver();
     // Bottom-up determination of the type hierarchy
     // Start with the actual type and look for the parent type
     // The complete hierarchy is saved in $types, the first entry being
     // the root and the last entry being the leaf (the concrete type)
     while (null !== $type) {
         if ($type instanceof FormTypeInterface) {
             if ($type->getName() == $type->getParent($options)) {
                 throw new FormException(sprintf('The form type name "%s" for class "%s" cannot be the same as the parent type.', $type->getName(), get_class($type)));
             }
             $this->addType($type);
         } elseif (is_string($type)) {
             $type = $this->getType($type);
         } else {
             throw new UnexpectedTypeException($type, 'string or Symfony\\Component\\Form\\FormTypeInterface');
         }
         array_unshift($types, $type);
         // getParent() cannot see default options set by this type nor
         // default options set by parent types
         // As a result, the options always have to be checked for
         // existence with isset() before using them in this method.
         $type = $type->getParent($options);
     }
     // Top-down determination of the default options
     foreach ($types as $type) {
         // Merge the default options of all types to an array of default
         // options. Default options of children override default options
         // of parents.
         $typeOptions = $type->getDefaultOptions();
         $optionsResolver->setDefaults($typeOptions);
         $optionsResolver->addAllowedValues($type->getAllowedOptionValues());
         $knownOptions = array_merge($knownOptions, array_keys($typeOptions));
         foreach ($type->getExtensions() as $typeExtension) {
             $extensionOptions = $typeExtension->getDefaultOptions();
             $optionsResolver->setDefaults($extensionOptions);
             $optionsResolver->addAllowedValues($typeExtension->getAllowedOptionValues());
             $knownOptions = array_merge($knownOptions, array_keys($extensionOptions));
         }
     }
     // Resolve concrete type
     $type = end($types);
     // Validate options required by the factory
     $diff = array_diff(self::$requiredOptions, $knownOptions);
     if (count($diff) > 0) {
         throw new TypeDefinitionException(sprintf('Type "%s" should support the option(s) "%s"', $type->getName(), implode('", "', $diff)));
     }
     // Resolve options
     $options = $optionsResolver->resolve($options);
     for ($i = 0, $l = count($types); $i < $l && !$builder; ++$i) {
         $builder = $types[$i]->createBuilder($name, $this, $options);
     }
     if (!$builder) {
         throw new TypeDefinitionException(sprintf('Type "%s" or any of its parents should return a FormBuilder instance from createBuilder()', $type->getName()));
     }
     $builder->setTypes($types);
     $builder->setCurrentLoadingType($type->getName());
     $builder->setParent($parent);
     foreach ($types as $type) {
         $type->buildForm($builder, $options);
         foreach ($type->getExtensions() as $typeExtension) {
             $typeExtension->buildForm($builder, $options);
         }
     }
     $builder->setCurrentLoadingType(null);
     return $builder;
 }
开发者ID:rikaix,项目名称:symfony,代码行数:88,代码来源:FormFactory.php

示例7: configureOptions

 /**
  * {@inheritdoc}
  */
 public function configureOptions(OptionsResolver $resolver)
 {
     $resolver->setDefaults(array('model_manager' => null, 'class' => null, 'required' => false, 'provider_name' => false, 'context' => false, 'admin_code' => 'sonata.media.admin.media', 'error_bubbling' => false, 'compound' => false));
     $resolver->setRequired(array('class'));
     $resolver->addAllowedValues(array('required' => array(false)));
 }
开发者ID:rapemer,项目名称:init-cms-bundle,代码行数:9,代码来源:MediaEntityType.php

示例8: configureOptions

 /**
  * {@inheritdoc}
  */
 public function configureOptions(OptionsResolver $resolver)
 {
     $resolver->setDefaults(array('password_required' => false, 'data_class' => 'Kunstmaan\\AdminBundle\\Entity\\User', 'langs' => null, 'can_edit_all_fields' => null));
     $resolver->addAllowedValues('password_required', array(true, false));
 }
开发者ID:bakie,项目名称:KunstmaanBundlesCMS,代码行数:8,代码来源:UserType.php

示例9: configureOptions

 public function configureOptions(OptionsResolver $resolver)
 {
     $resolver->setDefaults(['widget' => 'dual_text', 'first_name' => 'dialcode', 'first_options' => [], 'second_name' => 'dialnumber', 'second_options' => [], 'leading_sign' => '+', 'separator_sign' => '/']);
     $resolver->addAllowedValues('widget', ['single_text', 'dual_text', 'choice_text']);
 }
开发者ID:barachenadia,项目名称:Formation-Symfony-Hugo-Hamon,代码行数:5,代码来源:PhoneNumberType.php

示例10: configureOptions

 /**
  * {@inheritdoc}
  */
 public function configureOptions(OptionsResolver $resolver)
 {
     $resolver->setDefaults(array('password_required' => false, 'data_class' => 'Kunstmaan\\AdminBundle\\Entity\\User'));
     $resolver->addAllowedValues(array('password_required' => array(true, false)));
 }
开发者ID:axelvnk,项目名称:KunstmaanBundlesCMS,代码行数:8,代码来源:UserType.php

示例11: __construct

 /**
  * Конструктор
  * @param array $options
  */
 public function __construct(array $options = array())
 {
     $resolver = new OptionsResolver();
     $resolver->setDefaults(array('schema' => 'https', 'ip' => '127.0.0.1', 'port' => 8089, 'timeout' => 10, 'curl_debug' => false));
     $resolver->addAllowedValues(array('schema' => array('http', 'https')));
     $resolver->setRequired(array('secret_key', 'ip', 'port'));
     $this->options = $resolver->resolve($options);
     if (!$this->responseClass) {
         $className = $this->get_class_name();
         $this->responseClass = 'BaseResponse';
         if (class_exists(self::ROOT_NAMESPACE . '\\Response\\' . $className)) {
             $this->responseClass = $className;
         }
     }
 }
开发者ID:it2k,项目名称:tmapi,代码行数:19,代码来源:BaseRequest.php


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