Skip to content

Commit

Permalink
minor #20536 [OptionsResolver] Support union of types (VincentLanglet)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the 7.3 branch.

Discussion
----------

[OptionsResolver] Support union of types

Closes #20531

But I'm not sure it's expected to be documented this way...

Commits
-------

f8667f5 [OptionsResolver] Support union of types
  • Loading branch information
javiereguiluz committed Jan 9, 2025
2 parents f2e47e6 + f8667f5 commit e44b2fb
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions components/options_resolver.rst
Original file line number Diff line number Diff line change
Expand Up @@ -305,13 +305,20 @@ correctly. To validate the types of the options, call

// specify multiple allowed types
$resolver->setAllowedTypes('port', ['null', 'int']);
// which is similar to
$resolver->setAllowedTypes('port', 'int|null');

// check all items in an array recursively for a type
$resolver->setAllowedTypes('dates', 'DateTime[]');
$resolver->setAllowedTypes('ports', 'int[]');
$resolver->setAllowedTypes('endpoints', '(int|string)[]');
}
}

.. versionadded:: 7.3

Union of type, using the ``|`` syntax, was introduced in Symfony 7.3.

You can pass any type for which an ``is_<type>()`` function is defined in PHP.
You may also pass fully qualified class or interface names (which is checked
using ``instanceof``). Additionally, you can validate all items in an array
Expand Down

0 comments on commit e44b2fb

Please sign in to comment.