本文整理汇总了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');
}
示例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']);
}
}
示例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']);
}
示例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']);
}
示例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);
}
示例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;
});
}
示例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');
}
示例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');
}
示例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');
}
示例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'));
}
示例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']);
}
示例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']);
}
示例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');
}
示例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'));
}
示例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']);
}