Skip to content

[OptionsResolver] Is it possible to allow/ignore extra options? #22536

@skafandri

Description

@skafandri
Q A
Bug report? no
Feature request? no
BC Break report? no
RFC? yes
Symfony version master

I have an array of options that has a subset that needs resolving, the rest of it is not important. Is it possible to ignore the rest of the array?
A similar behavior to Form allow_extra_fields

Example: email and phone are required, everything else just doesn't matter.

$options = [
    'email' => 'email',
    'phone' => 'phone',
    //many other keys
];

$resolver = new \Symfony\Component\OptionsResolver\OptionsResolver();
$resolver->setRequired(['email', 'phone']);
$resolver->resolve($options);

This obviously yields UndefinedOptionsException

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions