Skip to content

Commit 2307dc8

Browse files
committed
feature #18302 [OptionsResolver] add ignoreUndefined() (alamirault)
This PR was squashed before being merged into the 6.3 branch. Discussion ---------- [OptionsResolver] add `ignoreUndefined()` Fix #18282 Commits ------- 09914bc [OptionsResolver] add `ignoreUndefined()`
2 parents 2cc8f4b + 09914bc commit 2307dc8

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

components/options_resolver.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,29 @@ the option::
842842
This closure receives as argument the value of the option after validating it
843843
and before normalizing it when the option is being resolved.
844844

845+
Ignore not defined Options
846+
~~~~~~~~~~~~~~~~~~~~~~~~~~
847+
848+
By default, all options are resolved, validated and an :class:`Symfony\\Component\\OptionsResolver\\Exception\\UndefinedOptionsException`
849+
is thrown if an unknown option is passed. You can ignore not defined options by using the
850+
:method:`Symfony\\Component\\OptionsResolver\\OptionsResolver::ignoreUndefined` method::
851+
852+
// ...
853+
$resolver
854+
->setDefined(['hostname'])
855+
->setIgnoreUndefined(true)
856+
;
857+
858+
// option "version" will be ignored
859+
$resolver->resolve([
860+
'hostname' => 'acme/package',
861+
'version' => '1.2.3'
862+
]);
863+
864+
.. versionadded:: 6.3
865+
866+
The ``ignoreUndefined`` method was introduced in Symfony 6.3.
867+
845868
Chaining Option Configurations
846869
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
847870

0 commit comments

Comments
 (0)