本文整理汇总了PHP中Symfony\Component\OptionsResolver\OptionsResolver类的典型用法代码示例。如果您正苦于以下问题:PHP OptionsResolver类的具体用法?PHP OptionsResolver怎么用?PHP OptionsResolver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OptionsResolver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createOptionsResolver
/**
* @return OptionsResolverInterface
*/
protected function createOptionsResolver()
{
$resolver = new OptionsResolver();
$resolver->setOptional(['flush', 'copy_values_to_products', 'add_products', 'remove_products']);
$resolver->setAllowedTypes(['flush' => 'bool', 'copy_values_to_products' => 'bool', 'add_products' => 'array', 'remove_products' => 'array']);
return $resolver;
}
示例2: configureOptions
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
/* Note: the form's intention must correspond to that for the form login
* listener in order for the CSRF token to validate successfully.
*/
$resolver->setDefaults(array('intention' => 'authenticate'));
}
示例3: configureOptionResolver
/**
* {@inheritdoc}
*/
protected static function configureOptionResolver(OptionsResolver $resolver)
{
$resolver->setDefaults(['host' => '127.0.0.1', 'port' => 11211, 'redundant_servers' => []]);
$resolver->setAllowedTypes('host', ['string']);
$resolver->setAllowedTypes('port', ['string', 'int']);
$resolver->setAllowedTypes('redundant_servers', ['array']);
}
示例4:
function it_should_define_assigned_data_class(OptionsResolver $resolver)
{
$resolver->setDefaults(['data_class' => 'Rule', 'validation_groups' => ['Default']])->shouldBeCalled();
$resolver->setDefined(['configuration_type'])->shouldBeCalled();
$resolver->setDefaults(['configuration_type' => RuleInterface::TYPE_ITEM_TOTAL])->shouldBeCalled();
$this->configureOptions($resolver);
}
示例5: setDefaultOptions
/**
* {@inheritdoc}
*/
public function setDefaultOptions(OptionsResolver $resolver)
{
$resolver->setRequired(['new_relic_app_name']);
$resolver->setDefaults(['new_relic_license' => null, 'new_relic_transaction_name' => function (Options $options) {
return sprintf('swarrot %s', $options['queue']);
}]);
}
示例6: configureOptions
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array('type' => 'text', 'options' => array(), 'first_options' => array(), 'second_options' => array(), 'first_name' => 'first', 'second_name' => 'second', 'error_bubbling' => false));
$resolver->setAllowedTypes('options', 'array');
$resolver->setAllowedTypes('first_options', 'array');
$resolver->setAllowedTypes('second_options', 'array');
}
示例7: configureOptions
/**
* @param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver)
{
$user = $this->tokenStorage->getToken()->getUser();
$resolver->setDefaults(array('data_class' => Task::class, 'empty_data' => function (FormInterface $form) use($user) {
return new Task($form->getData()['name'], $user);
}));
}
示例8: __construct
/**
* When creating this subscriber, you can configure a number of options.
*
* - refresh_client_matcher: RequestMatcher to identify valid refresh clients.
* - refresh_client_ips: IP or array of IPs that are allowed to refresh.
*
* Only set one of refresh_client_ips and refresh_client_matcher.
*
* @param array $options Options to overwrite the default options
*
* @throws \InvalidArgumentException if unknown keys are found in $options
*/
public function __construct(array $options = [])
{
$resolver = new OptionsResolver();
$resolver->setDefaults(['refresh_client_matcher' => null, 'refresh_client_ips' => null]);
$options = $resolver->resolve($options);
parent::__construct($options['refresh_client_matcher'], $options['refresh_client_ips']);
}
示例9: setCurrencyResolver
/**
* Resolve amount option
*
* @param OptionsResolver $resolver
*/
protected function setCurrencyResolver(OptionsResolver $resolver)
{
$resolver->setAllowedTypes('currency', ['string', 'int']);
$resolver->setAllowedValues('currency', function ($value) {
return CurrencyTypes::currencyCodeExists($value) || CurrencyTypes::currencyNumberExists($value);
});
}
示例10: 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']);
}
示例11: __construct
/**
* @param array $options
*/
public function __construct(array $options)
{
$resolver = new OptionsResolver();
$resolver->setRequired(['secret', 'currency', 'min_sum'])->setDefaults(['math' => new NativeMath(), 'currency' => 'usd', 'min_sum' => 0])->setAllowedTypes('math', MathInterface::class);
$options = $resolver->resolve($options);
$this->options = $options;
}
示例12: configureOptions
/**
*
* @param array $options
* @return array
*/
public function configureOptions(array $options = array())
{
$resolver = new OptionsResolver();
$resolver->setDefaults(array('adapter' => 'default', 'host' => $this->getHost(), 'username' => null, 'password' => null, 'port' => $this->getPort(), 'auth_mode' => $this->getAuthMode(), 'encryption' => $this->getEncryption()));
$this->options = $resolver->resolve($options);
return $this->options;
}
示例13: resolveConfigurationOptions
/**
* Resolves options
*
* @param array $options
* @return array
*/
protected function resolveConfigurationOptions(array $configurationOptions)
{
$optionsResolver = new OptionsResolver();
$optionsResolver->setDefaults($this->defaultOptions);
$optionsResolver->setRequired(array_keys($this->defaultOptions));
return $optionsResolver->resolve($configurationOptions);
}
示例14: 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);
}
return $value;
};
$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('type', $typeNormalizer);
$resolver->setNormalizer('options', $optionsNormalizer);
$resolver->setNormalizer('entry_options', $entryOptionsNormalizer);
}
示例15: configureOptions
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setRequired(['roles']);
$resolver->setDefaults(['csrf_protection' => false, 'data_class' => InviteUserCommand::class, 'empty_data' => function (FormInterface $form) {
return new InviteUserCommand($form->get('email')->getData(), $this->roles);
}]);
}