本文整理汇总了PHP中Symfony\Component\OptionsResolver\OptionsResolver::setOptional方法的典型用法代码示例。如果您正苦于以下问题:PHP OptionsResolver::setOptional方法的具体用法?PHP OptionsResolver::setOptional怎么用?PHP OptionsResolver::setOptional使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\OptionsResolver\OptionsResolver
的用法示例。
在下文中一共展示了OptionsResolver::setOptional方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update
/**
* @param ProductInterface $product
* @param array $updates
*
* @return bool
*/
protected function update(ProductInterface $product, array $updates)
{
$resolver = new OptionsResolver();
$resolver->setRequired(['type']);
$resolver->setAllowedValues(['type' => ['set_data', 'copy_data', 'add_data', 'remove_data']]);
$resolver->setOptional(['field', 'data', 'locale', 'scope', 'from_field', 'to_field', 'from_locale', 'to_locale', 'from_scope', 'to_scope']);
$resolver->setDefaults(['locale' => null, 'scope' => null, 'from_locale' => null, 'to_locale' => null, 'from_scope' => null, 'to_scope' => null]);
foreach ($updates as $update) {
$update = $resolver->resolve($update);
switch ($update['type']) {
case 'set_data':
$this->applySetData($product, $update);
break;
case 'copy_data':
$this->applyCopyData($product, $update);
break;
case 'add_data':
$this->applyAddData($product, $update);
break;
case 'remove_data':
$this->applyRemoveData($product, $update);
break;
}
}
}
示例2: 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;
}
示例3: createOptionsResolver
/**
* @return OptionsResolverInterface
*/
protected function createOptionsResolver()
{
$resolver = new OptionsResolver();
$resolver->setOptional(['flush', 'schedule']);
$resolver->setAllowedTypes(['flush' => 'bool', 'schedule' => 'bool']);
return $resolver;
}
示例4: createOptionsResolver
/**
* @return OptionsResolverInterface
*/
protected function createOptionsResolver()
{
$resolver = new OptionsResolver();
$resolver->setOptional(['flush']);
$resolver->setAllowedTypes(['flush' => 'bool']);
$resolver->setDefaults(['flush' => true]);
return $resolver;
}
示例5: __construct
public function __construct(array $options = [])
{
$resolver = new OptionsResolver();
$resolver->setOptional($this->getOptionalOptions());
$resolver->setAllowedTypes($this->getAllowedOptionTypes());
$resolver->setDefaults($this->getDefaultOptions());
$this->options = $resolver->resolve($options);
}
示例6: getTagitOptions
/**
* Resolves tag-it options.
* See {@link https://github.com/aehlke/tag-it}
*
* @param FormInterface $form
*/
protected function getTagitOptions(FormInterface $form)
{
$resolver = new OptionsResolver();
$resolver->setOptional(array('availableTags', 'autocomplete', 'showAutocompleteOnFocus', 'removeConfirmation', 'caseSensitive', 'allowDuplicates', 'allowSpaces', 'readOnly', 'tagLimit', 'singleField', 'singleFieldDelimiter', 'singleFieldNode', 'tabIndex', 'placeholderText'));
$resolver->setAllowedTypes(array('autocomplete' => 'array'));
$resolver->setDefaults(array('allowSpaces' => true, 'removeConfirmation' => true, 'singleFieldDelimiter' => ',', 'autocomplete' => array()));
return $resolver->resolve($form->getConfig()->getOption('tagit', array()));
}
示例7: configureOptions
/**
* {@inheritDoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$optionNames = array('flow_instance', 'flow_instance_key', 'flow_step', 'flow_step_key');
if (Kernel::VERSION_ID < 20600) {
$resolver->setOptional($optionNames);
} else {
$resolver->setDefined($optionNames);
}
}
示例8: send
public function send(array $config = [])
{
$resolver = new OptionsResolver();
$resolver->setOptional(array_keys($config));
$resolver->setRequired(['protocol']);
$config = $resolver->resolve($config);
if (false !== ($transport = $this->transportChain->getTransport($config['protocol']))) {
return $transport->send($config);
}
}
示例9: loadTransitions
/**
* @param StateMachineInterface $stateMachine
*/
private function loadTransitions(StateMachineInterface $stateMachine)
{
$resolver = new OptionsResolver();
$resolver->setRequired(array('from', 'to'));
$resolver->setOptional(array('guard'));
$resolver->setNormalizers(array('from' => function (Options $options, $v) {
return (array) $v;
}, 'guard' => function (Options $options, $v) {
return !isset($v) ? null : $v;
}));
foreach ($this->config['transitions'] as $transition => $config) {
$config = $resolver->resolve($config);
$stateMachine->addTransition(new Transition($transition, $config['from'], $config['to'], $config['guard']));
}
}
示例10: update
/**
* @param ProductInterface $product
* @param array $updates
*
* @return boolean
*/
protected function update(ProductInterface $product, array $updates)
{
$resolver = new OptionsResolver();
$resolver->setRequired(['type']);
$resolver->setAllowedValues(['type' => ['set_value', 'copy_value']]);
$resolver->setOptional(['field', 'value', 'locale', 'scope', 'from_field', 'to_field', 'from_locale', 'to_locale', 'from_scope', 'to_scope']);
$resolver->setDefaults(['locale' => null, 'scope' => null, 'from_locale' => null, 'to_locale' => null, 'from_scope' => null, 'to_scope' => null]);
foreach ($updates as $update) {
$update = $resolver->resolve($update);
if ('set_value' === $update['type']) {
$this->applySetValue($product, $update);
} else {
$this->applyCopyValue($product, $update);
}
}
}
示例11: configureOptions
/**
* Add the client_validation option
*
* @param OptionsResolverInterface $resolver
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setOptional(array('client_validation'));
}
示例12: configureOptions
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setOptional(array('block', 'subblock', 'block_config', 'tooltip'));
}
示例13: createOptionsResolver
/**
* @return OptionsResolverInterface
*/
protected function createOptionsResolver()
{
$resolver = new OptionsResolver();
$required = [];
$allowedTypes = ['family' => 'string', 'enabled' => 'bool', 'categories' => 'string', 'groups' => 'string'];
$optional = array_merge(['family', 'enabled', 'categories', 'groups'], $this->attrColumnsResolver->resolveAttributeColumns(), $this->getOptionalAssociationFields());
$resolver->setRequired($required);
$resolver->setOptional($optional);
$resolver->setAllowedTypes($allowedTypes);
$booleanNormalizer = function ($options, $value) {
return (bool) $value;
};
$resolver->setNormalizers(['enabled' => $booleanNormalizer]);
return $resolver;
}
示例14: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$queue = $input->getArgument('queue');
$connection = $input->getArgument('connection');
$factory = $this->getContainer()->get('swarrot.factory.default');
$messageProvider = $factory->getMessageProvider($queue, $connection);
$stack = new Builder();
if (array_key_exists('signal_handler', $this->processorStack)) {
$stack->push($this->processorStack['signal_handler'], $this->logger);
}
if (array_key_exists('max_messages', $this->processorStack)) {
$stack->push($this->processorStack['max_messages'], $this->logger);
}
if (array_key_exists('max_execution_time', $this->processorStack)) {
$stack->push($this->processorStack['max_execution_time'], $this->logger);
}
if (array_key_exists('exception_catcher', $this->processorStack) && !$input->getOption('no-catch')) {
$stack->push($this->processorStack['exception_catcher'], $this->logger);
}
if (array_key_exists('ack', $this->processorStack)) {
$stack->push($this->processorStack['ack'], $messageProvider, $this->logger);
}
if (array_key_exists('retry', $this->processorStack) && !$input->getOption('no-retry')) {
$exchange = 'retry';
if (isset($this->extras['retry_exchange'])) {
$exchange = $this->extras['retry_exchange'];
}
$messagePublisher = $factory->getMessagePublisher($exchange, $connection);
$stack->push($this->processorStack['retry'], $messagePublisher, $this->logger);
}
$processor = $stack->resolve($this->processor);
$optionsResolver = new OptionsResolver();
$optionsResolver->setOptional(array('queue', 'connection'));
$consumer = new Consumer($messageProvider, $processor, $optionsResolver);
$consumer->consume($this->getOptions($input));
}
示例15: configureOptions
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setOptional($this->optionalParameters);
}